sequence
stringlengths
1.25k
34.6k
code
stringlengths
75
8.58k
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'check_recommended_global_attributes'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'dataset'},{'id': '6', 'type': 'block', 'children': ['7', '9', '19', '35', '44', '54', '66', '89', '138', '147', '168', '188', '196', '205', '214', '232', '254']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'string', 'children': [], 'value': '\'\'\'\n Check the global recommended attributes for 2.0 templates. These go an extra step besides\n just checking that they exist.\n :param netCDF4.Dataset dataset: An open netCDF dataset\n :id = "" ; //.................................................. RECOMMENDED - Should be a human readable unique identifier for data set. (ACDD)\n :naming_authority = "" ; //.................................... RECOMMENDED - Backward URL of institution (for example, gov.noaa.ncei). (ACDD)\n :history = "" ; //............................................. RECOMMENDED - Provides an audit trail for modifications to the original data. (ACDD)\n :source = "" ; //.............................................. RECOMMENDED - The method of production of the original data. (CF)\n :processing_level = "" ; //.................................... RECOMMENDED - Provide a description of the processing or quality control level of the data. (ACDD)\n :comment = "" ; //............................................. RECOMMENDED - Provide useful additional information here. (CF)\n :acknowledgment = "" ; //...................................... RECOMMENDED - A place to acknowledge various types of support for the project that produced this data. (ACDD)\n :license = "" ; //............................................. RECOMMENDED - Describe the restrictions to data access and distribution. (ACDD)\n :standard_name_vocabulary = "CF Standard Name Table vNN" ; //.. RECOMMENDED - If using CF standard name attribute for variables. Replace NN with the CF standard name table number (CF)\n :date_created = "" ; //........................................ RECOMMENDED - Creation date of this version of the data(netCDF). Use ISO 8601:2004 for date and time. (ACDD)\n :creator_name = "" ; //........................................ RECOMMENDED - The name of the person (or other creator type specified by the creator_type attribute) principally responsible for creating this data. (ACDD)\n :creator_email = "" ; //....................................... RECOMMENDED - The email address of the person (or other creator type specified by the creator_type attribute) principally responsible for creating this data. (ACDD)\n :creator_url = "" ; //......................................... RECOMMENDED - The URL of the person (or other creator type specified by the creator_type attribute) principally responsible for creating this data. (ACDD)\n :institution = "" ; //......................................... RECOMMENDED -The name of the institution principally responsible for originating this data.. An institution attribute can be used for each variable if variables come from more than one institution. (CF/ACDD)\n :project = "" ; //............................................. RECOMMENDED - The name of the project(s) principally responsible for originating this data. Multiple projects can be separated by commas. (ACDD)\n :publisher_name = "" ; //...................................... RECOMMENDED - The name of the person (or other entity specified by the publisher_type attribute) responsible for publishing the data file or product to users, with its current metadata and format. (ACDD)\n :publisher_email = "" ; //..................................... RECOMMENDED - The email address of the person (or other entity specified by the publisher_type attribute) responsible for publishing the data file or product to users, with its current metadata and format. (ACDD)\n :publisher_url = "" ; //....................................... RECOMMENDED - The URL of the person (or other entity specified by the publisher_type attribute) responsible for publishing the data file or product to users, with its current metadata and format. (ACDD)\n :geospatial_bounds = "" ; //................................... RECOMMENDED - Describes the data\'s 2D or 3D geospatial extent in OGC\'s Well-Known Text (WKT) Geometry format. (ACDD)\n :geospatial_bounds_crs = "" ; //............................... RECOMMENDED - The coordinate reference system (CRS) of the point coordinates in the geospatial_bounds attribute. (ACDD)\n :geospatial_bounds_vertical_crs = "" ; //...................... RECOMMENDED - The vertical coordinate reference system (CRS) for the Z axis of the point coordinates in the geospatial_bounds attribute. (ACDD)\n :geospatial_lat_min = 0.0d ; //................................ RECOMMENDED - Describes a simple lower latitude limit. (ACDD)\n :geospatial_lat_max = 0.0d ; //................................ RECOMMENDED - Describes a simple upper latitude limit. (ACDD)\n :geospatial_lon_min = 0.0d ; //................................ RECOMMENDED - Describes a simple lower longitude limit. (ACDD)\n :geospatial_lon_max = 0.0d ; //................................ RECOMMENDED - Describes a simple upper longitude limit. (ACDD)\n :geospatial_vertical_min = 0.0d ; //........................... RECOMMENDED - Describes the numerically smaller vertical limit. (ACDD)\n :geospatial_vertical_max = 0.0d ; //........................... RECOMMENDED - Describes the numerically larger vertical limit. (ACDD)\n :geospatial_vertical_positive = "" ; //........................ RECOMMENDED - Use "up" or "down". (ACDD)\n :time_coverage_start = "" ; //................................. RECOMMENDED - Describes the time of the first data point in the data set. Use ISO 8601:2004 for date and time. (ACDD)\n :time_coverage_end = "" ; //................................... RECOMMENDED - Describes the time of the last data point in the data set. Use ISO 8601:2004 for date and time.(ACDD)\n :time_coverage_duration = "" ; //.............................. RECOMMENDED - Describes the duration of the data set. Use ISO 8601:2004 for date and time. (ACDD)\n :time_coverage_resolution = "" ; //............................ RECOMMENDED - Describes the targeted time period between each value in the data set. Use ISO 8601:2004 for date and time. (ACDD)\n :uuid = "" ; //................................................ RECOMMENDED - Machine readable unique identifier for each file. A new uuid is created whenever the file is changed. (NCEI)\n :sea_name = "" ; //............................................ RECOMMENDED - The names of the sea in which the data were collected. Use NCEI sea names table. (NCEI)\n \'\'\''},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'recommended_ctx'},{'id': '12', 'type': 'call', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'TestCtx'},{'id': '14', 'type': 'argument_list', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'BaseCheck'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'MEDIUM'},{'id': '18', 'type': 'string', 'children': [], 'value': "'Recommended global attributes'"},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'sea_names'},{'id': '22', 'type': 'list_comprehension', 'children': ['23', '28']},{'id': '23', 'type': 'call', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'sn'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '27', 'type': 'argument_list', 'children': []},{'id': '28', 'type': 'for_in_clause', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'sn'},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'util'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'get_sea_names'},{'id': '34', 'type': 'argument_list', 'children': []},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'sea_name'},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '40', 'type': 'argument_list', 'children': ['41', '42', '43']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'dataset'},{'id': '42', 'type': 'string', 'children': [], 'value': "'sea_name'"},{'id': '43', 'type': 'string', 'children': [], 'value': "''"},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'sea_name'},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'sea_name'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '51', 'type': 'argument_list', 'children': ['52', '53']},{'id': '52', 'type': 'string', 'children': [], 'value': "', '"},{'id': '53', 'type': 'string', 'children': [], 'value': "','"},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'sea_name'},{'id': '57', 'type': 'conditional_expression', 'children': ['58', '64', '65'], 'value': 'if'},{'id': '58', 'type': 'call', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'sea_name'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'string', 'children': [], 'value': "','"},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'sea_name'},{'id': '65', 'type': 'list', 'children': [], 'value': '[]'},{'id': '66', 'type': 'for_statement', 'children': ['67', '68', '69']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'sea'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'sea_name'},{'id': '69', 'type': 'block', 'children': ['70']},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'call', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'recommended_ctx'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'assert_true'},{'id': '75', 'type': 'argument_list', 'children': ['76', '83']},{'id': '76', 'type': 'comparison_operator', 'children': ['77', '82'], 'value': 'in'},{'id': '77', 'type': 'call', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'sea'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '81', 'type': 'argument_list', 'children': []},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'sea_names'},{'id': '83', 'type': 'call', 'children': ['84', '87']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'string', 'children': [], 'value': "'sea_name attribute should exist and should be from the NODC sea names list: {} is not a valid sea name'"},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'sea'},{'id': '89', 'type': 'for_statement', 'children': ['90', '91', '96']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '91', 'type': 'list', 'children': ['92', '93', '94', '95'], 'value': "['time_coverage_start', 'time_coverage_end', 'date_created', 'date_modified']"},{'id': '92', 'type': 'string', 'children': [], 'value': "'time_coverage_start'"},{'id': '93', 'type': 'string', 'children': [], 'value': "'time_coverage_end'"},{'id': '94', 'type': 'string', 'children': [], 'value': "'date_created'"},{'id': '95', 'type': 'string', 'children': [], 'value': "'date_modified'"},{'id': '96', 'type': 'block', 'children': ['97', '106']},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'attr_value'},{'id': '100', 'type': 'call', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '102', 'type': 'argument_list', 'children': ['103', '104', '105']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'dataset'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '105', 'type': 'string', 'children': [], 'value': "''"},{'id': '106', 'type': 'try_statement', 'children': ['107', '121']},{'id': '107', 'type': 'block', 'children': ['108', '113']},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'call', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'parse_datetime'},{'id': '111', 'type': 'argument_list', 'children': ['112']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'attr_value'},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'call', 'children': ['115', '118']},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'recommended_ctx'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'assert_true'},{'id': '118', 'type': 'argument_list', 'children': ['119', '120']},{'id': '119', 'type': 'True', 'children': []},{'id': '120', 'type': 'string', 'children': [], 'value': "''"},{'id': '121', 'type': 'except_clause', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'ISO8601Error'},{'id': '123', 'type': 'block', 'children': ['124']},{'id': '124', 'type': 'expression_statement', 'children': ['125']},{'id': '125', 'type': 'call', 'children': ['126', '129']},{'id': '126', 'type': 'attribute', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'recommended_ctx'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'assert_true'},{'id': '129', 'type': 'argument_list', 'children': ['130', '131']},{'id': '130', 'type': 'False', 'children': []},{'id': '131', 'type': 'call', 'children': ['132', '135']},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'string', 'children': [], 'value': "'{} should exist and be ISO-8601 format (example: PT1M30S), currently: {}'"},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '135', 'type': 'argument_list', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'attr_value'},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'assignment', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '141', 'type': 'call', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '143', 'type': 'argument_list', 'children': ['144', '145', '146']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'dataset'},{'id': '145', 'type': 'string', 'children': [], 'value': "'geospatial_vertical_positive'"},{'id': '146', 'type': 'string', 'children': [], 'value': "''"},{'id': '147', 'type': 'expression_statement', 'children': ['148']},{'id': '148', 'type': 'call', 'children': ['149', '152']},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'recommended_ctx'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'assert_true'},{'id': '152', 'type': 'argument_list', 'children': ['153', '162']},{'id': '153', 'type': 'comparison_operator', 'children': ['154', '159'], 'value': 'in'},{'id': '154', 'type': 'call', 'children': ['155', '158']},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '158', 'type': 'argument_list', 'children': []},{'id': '159', 'type': 'list', 'children': ['160', '161'], 'value': "['up', 'down']"},{'id': '160', 'type': 'string', 'children': [], 'value': "'up'"},{'id': '161', 'type': 'string', 'children': [], 'value': "'down'"},{'id': '162', 'type': 'call', 'children': ['163', '166']},{'id': '163', 'type': 'attribute', 'children': ['164', '165']},{'id': '164', 'type': 'string', 'children': [], 'value': "'geospatial_vertical_positive attribute should be up or down: {}'"},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '166', 'type': 'argument_list', 'children': ['167']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'id': '169', 'type': 'assignment', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'ack_exists'},{'id': '171', 'type': 'call', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'any'},{'id': '173', 'type': 'argument_list', 'children': ['174']},{'id': '174', 'type': 'generator_expression', 'children': ['175', '183']},{'id': '175', 'type': 'comparison_operator', 'children': ['176', '182'], 'value': '!='},{'id': '176', 'type': 'call', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '178', 'type': 'argument_list', 'children': ['179', '180', '181']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'dataset'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '181', 'type': 'string', 'children': [], 'value': "''"},{'id': '182', 'type': 'string', 'children': [], 'value': "''"},{'id': '183', 'type': 'for_in_clause', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '185', 'type': 'list', 'children': ['186', '187'], 'value': "['acknowledgment', 'acknowledgement']"},{'id': '186', 'type': 'string', 'children': [], 'value': "'acknowledgment'"},{'id': '187', 'type': 'string', 'children': [], 'value': "'acknowledgement'"},{'id': '188', 'type': 'expression_statement', 'children': ['189']},{'id': '189', 'type': 'call', 'children': ['190', '193']},{'id': '190', 'type': 'attribute', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'recommended_ctx'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'assert_true'},{'id': '193', 'type': 'argument_list', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'ack_exists'},{'id': '195', 'type': 'string', 'children': [], 'value': "'acknowledgement attribute should exist and not be empty'"},{'id': '196', 'type': 'expression_statement', 'children': ['197']},{'id': '197', 'type': 'assignment', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'standard_name_vocab'},{'id': '199', 'type': 'call', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '201', 'type': 'argument_list', 'children': ['202', '203', '204']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'dataset'},{'id': '203', 'type': 'string', 'children': [], 'value': "'standard_name_vocabulary'"},{'id': '204', 'type': 'string', 'children': [], 'value': "''"},{'id': '205', 'type': 'expression_statement', 'children': ['206']},{'id': '206', 'type': 'assignment', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'regex'},{'id': '208', 'type': 'call', 'children': ['209', '212']},{'id': '209', 'type': 'attribute', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'compile'},{'id': '212', 'type': 'argument_list', 'children': ['213']},{'id': '213', 'type': 'string', 'children': [], 'value': "r'[sS]tandard [nN]ame [tT]able'"},{'id': '214', 'type': 'expression_statement', 'children': ['215']},{'id': '215', 'type': 'call', 'children': ['216', '219']},{'id': '216', 'type': 'attribute', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'recommended_ctx'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'assert_true'},{'id': '219', 'type': 'argument_list', 'children': ['220', '226']},{'id': '220', 'type': 'call', 'children': ['221', '224']},{'id': '221', 'type': 'attribute', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'regex'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '224', 'type': 'argument_list', 'children': ['225']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'standard_name_vocab'},{'id': '226', 'type': 'call', 'children': ['227', '230']},{'id': '227', 'type': 'attribute', 'children': ['228', '229']},{'id': '228', 'type': 'string', 'children': [], 'value': '"standard_name_vocabulary doesn\'t contain \'Standard Name Table\': {}"'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '230', 'type': 'argument_list', 'children': ['231']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'standard_name_vocab'},{'id': '232', 'type': 'if_statement', 'children': ['233', '238']},{'id': '233', 'type': 'call', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '235', 'type': 'argument_list', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'dataset'},{'id': '237', 'type': 'string', 'children': [], 'value': "'comment'"},{'id': '238', 'type': 'block', 'children': ['239']},{'id': '239', 'type': 'expression_statement', 'children': ['240']},{'id': '240', 'type': 'call', 'children': ['241', '244']},{'id': '241', 'type': 'attribute', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'recommended_ctx'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'assert_true'},{'id': '244', 'type': 'argument_list', 'children': ['245', '253']},{'id': '245', 'type': 'comparison_operator', 'children': ['246', '252'], 'value': '!='},{'id': '246', 'type': 'call', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '248', 'type': 'argument_list', 'children': ['249', '250', '251']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'dataset'},{'id': '250', 'type': 'string', 'children': [], 'value': "'comment'"},{'id': '251', 'type': 'string', 'children': [], 'value': "''"},{'id': '252', 'type': 'string', 'children': [], 'value': "''"},{'id': '253', 'type': 'string', 'children': [], 'value': "'comment attribute should not be empty if specified'"},{'id': '254', 'type': 'return_statement', 'children': ['255']},{'id': '255', 'type': 'call', 'children': ['256', '259']},{'id': '256', 'type': 'attribute', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'recommended_ctx'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'to_result'},{'id': '259', 'type': 'argument_list', 'children': []}
def check_recommended_global_attributes(self, dataset): ''' Check the global recommended attributes for 2.0 templates. These go an extra step besides just checking that they exist. :param netCDF4.Dataset dataset: An open netCDF dataset :id = "" ; //.................................................. RECOMMENDED - Should be a human readable unique identifier for data set. (ACDD) :naming_authority = "" ; //.................................... RECOMMENDED - Backward URL of institution (for example, gov.noaa.ncei). (ACDD) :history = "" ; //............................................. RECOMMENDED - Provides an audit trail for modifications to the original data. (ACDD) :source = "" ; //.............................................. RECOMMENDED - The method of production of the original data. (CF) :processing_level = "" ; //.................................... RECOMMENDED - Provide a description of the processing or quality control level of the data. (ACDD) :comment = "" ; //............................................. RECOMMENDED - Provide useful additional information here. (CF) :acknowledgment = "" ; //...................................... RECOMMENDED - A place to acknowledge various types of support for the project that produced this data. (ACDD) :license = "" ; //............................................. RECOMMENDED - Describe the restrictions to data access and distribution. (ACDD) :standard_name_vocabulary = "CF Standard Name Table vNN" ; //.. RECOMMENDED - If using CF standard name attribute for variables. Replace NN with the CF standard name table number (CF) :date_created = "" ; //........................................ RECOMMENDED - Creation date of this version of the data(netCDF). Use ISO 8601:2004 for date and time. (ACDD) :creator_name = "" ; //........................................ RECOMMENDED - The name of the person (or other creator type specified by the creator_type attribute) principally responsible for creating this data. (ACDD) :creator_email = "" ; //....................................... RECOMMENDED - The email address of the person (or other creator type specified by the creator_type attribute) principally responsible for creating this data. (ACDD) :creator_url = "" ; //......................................... RECOMMENDED - The URL of the person (or other creator type specified by the creator_type attribute) principally responsible for creating this data. (ACDD) :institution = "" ; //......................................... RECOMMENDED -The name of the institution principally responsible for originating this data.. An institution attribute can be used for each variable if variables come from more than one institution. (CF/ACDD) :project = "" ; //............................................. RECOMMENDED - The name of the project(s) principally responsible for originating this data. Multiple projects can be separated by commas. (ACDD) :publisher_name = "" ; //...................................... RECOMMENDED - The name of the person (or other entity specified by the publisher_type attribute) responsible for publishing the data file or product to users, with its current metadata and format. (ACDD) :publisher_email = "" ; //..................................... RECOMMENDED - The email address of the person (or other entity specified by the publisher_type attribute) responsible for publishing the data file or product to users, with its current metadata and format. (ACDD) :publisher_url = "" ; //....................................... RECOMMENDED - The URL of the person (or other entity specified by the publisher_type attribute) responsible for publishing the data file or product to users, with its current metadata and format. (ACDD) :geospatial_bounds = "" ; //................................... RECOMMENDED - Describes the data's 2D or 3D geospatial extent in OGC's Well-Known Text (WKT) Geometry format. (ACDD) :geospatial_bounds_crs = "" ; //............................... RECOMMENDED - The coordinate reference system (CRS) of the point coordinates in the geospatial_bounds attribute. (ACDD) :geospatial_bounds_vertical_crs = "" ; //...................... RECOMMENDED - The vertical coordinate reference system (CRS) for the Z axis of the point coordinates in the geospatial_bounds attribute. (ACDD) :geospatial_lat_min = 0.0d ; //................................ RECOMMENDED - Describes a simple lower latitude limit. (ACDD) :geospatial_lat_max = 0.0d ; //................................ RECOMMENDED - Describes a simple upper latitude limit. (ACDD) :geospatial_lon_min = 0.0d ; //................................ RECOMMENDED - Describes a simple lower longitude limit. (ACDD) :geospatial_lon_max = 0.0d ; //................................ RECOMMENDED - Describes a simple upper longitude limit. (ACDD) :geospatial_vertical_min = 0.0d ; //........................... RECOMMENDED - Describes the numerically smaller vertical limit. (ACDD) :geospatial_vertical_max = 0.0d ; //........................... RECOMMENDED - Describes the numerically larger vertical limit. (ACDD) :geospatial_vertical_positive = "" ; //........................ RECOMMENDED - Use "up" or "down". (ACDD) :time_coverage_start = "" ; //................................. RECOMMENDED - Describes the time of the first data point in the data set. Use ISO 8601:2004 for date and time. (ACDD) :time_coverage_end = "" ; //................................... RECOMMENDED - Describes the time of the last data point in the data set. Use ISO 8601:2004 for date and time.(ACDD) :time_coverage_duration = "" ; //.............................. RECOMMENDED - Describes the duration of the data set. Use ISO 8601:2004 for date and time. (ACDD) :time_coverage_resolution = "" ; //............................ RECOMMENDED - Describes the targeted time period between each value in the data set. Use ISO 8601:2004 for date and time. (ACDD) :uuid = "" ; //................................................ RECOMMENDED - Machine readable unique identifier for each file. A new uuid is created whenever the file is changed. (NCEI) :sea_name = "" ; //............................................ RECOMMENDED - The names of the sea in which the data were collected. Use NCEI sea names table. (NCEI) ''' recommended_ctx = TestCtx(BaseCheck.MEDIUM, 'Recommended global attributes') sea_names = [sn.lower() for sn in util.get_sea_names()] sea_name = getattr(dataset, 'sea_name', '') sea_name = sea_name.replace(', ', ',') sea_name = sea_name.split(',') if sea_name else [] for sea in sea_name: recommended_ctx.assert_true( sea.lower() in sea_names, 'sea_name attribute should exist and should be from the NODC sea names list: {} is not a valid sea name'.format(sea) ) for attr in ['time_coverage_start', 'time_coverage_end', 'date_created', 'date_modified']: attr_value = getattr(dataset, attr, '') try: parse_datetime(attr_value) recommended_ctx.assert_true(True, '') except ISO8601Error: recommended_ctx.assert_true(False, '{} should exist and be ISO-8601 format (example: PT1M30S), currently: {}'.format(attr, attr_value)) value = getattr(dataset, 'geospatial_vertical_positive', '') recommended_ctx.assert_true(value.lower() in ['up', 'down'], 'geospatial_vertical_positive attribute should be up or down: {}'.format(value)) ack_exists = any((getattr(dataset, attr, '') != '' for attr in ['acknowledgment', 'acknowledgement'])) recommended_ctx.assert_true(ack_exists, 'acknowledgement attribute should exist and not be empty') standard_name_vocab = getattr(dataset, 'standard_name_vocabulary', '') regex = re.compile(r'[sS]tandard [nN]ame [tT]able') recommended_ctx.assert_true(regex.search(standard_name_vocab), "standard_name_vocabulary doesn't contain 'Standard Name Table': {}".format(standard_name_vocab)) if hasattr(dataset, 'comment'): recommended_ctx.assert_true(getattr(dataset, 'comment', '') != '', 'comment attribute should not be empty if specified') return recommended_ctx.to_result()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'check_base_suggested_attributes'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'dataset'},{'id': '6', 'type': 'block', 'children': ['7', '9', '19', '28', '38', '47', '73', '121', '134', '149', '162', '177', '186', '195', '204', '213', '223', '239', '249', '265']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'string', 'children': [], 'value': '\'\'\'\n Check the global suggested attributes for 2.0 templates. These go an extra step besides\n just checking that they exist.\n :param netCDF4.Dataset dataset: An open netCDF dataset\n :creator_type = "" ; //........................................ SUGGESTED - Specifies type of creator with one of the following: \'person\', \'group\', \'institution\', or \'position\'. (ACDD)\n :creator_institution = "" ; //................................. SUGGESTED - The institution of the creator; should uniquely identify the creator\'s institution. (ACDD)\n :publisher_type = "" ; //...................................... SUGGESTED - Specifies type of publisher with one of the following: \'person\', \'group\', \'institution\', or \'position\'. (ACDD)\n :publisher_institution = "" ; //............................... SUGGESTED - The institution that presented the data file or equivalent product to users; should uniquely identify the institution. (ACDD)\n :program = "" ; //............................................. SUGGESTED - The overarching program(s) of which the dataset is a part. (ACDD)\n :contributor_name = "" ; //.................................... SUGGESTED - The name of any individuals, projects, or institutions that contributed to the creation of this data. (ACDD)\n :contributor_role = "" ; //.................................... SUGGESTED - The role of any individuals, projects, or institutions that contributed to the creation of this data. (ACDD)\n :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)\n :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)\n :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)\n :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)\n :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)\n :date_metadata_modified = "" ; //.............................. SUGGESTED - The date on which the metadata was last modified. Use ISO 8601:2004 for date and time. (ACDD)\n :product_version = "" ; //..................................... SUGGESTED - Version identifier of the data file or product as assigned by the data creator. (ACDD)\n :keywords_vocabulary = "" ; //................................. SUGGESTED - Identifies the controlled keyword vocabulary used to specify the values within the attribute "keywords". Example: \'GCMD:GCMD Keywords\' ACDD)\n :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)\n :platform_vocabulary = "" ; //................................. SUGGESTED - Controlled vocabulary for the names used in the "platform" attribute . Example: ‘NASA/GCMD Platform Keywords Version 8.1’ (ACDD)\n :instrument = "" ; //.......................................... SUGGESTED - Name of the contributing instrument(s) or sensor(s) used to create this data set or product. (ACDD)\n :instrument_vocabulary = "" ; //............................... SUGGESTED - Controlled vocabulary for the names used in the "instrument" attribute. Example: ‘NASA/GCMD Instrument Keywords Version 8.1’ (ACDD)\n :cdm_data_type = "Point" ; //.................................. SUGGESTED - The data type, as derived from Unidata\'s Common Data Model Scientific Data types and understood by THREDDS. (ACDD)\n :metadata_link = "" ; //....................................... SUGGESTED - A URL that gives the location of more complete metadata. A persistent URL is recommended for this attribute. (ACDD)\n :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)\n \'\'\''},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'suggested_ctx'},{'id': '12', 'type': 'call', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'TestCtx'},{'id': '14', 'type': 'argument_list', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'BaseCheck'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'LOW'},{'id': '18', 'type': 'string', 'children': [], 'value': "'Suggested global attributes'"},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'platform_name'},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '24', 'type': 'argument_list', 'children': ['25', '26', '27']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'dataset'},{'id': '26', 'type': 'string', 'children': [], 'value': "'platform'"},{'id': '27', 'type': 'string', 'children': [], 'value': "''"},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'suggested_ctx'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'assert_true'},{'id': '33', 'type': 'argument_list', 'children': ['34', '37']},{'id': '34', 'type': 'comparison_operator', 'children': ['35', '36'], 'value': '!='},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'platform_name'},{'id': '36', 'type': 'string', 'children': [], 'value': "''"},{'id': '37', 'type': 'string', 'children': [], 'value': "'platform should exist and point to a term in :platform_vocabulary.'"},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'cdm_data_type'},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '43', 'type': 'argument_list', 'children': ['44', '45', '46']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'dataset'},{'id': '45', 'type': 'string', 'children': [], 'value': "'cdm_data_type'"},{'id': '46', 'type': 'string', 'children': [], 'value': "''"},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'call', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'suggested_ctx'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'assert_true'},{'id': '52', 'type': 'argument_list', 'children': ['53', '67']},{'id': '53', 'type': 'comparison_operator', 'children': ['54', '59'], 'value': 'in'},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'cdm_data_type'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '58', 'type': 'argument_list', 'children': []},{'id': '59', 'type': 'list', 'children': ['60', '61', '62', '63', '64', '65', '66'], 'value': "['grid', 'image', 'point', 'radial', 'station', 'swath', 'trajectory']"},{'id': '60', 'type': 'string', 'children': [], 'value': "'grid'"},{'id': '61', 'type': 'string', 'children': [], 'value': "'image'"},{'id': '62', 'type': 'string', 'children': [], 'value': "'point'"},{'id': '63', 'type': 'string', 'children': [], 'value': "'radial'"},{'id': '64', 'type': 'string', 'children': [], 'value': "'station'"},{'id': '65', 'type': 'string', 'children': [], 'value': "'swath'"},{'id': '66', 'type': 'string', 'children': [], 'value': "'trajectory'"},{'id': '67', 'type': 'call', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'string', 'children': [], 'value': "'cdm_data_type must be one of Grid, Image, Point, Radial, Station, Swath, Trajectory: {}'"},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'cdm_data_type'},{'id': '73', 'type': 'for_statement', 'children': ['74', '75', '79']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '75', 'type': 'list', 'children': ['76', '77', '78'], 'value': "['date_modified', 'date_issued', 'date_metadata_modified']"},{'id': '76', 'type': 'string', 'children': [], 'value': "'date_modified'"},{'id': '77', 'type': 'string', 'children': [], 'value': "'date_issued'"},{'id': '78', 'type': 'string', 'children': [], 'value': "'date_metadata_modified'"},{'id': '79', 'type': 'block', 'children': ['80', '89']},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'attr_value'},{'id': '83', 'type': 'call', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '85', 'type': 'argument_list', 'children': ['86', '87', '88']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'dataset'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '88', 'type': 'string', 'children': [], 'value': "''"},{'id': '89', 'type': 'try_statement', 'children': ['90', '104']},{'id': '90', 'type': 'block', 'children': ['91', '96']},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'call', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'parse_datetime'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'attr_value'},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'call', 'children': ['98', '101']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'suggested_ctx'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'assert_true'},{'id': '101', 'type': 'argument_list', 'children': ['102', '103']},{'id': '102', 'type': 'True', 'children': []},{'id': '103', 'type': 'string', 'children': [], 'value': "''"},{'id': '104', 'type': 'except_clause', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'ISO8601Error'},{'id': '106', 'type': 'block', 'children': ['107']},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'call', 'children': ['109', '112']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'suggested_ctx'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'assert_true'},{'id': '112', 'type': 'argument_list', 'children': ['113', '114']},{'id': '113', 'type': 'False', 'children': []},{'id': '114', 'type': 'call', 'children': ['115', '118']},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'string', 'children': [], 'value': "'{} should exist and be ISO-8601 format (example: PT1M30S), currently: {}'"},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '118', 'type': 'argument_list', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'attr_value'},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'assignment', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'units'},{'id': '124', 'type': 'call', 'children': ['125', '133']},{'id': '125', 'type': 'attribute', 'children': ['126', '132']},{'id': '126', 'type': 'call', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '128', 'type': 'argument_list', 'children': ['129', '130', '131']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'dataset'},{'id': '130', 'type': 'string', 'children': [], 'value': "'geospatial_lat_units'"},{'id': '131', 'type': 'string', 'children': [], 'value': "''"},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '133', 'type': 'argument_list', 'children': []},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'call', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'suggested_ctx'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'assert_true'},{'id': '139', 'type': 'argument_list', 'children': ['140', '143']},{'id': '140', 'type': 'comparison_operator', 'children': ['141', '142'], 'value': '=='},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'units'},{'id': '142', 'type': 'string', 'children': [], 'value': "'degrees_north'"},{'id': '143', 'type': 'call', 'children': ['144', '147']},{'id': '144', 'type': 'attribute', 'children': ['145', '146']},{'id': '145', 'type': 'string', 'children': [], 'value': "'geospatial_lat_units attribute should be degrees_north: {}'"},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '147', 'type': 'argument_list', 'children': ['148']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'units'},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'assignment', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'units'},{'id': '152', 'type': 'call', 'children': ['153', '161']},{'id': '153', 'type': 'attribute', 'children': ['154', '160']},{'id': '154', 'type': 'call', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '156', 'type': 'argument_list', 'children': ['157', '158', '159']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'dataset'},{'id': '158', 'type': 'string', 'children': [], 'value': "'geospatial_lon_units'"},{'id': '159', 'type': 'string', 'children': [], 'value': "''"},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '161', 'type': 'argument_list', 'children': []},{'id': '162', 'type': 'expression_statement', 'children': ['163']},{'id': '163', 'type': 'call', 'children': ['164', '167']},{'id': '164', 'type': 'attribute', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'suggested_ctx'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'assert_true'},{'id': '167', 'type': 'argument_list', 'children': ['168', '171']},{'id': '168', 'type': 'comparison_operator', 'children': ['169', '170'], 'value': '=='},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'units'},{'id': '170', 'type': 'string', 'children': [], 'value': "'degrees_east'"},{'id': '171', 'type': 'call', 'children': ['172', '175']},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'string', 'children': [], 'value': "'geospatial_lon_units attribute should be degrees_east: {}'"},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '175', 'type': 'argument_list', 'children': ['176']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'units'},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'assignment', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'contributor_name'},{'id': '180', 'type': 'call', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '182', 'type': 'argument_list', 'children': ['183', '184', '185']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'dataset'},{'id': '184', 'type': 'string', 'children': [], 'value': "'contributor_name'"},{'id': '185', 'type': 'string', 'children': [], 'value': "''"},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'assignment', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'contributor_role'},{'id': '189', 'type': 'call', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '191', 'type': 'argument_list', 'children': ['192', '193', '194']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'dataset'},{'id': '193', 'type': 'string', 'children': [], 'value': "'contributor_role'"},{'id': '194', 'type': 'string', 'children': [], 'value': "''"},{'id': '195', 'type': 'expression_statement', 'children': ['196']},{'id': '196', 'type': 'assignment', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '198', 'type': 'call', 'children': ['199', '202']},{'id': '199', 'type': 'attribute', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'contributor_role'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '202', 'type': 'argument_list', 'children': ['203']},{'id': '203', 'type': 'string', 'children': [], 'value': "','"},{'id': '204', 'type': 'expression_statement', 'children': ['205']},{'id': '205', 'type': 'assignment', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'roles'},{'id': '207', 'type': 'call', 'children': ['208', '211']},{'id': '208', 'type': 'attribute', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'contributor_role'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '211', 'type': 'argument_list', 'children': ['212']},{'id': '212', 'type': 'string', 'children': [], 'value': "','"},{'id': '213', 'type': 'expression_statement', 'children': ['214']},{'id': '214', 'type': 'call', 'children': ['215', '218']},{'id': '215', 'type': 'attribute', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'suggested_ctx'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'assert_true'},{'id': '218', 'type': 'argument_list', 'children': ['219', '222']},{'id': '219', 'type': 'comparison_operator', 'children': ['220', '221'], 'value': '!='},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'contributor_name'},{'id': '221', 'type': 'string', 'children': [], 'value': "''"},{'id': '222', 'type': 'string', 'children': [], 'value': "'contributor_name should exist and not be empty.'"},{'id': '223', 'type': 'expression_statement', 'children': ['224']},{'id': '224', 'type': 'call', 'children': ['225', '228']},{'id': '225', 'type': 'attribute', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'suggested_ctx'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'assert_true'},{'id': '228', 'type': 'argument_list', 'children': ['229', '238']},{'id': '229', 'type': 'comparison_operator', 'children': ['230', '234'], 'value': '=='},{'id': '230', 'type': 'call', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '232', 'type': 'argument_list', 'children': ['233']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '234', 'type': 'call', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '236', 'type': 'argument_list', 'children': ['237']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'roles'},{'id': '238', 'type': 'string', 'children': [], 'value': "'length of contributor names matches length of roles'"},{'id': '239', 'type': 'expression_statement', 'children': ['240']},{'id': '240', 'type': 'call', 'children': ['241', '244']},{'id': '241', 'type': 'attribute', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'suggested_ctx'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'assert_true'},{'id': '244', 'type': 'argument_list', 'children': ['245', '248']},{'id': '245', 'type': 'comparison_operator', 'children': ['246', '247'], 'value': '!='},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'contributor_role'},{'id': '247', 'type': 'string', 'children': [], 'value': "''"},{'id': '248', 'type': 'string', 'children': [], 'value': "'contributor_role should exist and not be empty.'"},{'id': '249', 'type': 'expression_statement', 'children': ['250']},{'id': '250', 'type': 'call', 'children': ['251', '254']},{'id': '251', 'type': 'attribute', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'suggested_ctx'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'assert_true'},{'id': '254', 'type': 'argument_list', 'children': ['255', '264']},{'id': '255', 'type': 'comparison_operator', 'children': ['256', '260'], 'value': '=='},{'id': '256', 'type': 'call', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '258', 'type': 'argument_list', 'children': ['259']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '260', 'type': 'call', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '262', 'type': 'argument_list', 'children': ['263']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'roles'},{'id': '264', 'type': 'string', 'children': [], 'value': "'length of contributor names matches length of roles'"},{'id': '265', 'type': 'return_statement', 'children': ['266']},{'id': '266', 'type': 'call', 'children': ['267', '270']},{'id': '267', 'type': 'attribute', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'suggested_ctx'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'to_result'},{'id': '270', 'type': 'argument_list', 'children': []}
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') 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)) 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, '') 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()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'load_from_args_as_dataframe'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '5', 'type': 'block', 'children': ['6', '8', '21', '58', '67', '71', '185', '281', '290', '313', '323', '346', '365', '387', '409', '424', '453']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'string', 'children': [], 'value': "'''\n Given parsed variant-loading arguments, return a pandas DataFrame.\n If no variant loading arguments are specified, return None.\n '''"},{'id': '8', 'type': 'if_statement', 'children': ['9', '18']},{'id': '9', 'type': 'boolean_operator', 'children': ['10', '14'], 'value': 'and'},{'id': '10', 'type': 'not_operator', 'children': ['11']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'variants'},{'id': '14', 'type': 'not_operator', 'children': ['15']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'single_variant'},{'id': '18', 'type': 'block', 'children': ['19']},{'id': '19', 'type': 'return_statement', 'children': ['20']},{'id': '20', 'type': 'None', 'children': []},{'id': '21', 'type': 'if_statement', 'children': ['22', '25', '45']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'variant_source_name'},{'id': '25', 'type': 'block', 'children': ['26']},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'variant_source_names'},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'util'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'expand'},{'id': '33', 'type': 'argument_list', 'children': ['34', '37', '38', '39']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'variant_source_name'},{'id': '37', 'type': 'string', 'children': [], 'value': "'variant_source_name'"},{'id': '38', 'type': 'string', 'children': [], 'value': "'variant source'"},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'variants'},{'id': '45', 'type': 'else_clause', 'children': ['46']},{'id': '46', 'type': 'block', 'children': ['47']},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'variant_source_names'},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'util'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'drop_prefix'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'variants'},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'variant_to_sources'},{'id': '61', 'type': 'call', 'children': ['62', '65']},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'collections'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'defaultdict'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'dfs'},{'id': '70', 'type': 'list', 'children': [], 'value': '[]'},{'id': '71', 'type': 'for_statement', 'children': ['72', '73', '82']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '73', 'type': 'call', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'call', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'variants'},{'id': '82', 'type': 'block', 'children': ['83', '89', '106', '139']},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '86', 'type': 'subscript', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'variant_source_names'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '89', 'type': 'expression_statement', 'children': ['90']},{'id': '90', 'type': 'assignment', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '92', 'type': '()', 'children': ['93']},{'id': '93', 'type': 'conditional_expression', 'children': ['94', '95', '103'], 'value': 'if'},{'id': '94', 'type': 'string', 'children': [], 'value': "'metadata:'"},{'id': '95', 'type': 'comparison_operator', 'children': ['96', '102'], 'value': '=='},{'id': '96', 'type': 'call', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'variants'},{'id': '102', 'type': 'integer', 'children': [], 'value': '1'},{'id': '103', 'type': 'binary_operator', 'children': ['104', '105'], 'value': '%'},{'id': '104', 'type': 'string', 'children': [], 'value': '"metadata:%s:"'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'assignment', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '109', 'type': 'call', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'load_as_dataframe'},{'id': '111', 'type': 'argument_list', 'children': ['112', '117', '120', '125', '130', '136']},{'id': '112', 'type': 'subscript', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'variants'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '117', 'type': 'keyword_argument', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '120', 'type': 'keyword_argument', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'genome'},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'genome'},{'id': '125', 'type': 'keyword_argument', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'max_variants'},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'max_variants_per_source'},{'id': '130', 'type': 'keyword_argument', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'only_passing'},{'id': '132', 'type': 'not_operator', 'children': ['133']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'include_failing_variants'},{'id': '136', 'type': 'keyword_argument', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'metadata_column_prefix'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '139', 'type': 'if_statement', 'children': ['140', '147', '161']},{'id': '140', 'type': 'comparison_operator', 'children': ['141', '146'], 'value': '=='},{'id': '141', 'type': 'subscript', 'children': ['142', '145']},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '145', 'type': 'integer', 'children': [], 'value': '0'},{'id': '146', 'type': 'integer', 'children': [], 'value': '0'},{'id': '147', 'type': 'block', 'children': ['148']},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'call', 'children': ['150', '153']},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'warn'},{'id': '153', 'type': 'argument_list', 'children': ['154']},{'id': '154', 'type': 'binary_operator', 'children': ['155', '156'], 'value': '%'},{'id': '155', 'type': 'string', 'children': [], 'value': '"No variants loaded from: %s"'},{'id': '156', 'type': 'subscript', 'children': ['157', '160']},{'id': '157', 'type': 'attribute', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'variants'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '161', 'type': 'else_clause', 'children': ['162']},{'id': '162', 'type': 'block', 'children': ['163', '178']},{'id': '163', 'type': 'for_statement', 'children': ['164', '165', '168']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '168', 'type': 'block', 'children': ['169']},{'id': '169', 'type': 'expression_statement', 'children': ['170']},{'id': '170', 'type': 'call', 'children': ['171', '176']},{'id': '171', 'type': 'attribute', 'children': ['172', '175']},{'id': '172', 'type': 'subscript', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'variant_to_sources'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '176', 'type': 'argument_list', 'children': ['177']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '178', 'type': 'expression_statement', 'children': ['179']},{'id': '179', 'type': 'call', 'children': ['180', '183']},{'id': '180', 'type': 'attribute', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'dfs'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '183', 'type': 'argument_list', 'children': ['184']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '185', 'type': 'if_statement', 'children': ['186', '189']},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'single_variant'},{'id': '189', 'type': 'block', 'children': ['190', '194', '198', '219', '271']},{'id': '190', 'type': 'expression_statement', 'children': ['191']},{'id': '191', 'type': 'assignment', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'variants'},{'id': '193', 'type': 'list', 'children': [], 'value': '[]'},{'id': '194', 'type': 'expression_statement', 'children': ['195']},{'id': '195', 'type': 'assignment', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'extra_args'},{'id': '197', 'type': 'dictionary', 'children': []},{'id': '198', 'type': 'if_statement', 'children': ['199', '202']},{'id': '199', 'type': 'attribute', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'genome'},{'id': '202', 'type': 'block', 'children': ['203']},{'id': '203', 'type': 'expression_statement', 'children': ['204']},{'id': '204', 'type': 'assignment', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'extra_args'},{'id': '206', 'type': 'dictionary', 'children': ['207']},{'id': '207', 'type': 'pair', 'children': ['208', '209']},{'id': '208', 'type': 'string', 'children': [], 'value': "'ensembl'"},{'id': '209', 'type': 'call', 'children': ['210', '215']},{'id': '210', 'type': 'attribute', 'children': ['211', '214']},{'id': '211', 'type': 'attribute', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'varcode'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'reference'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'infer_genome'},{'id': '215', 'type': 'argument_list', 'children': ['216']},{'id': '216', 'type': 'attribute', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'genome'},{'id': '219', 'type': 'for_statement', 'children': ['220', '224', '227']},{'id': '220', 'type': 'tuple_pattern', 'children': ['221', '222', '223']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'locus_str'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'ref'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'alt'},{'id': '224', 'type': 'attribute', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'single_variant'},{'id': '227', 'type': 'block', 'children': ['228', '237', '255', '262']},{'id': '228', 'type': 'expression_statement', 'children': ['229']},{'id': '229', 'type': 'assignment', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'locus'},{'id': '231', 'type': 'call', 'children': ['232', '235']},{'id': '232', 'type': 'attribute', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'Locus'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'parse'},{'id': '235', 'type': 'argument_list', 'children': ['236']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'locus_str'},{'id': '237', 'type': 'expression_statement', 'children': ['238']},{'id': '238', 'type': 'assignment', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '240', 'type': 'call', 'children': ['241', '244']},{'id': '241', 'type': 'attribute', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'varcode'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'Variant'},{'id': '244', 'type': 'argument_list', 'children': ['245', '248', '251', '252', '253']},{'id': '245', 'type': 'attribute', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'locus'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'contig'},{'id': '248', 'type': 'attribute', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'locus'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'inclusive_start'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'ref'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'alt'},{'id': '253', 'type': 'dictionary_splat', 'children': ['254']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'extra_args'},{'id': '255', 'type': 'expression_statement', 'children': ['256']},{'id': '256', 'type': 'call', 'children': ['257', '260']},{'id': '257', 'type': 'attribute', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'variants'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '260', 'type': 'argument_list', 'children': ['261']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '262', 'type': 'expression_statement', 'children': ['263']},{'id': '263', 'type': 'call', 'children': ['264', '269']},{'id': '264', 'type': 'attribute', 'children': ['265', '268']},{'id': '265', 'type': 'subscript', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'variant_to_sources'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '269', 'type': 'argument_list', 'children': ['270']},{'id': '270', 'type': 'string', 'children': [], 'value': '"commandline"'},{'id': '271', 'type': 'expression_statement', 'children': ['272']},{'id': '272', 'type': 'call', 'children': ['273', '276']},{'id': '273', 'type': 'attribute', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'dfs'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '276', 'type': 'argument_list', 'children': ['277']},{'id': '277', 'type': 'call', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'variants_to_dataframe'},{'id': '279', 'type': 'argument_list', 'children': ['280']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'variants'},{'id': '281', 'type': 'expression_statement', 'children': ['282']},{'id': '282', 'type': 'assignment', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '284', 'type': 'call', 'children': ['285', '288']},{'id': '285', 'type': 'attribute', 'children': ['286', '287']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'dfs'},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '288', 'type': 'argument_list', 'children': ['289']},{'id': '289', 'type': 'integer', 'children': [], 'value': '0'},{'id': '290', 'type': 'for_statement', 'children': ['291', '292', '293']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'other_df'},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'dfs'},{'id': '293', 'type': 'block', 'children': ['294']},{'id': '294', 'type': 'expression_statement', 'children': ['295']},{'id': '295', 'type': 'assignment', 'children': ['296', '297']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '297', 'type': 'call', 'children': ['298', '301']},{'id': '298', 'type': 'attribute', 'children': ['299', '300']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'pandas'},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'merge'},{'id': '301', 'type': 'argument_list', 'children': ['302', '303', '304', '307']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'other_df'},{'id': '304', 'type': 'keyword_argument', 'children': ['305', '306']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'how'},{'id': '306', 'type': 'string', 'children': [], 'value': "'outer'"},{'id': '307', 'type': 'keyword_argument', 'children': ['308', '309']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'on'},{'id': '309', 'type': 'binary_operator', 'children': ['310', '312'], 'value': '+'},{'id': '310', 'type': 'list', 'children': ['311'], 'value': '["variant"]'},{'id': '311', 'type': 'string', 'children': [], 'value': '"variant"'},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'STANDARD_DATAFRAME_COLUMNS'},{'id': '313', 'type': 'expression_statement', 'children': ['314']},{'id': '314', 'type': 'assignment', 'children': ['315', '316']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'genomes'},{'id': '316', 'type': 'call', 'children': ['317', '322']},{'id': '317', 'type': 'attribute', 'children': ['318', '321']},{'id': '318', 'type': 'subscript', 'children': ['319', '320']},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '320', 'type': 'string', 'children': [], 'value': '"genome"'},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'unique'},{'id': '322', 'type': 'argument_list', 'children': []},{'id': '323', 'type': 'if_statement', 'children': ['324', '330']},{'id': '324', 'type': 'comparison_operator', 'children': ['325', '329'], 'value': '>'},{'id': '325', 'type': 'call', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '327', 'type': 'argument_list', 'children': ['328']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'genomes'},{'id': '329', 'type': 'integer', 'children': [], 'value': '1'},{'id': '330', 'type': 'block', 'children': ['331']},{'id': '331', 'type': 'raise_statement', 'children': ['332']},{'id': '332', 'type': 'call', 'children': ['333', '334']},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '334', 'type': 'argument_list', 'children': ['335']},{'id': '335', 'type': 'binary_operator', 'children': ['336', '339'], 'value': '%'},{'id': '336', 'type': 'concatenated_string', 'children': ['337', '338']},{'id': '337', 'type': 'string', 'children': [], 'value': '"Mixing references is not supported. "'},{'id': '338', 'type': 'string', 'children': [], 'value': '"Reference genomes: %s"'},{'id': '339', 'type': '()', 'children': ['340']},{'id': '340', 'type': 'call', 'children': ['341', '344']},{'id': '341', 'type': 'attribute', 'children': ['342', '343']},{'id': '342', 'type': 'string', 'children': [], 'value': '", "'},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '344', 'type': 'argument_list', 'children': ['345']},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'genomes'},{'id': '346', 'type': 'expression_statement', 'children': ['347']},{'id': '347', 'type': 'assignment', 'children': ['348', '351']},{'id': '348', 'type': 'subscript', 'children': ['349', '350']},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '350', 'type': 'string', 'children': [], 'value': '"sources"'},{'id': '351', 'type': 'list_comprehension', 'children': ['352', '360']},{'id': '352', 'type': 'call', 'children': ['353', '356']},{'id': '353', 'type': 'attribute', 'children': ['354', '355']},{'id': '354', 'type': 'string', 'children': [], 'value': '" "'},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '356', 'type': 'argument_list', 'children': ['357']},{'id': '357', 'type': 'subscript', 'children': ['358', '359']},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'variant_to_sources'},{'id': '359', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '360', 'type': 'for_in_clause', 'children': ['361', '362']},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '362', 'type': 'attribute', 'children': ['363', '364']},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '364', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '365', 'type': 'if_statement', 'children': ['366', '369']},{'id': '366', 'type': 'attribute', 'children': ['367', '368']},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'ref'},{'id': '369', 'type': 'block', 'children': ['370']},{'id': '370', 'type': 'expression_statement', 'children': ['371']},{'id': '371', 'type': 'assignment', 'children': ['372', '373']},{'id': '372', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '373', 'type': 'subscript', 'children': ['374', '377']},{'id': '374', 'type': 'attribute', 'children': ['375', '376']},{'id': '375', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '376', 'type': 'identifier', 'children': [], 'value': 'ix'},{'id': '377', 'type': 'call', 'children': ['378', '383']},{'id': '378', 'type': 'attribute', 'children': ['379', '382']},{'id': '379', 'type': 'attribute', 'children': ['380', '381']},{'id': '380', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '381', 'type': 'identifier', 'children': [], 'value': 'ref'},{'id': '382', 'type': 'identifier', 'children': [], 'value': 'isin'},{'id': '383', 'type': 'argument_list', 'children': ['384']},{'id': '384', 'type': 'attribute', 'children': ['385', '386']},{'id': '385', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '386', 'type': 'identifier', 'children': [], 'value': 'ref'},{'id': '387', 'type': 'if_statement', 'children': ['388', '391']},{'id': '388', 'type': 'attribute', 'children': ['389', '390']},{'id': '389', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '390', 'type': 'identifier', 'children': [], 'value': 'alt'},{'id': '391', 'type': 'block', 'children': ['392']},{'id': '392', 'type': 'expression_statement', 'children': ['393']},{'id': '393', 'type': 'assignment', 'children': ['394', '395']},{'id': '394', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '395', 'type': 'subscript', 'children': ['396', '399']},{'id': '396', 'type': 'attribute', 'children': ['397', '398']},{'id': '397', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '398', 'type': 'identifier', 'children': [], 'value': 'ix'},{'id': '399', 'type': 'call', 'children': ['400', '405']},{'id': '400', 'type': 'attribute', 'children': ['401', '404']},{'id': '401', 'type': 'attribute', 'children': ['402', '403']},{'id': '402', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '403', 'type': 'identifier', 'children': [], 'value': 'alt'},{'id': '404', 'type': 'identifier', 'children': [], 'value': 'isin'},{'id': '405', 'type': 'argument_list', 'children': ['406']},{'id': '406', 'type': 'attribute', 'children': ['407', '408']},{'id': '407', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '408', 'type': 'identifier', 'children': [], 'value': 'alt'},{'id': '409', 'type': 'expression_statement', 'children': ['410']},{'id': '410', 'type': 'assignment', 'children': ['411', '412']},{'id': '411', 'type': 'identifier', 'children': [], 'value': 'loci'},{'id': '412', 'type': 'call', 'children': ['413', '416']},{'id': '413', 'type': 'attribute', 'children': ['414', '415']},{'id': '414', 'type': 'identifier', 'children': [], 'value': 'loci_util'},{'id': '415', 'type': 'identifier', 'children': [], 'value': 'load_from_args'},{'id': '416', 'type': 'argument_list', 'children': ['417']},{'id': '417', 'type': 'call', 'children': ['418', '421']},{'id': '418', 'type': 'attribute', 'children': ['419', '420']},{'id': '419', 'type': 'identifier', 'children': [], 'value': 'util'},{'id': '420', 'type': 'identifier', 'children': [], 'value': 'remove_prefix_from_parsed_args'},{'id': '421', 'type': 'argument_list', 'children': ['422', '423']},{'id': '422', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '423', 'type': 'string', 'children': [], 'value': '"variant"'},{'id': '424', 'type': 'if_statement', 'children': ['425', '428']},{'id': '425', 'type': 'comparison_operator', 'children': ['426', '427'], 'value': 'is'},{'id': '426', 'type': 'identifier', 'children': [], 'value': 'loci'},{'id': '427', 'type': 'None', 'children': []},{'id': '428', 'type': 'block', 'children': ['429']},{'id': '429', 'type': 'expression_statement', 'children': ['430']},{'id': '430', 'type': 'assignment', 'children': ['431', '432']},{'id': '431', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '432', 'type': 'subscript', 'children': ['433', '436']},{'id': '433', 'type': 'attribute', 'children': ['434', '435']},{'id': '434', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '435', 'type': 'identifier', 'children': [], 'value': 'ix'},{'id': '436', 'type': 'list_comprehension', 'children': ['437', '448']},{'id': '437', 'type': 'call', 'children': ['438', '441']},{'id': '438', 'type': 'attribute', 'children': ['439', '440']},{'id': '439', 'type': 'identifier', 'children': [], 'value': 'loci'},{'id': '440', 'type': 'identifier', 'children': [], 'value': 'intersects'},{'id': '441', 'type': 'argument_list', 'children': ['442']},{'id': '442', 'type': 'call', 'children': ['443', '446']},{'id': '443', 'type': 'attribute', 'children': ['444', '445']},{'id': '444', 'type': 'identifier', 'children': [], 'value': 'pileup_collection'},{'id': '445', 'type': 'identifier', 'children': [], 'value': 'to_locus'},{'id': '446', 'type': 'argument_list', 'children': ['447']},{'id': '447', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '448', 'type': 'for_in_clause', 'children': ['449', '450']},{'id': '449', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '450', 'type': 'attribute', 'children': ['451', '452']},{'id': '451', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '452', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '453', 'type': 'return_statement', 'children': ['454']},{'id': '454', 'type': 'identifier', 'children': [], 'value': '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] 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
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'protected'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'list_splat_pattern', 'children': ['6']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'tests'},{'id': '7', 'type': 'dictionary_splat_pattern', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '9', 'type': 'block', 'children': ['10', '20', '32', '42', '52', '62', '72', '83', '87', '91', '387']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': '_role'},{'id': '13', 'type': 'call', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '17', 'type': 'argument_list', 'children': ['18', '19']},{'id': '18', 'type': 'string', 'children': [], 'value': "'role'"},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': '_roles'},{'id': '23', 'type': 'boolean_operator', 'children': ['24', '31'], 'value': 'or'},{'id': '24', 'type': 'call', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '28', 'type': 'argument_list', 'children': ['29', '30']},{'id': '29', 'type': 'string', 'children': [], 'value': "'roles'"},{'id': '30', 'type': 'None', 'children': []},{'id': '31', 'type': 'list', 'children': [], 'value': '[]'},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': '_csrf'},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '39', 'type': 'argument_list', 'children': ['40', '41']},{'id': '40', 'type': 'string', 'children': [], 'value': "'csrf'"},{'id': '41', 'type': 'None', 'children': []},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': '_url_sign_in'},{'id': '45', 'type': 'call', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '49', 'type': 'argument_list', 'children': ['50', '51']},{'id': '50', 'type': 'string', 'children': [], 'value': "'url_sign_in'"},{'id': '51', 'type': 'None', 'children': []},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': '_request'},{'id': '55', 'type': 'call', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '59', 'type': 'argument_list', 'children': ['60', '61']},{'id': '60', 'type': 'string', 'children': [], 'value': "'request'"},{'id': '61', 'type': 'None', 'children': []},{'id': '62', 'type': 'if_statement', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': '_role'},{'id': '64', 'type': 'block', 'children': ['65']},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'call', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': '_roles'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'identifier', 'children': [], 'value': '_role'},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': '_roles'},{'id': '75', 'type': 'list_comprehension', 'children': ['76', '80']},{'id': '76', 'type': 'call', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'to_unicode'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '80', 'type': 'for_in_clause', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '82', 'type': 'identifier', 'children': [], 'value': '_roles'},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': '_tests'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'tests'},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': '_user_tests'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '91', 'type': 'function_definition', 'children': ['92', '93', '95']},{'id': '92', 'type': 'function_name', 'children': [], 'value': 'decorator'},{'id': '93', 'type': 'parameters', 'children': ['94']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '95', 'type': 'block', 'children': ['96', '385']},{'id': '96', 'type': 'decorated_definition', 'children': ['97', '104']},{'id': '97', 'type': 'decorator', 'children': ['98']},{'id': '98', 'type': 'call', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'functools'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'wraps'},{'id': '102', 'type': 'argument_list', 'children': ['103']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '104', 'type': 'function_definition', 'children': ['105', '106', '111']},{'id': '105', 'type': 'function_name', 'children': [], 'value': 'wrapper'},{'id': '106', 'type': 'parameters', 'children': ['107', '109']},{'id': '107', 'type': 'list_splat_pattern', 'children': ['108']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '109', 'type': 'dictionary_splat_pattern', 'children': ['110']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '111', 'type': 'block', 'children': ['112', '121', '135', '145', '153', '165', '226', '267', '322', '328', '377']},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'assignment', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '115', 'type': 'call', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'getLogger'},{'id': '119', 'type': 'argument_list', 'children': ['120']},{'id': '120', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'assignment', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '124', 'type': 'boolean_operator', 'children': ['125', '130'], 'value': 'or'},{'id': '125', 'type': 'boolean_operator', 'children': ['126', '127'], 'value': 'or'},{'id': '126', 'type': 'identifier', 'children': [], 'value': '_request'},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '130', 'type': 'boolean_operator', 'children': ['131', '132'], 'value': 'and'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '132', 'type': 'subscript', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '134', 'type': 'integer', 'children': [], 'value': '0'},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'assignment', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'url_sign_in'},{'id': '138', 'type': 'call', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '141', 'type': 'identifier', 'children': [], 'value': '_get_url_sign_in'},{'id': '142', 'type': 'argument_list', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '144', 'type': 'identifier', 'children': [], 'value': '_url_sign_in'},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'assignment', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '148', 'type': 'call', 'children': ['149', '152']},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'get_user'},{'id': '152', 'type': 'argument_list', 'children': []},{'id': '153', 'type': 'if_statement', 'children': ['154', '156']},{'id': '154', 'type': 'not_operator', 'children': ['155']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '156', 'type': 'block', 'children': ['157']},{'id': '157', 'type': 'return_statement', 'children': ['158']},{'id': '158', 'type': 'call', 'children': ['159', '162']},{'id': '159', 'type': 'attribute', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '161', 'type': 'identifier', 'children': [], 'value': '_login_required'},{'id': '162', 'type': 'argument_list', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'url_sign_in'},{'id': '165', 'type': 'if_statement', 'children': ['166', '173']},{'id': '166', 'type': 'boolean_operator', 'children': ['167', '172'], 'value': 'and'},{'id': '167', 'type': 'call', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '169', 'type': 'argument_list', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '171', 'type': 'string', 'children': [], 'value': "'has_role'"},{'id': '172', 'type': 'identifier', 'children': [], 'value': '_roles'},{'id': '173', 'type': 'block', 'children': ['174']},{'id': '174', 'type': 'if_statement', 'children': ['175', '183']},{'id': '175', 'type': 'not_operator', 'children': ['176']},{'id': '176', 'type': 'call', 'children': ['177', '180']},{'id': '177', 'type': 'attribute', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'has_role'},{'id': '180', 'type': 'argument_list', 'children': ['181']},{'id': '181', 'type': 'list_splat', 'children': ['182']},{'id': '182', 'type': 'identifier', 'children': [], 'value': '_roles'},{'id': '183', 'type': 'block', 'children': ['184', '198', '218']},{'id': '184', 'type': 'expression_statement', 'children': ['185']},{'id': '185', 'type': 'call', 'children': ['186', '189']},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '189', 'type': 'argument_list', 'children': ['190']},{'id': '190', 'type': 'call', 'children': ['191', '194']},{'id': '191', 'type': 'attribute', 'children': ['192', '193']},{'id': '192', 'type': 'string', 'children': [], 'value': "u'User `{0}`: has_role fail'"},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '194', 'type': 'argument_list', 'children': ['195']},{'id': '195', 'type': 'attribute', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'login'},{'id': '198', 'type': 'expression_statement', 'children': ['199']},{'id': '199', 'type': 'call', 'children': ['200', '203']},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '203', 'type': 'argument_list', 'children': ['204']},{'id': '204', 'type': 'call', 'children': ['205', '208']},{'id': '205', 'type': 'attribute', 'children': ['206', '207']},{'id': '206', 'type': 'string', 'children': [], 'value': "u'User roles: {0}'"},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '208', 'type': 'argument_list', 'children': ['209']},{'id': '209', 'type': 'list_comprehension', 'children': ['210', '213']},{'id': '210', 'type': 'attribute', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '213', 'type': 'for_in_clause', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '215', 'type': 'attribute', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'roles'},{'id': '218', 'type': 'return_statement', 'children': ['219']},{'id': '219', 'type': 'call', 'children': ['220', '225']},{'id': '220', 'type': 'attribute', 'children': ['221', '224']},{'id': '221', 'type': 'attribute', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'wsgi'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'raise_forbidden'},{'id': '225', 'type': 'argument_list', 'children': []},{'id': '226', 'type': 'for_statement', 'children': ['227', '228', '229']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'test'},{'id': '228', 'type': 'identifier', 'children': [], 'value': '_tests'},{'id': '229', 'type': 'block', 'children': ['230', '241']},{'id': '230', 'type': 'expression_statement', 'children': ['231']},{'id': '231', 'type': 'assignment', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'test_pass'},{'id': '233', 'type': 'call', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'test'},{'id': '235', 'type': 'argument_list', 'children': ['236', '237', '239']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '237', 'type': 'list_splat', 'children': ['238']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '239', 'type': 'dictionary_splat', 'children': ['240']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '241', 'type': 'if_statement', 'children': ['242', '244']},{'id': '242', 'type': 'not_operator', 'children': ['243']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'test_pass'},{'id': '244', 'type': 'block', 'children': ['245', '259']},{'id': '245', 'type': 'expression_statement', 'children': ['246']},{'id': '246', 'type': 'call', 'children': ['247', '250']},{'id': '247', 'type': 'attribute', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '250', 'type': 'argument_list', 'children': ['251']},{'id': '251', 'type': 'call', 'children': ['252', '255']},{'id': '252', 'type': 'attribute', 'children': ['253', '254']},{'id': '253', 'type': 'string', 'children': [], 'value': "u'User `{0}`: test fail'"},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '255', 'type': 'argument_list', 'children': ['256']},{'id': '256', 'type': 'attribute', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'login'},{'id': '259', 'type': 'return_statement', 'children': ['260']},{'id': '260', 'type': 'call', 'children': ['261', '266']},{'id': '261', 'type': 'attribute', 'children': ['262', '265']},{'id': '262', 'type': 'attribute', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'wsgi'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'raise_forbidden'},{'id': '266', 'type': 'argument_list', 'children': []},{'id': '267', 'type': 'for_statement', 'children': ['268', '271', '276']},{'id': '268', 'type': 'pattern_list', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '271', 'type': 'call', 'children': ['272', '275']},{'id': '272', 'type': 'attribute', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': '_user_tests'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '275', 'type': 'argument_list', 'children': []},{'id': '276', 'type': 'block', 'children': ['277', '285', '296']},{'id': '277', 'type': 'expression_statement', 'children': ['278']},{'id': '278', 'type': 'assignment', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'user_test'},{'id': '280', 'type': 'call', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '282', 'type': 'argument_list', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '285', 'type': 'expression_statement', 'children': ['286']},{'id': '286', 'type': 'assignment', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'test_pass'},{'id': '288', 'type': 'call', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'user_test'},{'id': '290', 'type': 'argument_list', 'children': ['291', '292', '294']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '292', 'type': 'list_splat', 'children': ['293']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '294', 'type': 'dictionary_splat', 'children': ['295']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '296', 'type': 'if_statement', 'children': ['297', '299']},{'id': '297', 'type': 'not_operator', 'children': ['298']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'test_pass'},{'id': '299', 'type': 'block', 'children': ['300', '314']},{'id': '300', 'type': 'expression_statement', 'children': ['301']},{'id': '301', 'type': 'call', 'children': ['302', '305']},{'id': '302', 'type': 'attribute', 'children': ['303', '304']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '305', 'type': 'argument_list', 'children': ['306']},{'id': '306', 'type': 'call', 'children': ['307', '310']},{'id': '307', 'type': 'attribute', 'children': ['308', '309']},{'id': '308', 'type': 'string', 'children': [], 'value': "u'User `{0}`: test fail'"},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '310', 'type': 'argument_list', 'children': ['311']},{'id': '311', 'type': 'attribute', 'children': ['312', '313']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'login'},{'id': '314', 'type': 'return_statement', 'children': ['315']},{'id': '315', 'type': 'call', 'children': ['316', '321']},{'id': '316', 'type': 'attribute', 'children': ['317', '320']},{'id': '317', 'type': 'attribute', 'children': ['318', '319']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'wsgi'},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'raise_forbidden'},{'id': '321', 'type': 'argument_list', 'children': []},{'id': '322', 'type': 'expression_statement', 'children': ['323']},{'id': '323', 'type': 'assignment', 'children': ['324', '325']},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'disable_csrf'},{'id': '325', 'type': 'comparison_operator', 'children': ['326', '327'], 'value': '=='},{'id': '326', 'type': 'identifier', 'children': [], 'value': '_csrf'},{'id': '327', 'type': 'False', 'children': []},{'id': '328', 'type': 'if_statement', 'children': ['329', '344']},{'id': '329', 'type': 'boolean_operator', 'children': ['330', '343'], 'value': 'or'},{'id': '330', 'type': '()', 'children': ['331']},{'id': '331', 'type': 'boolean_operator', 'children': ['332', '341'], 'value': 'and'},{'id': '332', 'type': 'not_operator', 'children': ['333']},{'id': '333', 'type': 'call', 'children': ['334', '339']},{'id': '334', 'type': 'attribute', 'children': ['335', '338']},{'id': '335', 'type': 'attribute', 'children': ['336', '337']},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'wsgi'},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'is_idempotent'},{'id': '339', 'type': 'argument_list', 'children': ['340']},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '341', 'type': 'not_operator', 'children': ['342']},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'disable_csrf'},{'id': '343', 'type': 'identifier', 'children': [], 'value': '_csrf'},{'id': '344', 'type': 'block', 'children': ['345']},{'id': '345', 'type': 'if_statement', 'children': ['346', '353']},{'id': '346', 'type': 'not_operator', 'children': ['347']},{'id': '347', 'type': 'call', 'children': ['348', '351']},{'id': '348', 'type': 'attribute', 'children': ['349', '350']},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'csrf_token_is_valid'},{'id': '351', 'type': 'argument_list', 'children': ['352']},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '353', 'type': 'block', 'children': ['354', '368']},{'id': '354', 'type': 'expression_statement', 'children': ['355']},{'id': '355', 'type': 'call', 'children': ['356', '359']},{'id': '356', 'type': 'attribute', 'children': ['357', '358']},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '359', 'type': 'argument_list', 'children': ['360']},{'id': '360', 'type': 'call', 'children': ['361', '364']},{'id': '361', 'type': 'attribute', 'children': ['362', '363']},{'id': '362', 'type': 'string', 'children': [], 'value': "u'User `{0}`: invalid CSFR token'"},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '364', 'type': 'argument_list', 'children': ['365']},{'id': '365', 'type': 'attribute', 'children': ['366', '367']},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'login'},{'id': '368', 'type': 'return_statement', 'children': ['369']},{'id': '369', 'type': 'call', 'children': ['370', '375']},{'id': '370', 'type': 'attribute', 'children': ['371', '374']},{'id': '371', 'type': 'attribute', 'children': ['372', '373']},{'id': '372', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '373', 'type': 'identifier', 'children': [], 'value': 'wsgi'},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'raise_forbidden'},{'id': '375', 'type': 'argument_list', 'children': ['376']},{'id': '376', 'type': 'string', 'children': [], 'value': '"CSFR token isn\'t valid"'},{'id': '377', 'type': 'return_statement', 'children': ['378']},{'id': '378', 'type': 'call', 'children': ['379', '380']},{'id': '379', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '380', 'type': 'argument_list', 'children': ['381', '383']},{'id': '381', 'type': 'list_splat', 'children': ['382']},{'id': '382', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '383', 'type': 'dictionary_splat', 'children': ['384']},{'id': '384', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '385', 'type': 'return_statement', 'children': ['386']},{'id': '386', 'type': 'identifier', 'children': [], 'value': 'wrapper'},{'id': '387', 'type': 'return_statement', 'children': ['388']},{'id': '388', 'type': 'identifier', 'children': [], 'value': 'decorator'}
def protected(self, *tests, **kwargs): _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 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
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_verify_multi'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'verifying_keys'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'num_required'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'block', 'children': ['11', '22', '34', '44', '60', '74', '98', '114', '118', '179']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '18']},{'id': '13', 'type': 'pattern_list', 'children': ['14', '15', '16', '17']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'payload'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'raw_signatures'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'signing_inputs'},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': '_unpack_token_json'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '22', 'type': 'if_statement', 'children': ['23', '26']},{'id': '23', 'type': 'comparison_operator', 'children': ['24', '25'], 'value': 'is'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'num_required'},{'id': '25', 'type': 'None', 'children': []},{'id': '26', 'type': 'block', 'children': ['27']},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'num_required'},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'raw_signatures'},{'id': '34', 'type': 'if_statement', 'children': ['35', '41']},{'id': '35', 'type': 'comparison_operator', 'children': ['36', '37'], 'value': '>'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'num_required'},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'verifying_keys'},{'id': '41', 'type': 'block', 'children': ['42']},{'id': '42', 'type': 'return_statement', 'children': ['43']},{'id': '43', 'type': 'False', 'children': []},{'id': '44', 'type': 'if_statement', 'children': ['45', '54']},{'id': '45', 'type': 'comparison_operator', 'children': ['46', '50'], 'value': '!='},{'id': '46', 'type': 'call', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'raw_signatures'},{'id': '54', 'type': 'block', 'children': ['55']},{'id': '55', 'type': 'raise_statement', 'children': ['56']},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'DecodeError'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'string', 'children': [], 'value': "'Header/signature mismatch'"},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'verifying_keys'},{'id': '63', 'type': 'list_comprehension', 'children': ['64', '71']},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'load_verifying_key'},{'id': '66', 'type': 'argument_list', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'vk'},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'crypto_backend'},{'id': '71', 'type': 'for_in_clause', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'vk'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'verifying_keys'},{'id': '74', 'type': 'for_statement', 'children': ['75', '76', '77']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'vk'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'verifying_keys'},{'id': '77', 'type': 'block', 'children': ['78']},{'id': '78', 'type': 'if_statement', 'children': ['79', '92']},{'id': '79', 'type': 'comparison_operator', 'children': ['80', '85'], 'value': '!='},{'id': '80', 'type': 'attribute', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'vk'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'curve'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '85', 'type': 'attribute', 'children': ['86', '91']},{'id': '86', 'type': 'attribute', 'children': ['87', '90']},{'id': '87', 'type': 'subscript', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'verifying_keys'},{'id': '89', 'type': 'integer', 'children': [], 'value': '0'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'curve'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '92', 'type': 'block', 'children': ['93']},{'id': '93', 'type': 'raise_statement', 'children': ['94']},{'id': '94', 'type': 'call', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'DecodeError'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'string', 'children': [], 'value': '"TODO: only support using keys from one curve per JWT"'},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'der_signatures'},{'id': '101', 'type': 'list_comprehension', 'children': ['102', '111']},{'id': '102', 'type': 'call', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'raw_to_der_signature'},{'id': '104', 'type': 'argument_list', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'rs'},{'id': '106', 'type': 'attribute', 'children': ['107', '110']},{'id': '107', 'type': 'subscript', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'verifying_keys'},{'id': '109', 'type': 'integer', 'children': [], 'value': '0'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'curve'},{'id': '111', 'type': 'for_in_clause', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'rs'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'raw_signatures'},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'assignment', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'num_verified'},{'id': '117', 'type': 'integer', 'children': [], 'value': '0'},{'id': '118', 'type': 'for_statement', 'children': ['119', '122', '127']},{'id': '119', 'type': 'tuple_pattern', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'signing_input'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'der_sig'},{'id': '122', 'type': 'call', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '124', 'type': 'argument_list', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'signing_inputs'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'der_signatures'},{'id': '127', 'type': 'block', 'children': ['128', '173']},{'id': '128', 'type': 'for_statement', 'children': ['129', '130', '131']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'vk'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'verifying_keys'},{'id': '131', 'type': 'block', 'children': ['132', '142', '149']},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'assignment', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'verifier'},{'id': '135', 'type': 'call', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '138', 'type': 'identifier', 'children': [], 'value': '_get_verifier'},{'id': '139', 'type': 'argument_list', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'vk'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'der_sig'},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'call', 'children': ['144', '147']},{'id': '144', 'type': 'attribute', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'verifier'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '147', 'type': 'argument_list', 'children': ['148']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'signing_input'},{'id': '149', 'type': 'try_statement', 'children': ['150', '169']},{'id': '150', 'type': 'block', 'children': ['151', '157', '161', '168']},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'call', 'children': ['153', '156']},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'verifier'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'verify'},{'id': '156', 'type': 'argument_list', 'children': []},{'id': '157', 'type': 'expression_statement', 'children': ['158']},{'id': '158', 'type': 'augmented_assignment', 'children': ['159', '160'], 'value': '+='},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'num_verified'},{'id': '160', 'type': 'integer', 'children': [], 'value': '1'},{'id': '161', 'type': 'expression_statement', 'children': ['162']},{'id': '162', 'type': 'call', 'children': ['163', '166']},{'id': '163', 'type': 'attribute', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'verifying_keys'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'remove'},{'id': '166', 'type': 'argument_list', 'children': ['167']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'vk'},{'id': '168', 'type': 'break_statement', 'children': []},{'id': '169', 'type': 'except_clause', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'InvalidSignature'},{'id': '171', 'type': 'block', 'children': ['172']},{'id': '172', 'type': 'pass_statement', 'children': []},{'id': '173', 'type': 'if_statement', 'children': ['174', '177']},{'id': '174', 'type': 'comparison_operator', 'children': ['175', '176'], 'value': '>='},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'num_verified'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'num_required'},{'id': '177', 'type': 'block', 'children': ['178']},{'id': '178', 'type': 'break_statement', 'children': []},{'id': '179', 'type': 'return_statement', 'children': ['180']},{'id': '180', 'type': '()', 'children': ['181']},{'id': '181', 'type': 'comparison_operator', 'children': ['182', '183'], 'value': '>='},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'num_verified'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'num_required'}
def _verify_multi(self, token, verifying_keys, num_required=None): 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): return False if len(headers) != len(raw_signatures): raise DecodeError('Header/signature mismatch') verifying_keys = [load_verifying_key(vk, self.crypto_backend) for vk in verifying_keys] 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] 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)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse_pic_field'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'last_section_node'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'last_vars'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '9', 'type': 'block', 'children': ['10', '14', '23', '27', '50', '95', '105', '118', '131', '162', '210', '223', '270', '276', '296', '311', '318', '324', '338', '354']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'parent_node'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'raw_tokens'},{'id': '17', 'type': 'call', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'string', 'children': [], 'value': '" "'},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '26', 'type': 'list', 'children': [], 'value': '[]'},{'id': '27', 'type': 'for_statement', 'children': ['28', '29', '30']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'raw_tokens'},{'id': '30', 'type': 'block', 'children': ['31']},{'id': '31', 'type': 'if_statement', 'children': ['32', '42']},{'id': '32', 'type': 'boolean_operator', 'children': ['33', '39'], 'value': 'and'},{'id': '33', 'type': 'not_operator', 'children': ['34']},{'id': '34', 'type': 'call', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'isspace'},{'id': '38', 'type': 'argument_list', 'children': []},{'id': '39', 'type': 'comparison_operator', 'children': ['40', '41'], 'value': '!='},{'id': '40', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '41', 'type': 'string', 'children': [], 'value': '""'},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'call', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '50', 'type': 'try_statement', 'children': ['51', '85', '90']},{'id': '51', 'type': 'block', 'children': ['52', '79']},{'id': '52', 'type': 'if_statement', 'children': ['53', '62', '67']},{'id': '53', 'type': 'comparison_operator', 'children': ['54', '61'], 'value': '=='},{'id': '54', 'type': 'call', 'children': ['55', '60']},{'id': '55', 'type': 'attribute', 'children': ['56', '59']},{'id': '56', 'type': 'subscript', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '58', 'type': 'integer', 'children': [], 'value': '0'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '60', 'type': 'argument_list', 'children': []},{'id': '61', 'type': 'string', 'children': [], 'value': '"FD"'},{'id': '62', 'type': 'block', 'children': ['63']},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'lvl'},{'id': '66', 'type': 'integer', 'children': [], 'value': '1'},{'id': '67', 'type': 'else_clause', 'children': ['68']},{'id': '68', 'type': 'block', 'children': ['69']},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'lvl'},{'id': '72', 'type': 'call', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '74', 'type': 'argument_list', 'children': ['75', '78']},{'id': '75', 'type': 'subscript', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '77', 'type': 'integer', 'children': [], 'value': '0'},{'id': '78', 'type': 'integer', 'children': [], 'value': '16'},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '82', 'type': 'subscript', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '84', 'type': 'integer', 'children': [], 'value': '1'},{'id': '85', 'type': 'except_clause', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '87', 'type': 'block', 'children': ['88']},{'id': '88', 'type': 'return_statement', 'children': ['89']},{'id': '89', 'type': 'None', 'children': []},{'id': '90', 'type': 'except_clause', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'IndexError'},{'id': '92', 'type': 'block', 'children': ['93']},{'id': '93', 'type': 'return_statement', 'children': ['94']},{'id': '94', 'type': 'None', 'children': []},{'id': '95', 'type': 'expression_statement', 'children': ['96']},{'id': '96', 'type': 'assignment', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '98', 'type': 'call', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '102', 'type': 'argument_list', 'children': ['103', '104']},{'id': '103', 'type': 'string', 'children': [], 'value': '"."'},{'id': '104', 'type': 'string', 'children': [], 'value': '""'},{'id': '105', 'type': 'if_statement', 'children': ['106', '115']},{'id': '106', 'type': 'boolean_operator', 'children': ['107', '110'], 'value': 'or'},{'id': '107', 'type': 'comparison_operator', 'children': ['108', '109'], 'value': 'in'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'ALL_KEYWORDS'},{'id': '110', 'type': 'comparison_operator', 'children': ['111', '112'], 'value': 'in'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '112', 'type': 'list', 'children': ['113', '114'], 'value': "['-', '/']"},{'id': '113', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '114', 'type': 'string', 'children': [], 'value': "'/'"},{'id': '115', 'type': 'block', 'children': ['116']},{'id': '116', 'type': 'return_statement', 'children': ['117']},{'id': '117', 'type': 'None', 'children': []},{'id': '118', 'type': 'expression_statement', 'children': ['119']},{'id': '119', 'type': 'assignment', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '121', 'type': 'call', 'children': ['122', '125']},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'findall'},{'id': '125', 'type': 'argument_list', 'children': ['126', '127', '128']},{'id': '126', 'type': 'string', 'children': [], 'value': "r'pic.*\\.'"},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'IGNORECASE'},{'id': '131', 'type': 'if_statement', 'children': ['132', '133', '156']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '133', 'type': 'block', 'children': ['134']},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'assignment', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '137', 'type': 'call', 'children': ['138', '141']},{'id': '138', 'type': 'attribute', 'children': ['139', '140']},{'id': '139', 'type': 'string', 'children': [], 'value': "' '"},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '141', 'type': 'argument_list', 'children': ['142']},{'id': '142', 'type': 'list_comprehension', 'children': ['143', '144', '154']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '144', 'type': 'for_in_clause', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '146', 'type': 'call', 'children': ['147', '152']},{'id': '147', 'type': 'attribute', 'children': ['148', '151']},{'id': '148', 'type': 'subscript', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '150', 'type': 'integer', 'children': [], 'value': '0'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '152', 'type': 'argument_list', 'children': ['153']},{'id': '153', 'type': 'string', 'children': [], 'value': "' '"},{'id': '154', 'type': 'if_clause', 'children': ['155']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '156', 'type': 'else_clause', 'children': ['157']},{'id': '157', 'type': 'block', 'children': ['158']},{'id': '158', 'type': 'expression_statement', 'children': ['159']},{'id': '159', 'type': 'assignment', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '162', 'type': 'try_statement', 'children': ['163', '177', '190']},{'id': '163', 'type': 'block', 'children': ['164']},{'id': '164', 'type': 'expression_statement', 'children': ['165']},{'id': '165', 'type': 'assignment', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '167', 'type': 'call', 'children': ['168', '175']},{'id': '168', 'type': 'attribute', 'children': ['169', '174']},{'id': '169', 'type': 'call', 'children': ['170', '173']},{'id': '170', 'type': 'attribute', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '173', 'type': 'argument_list', 'children': []},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '175', 'type': 'argument_list', 'children': ['176']},{'id': '176', 'type': 'string', 'children': [], 'value': "'value'"},{'id': '177', 'type': 'except_clause', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '179', 'type': 'block', 'children': ['180']},{'id': '180', 'type': 'expression_statement', 'children': ['181']},{'id': '181', 'type': 'assignment', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '183', 'type': 'call', 'children': ['184', '187']},{'id': '184', 'type': 'attribute', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '187', 'type': 'argument_list', 'children': ['188', '189']},{'id': '188', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '189', 'type': 'string', 'children': [], 'value': "''"},{'id': '190', 'type': 'else_clause', 'children': ['191']},{'id': '191', 'type': 'block', 'children': ['192']},{'id': '192', 'type': 'expression_statement', 'children': ['193']},{'id': '193', 'type': 'assignment', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '195', 'type': 'subscript', 'children': ['196', '207']},{'id': '196', 'type': 'call', 'children': ['197', '204']},{'id': '197', 'type': 'attribute', 'children': ['198', '203']},{'id': '198', 'type': 'subscript', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '200', 'type': 'slice', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '202', 'type': 'colon', 'children': []},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '204', 'type': 'argument_list', 'children': ['205', '206']},{'id': '205', 'type': 'string', 'children': [], 'value': "'value'"},{'id': '206', 'type': 'string', 'children': [], 'value': "''"},{'id': '207', 'type': 'slice', 'children': ['208', '209']},{'id': '208', 'type': 'colon', 'children': []},{'id': '209', 'type': 'integer', 'children': [], 'value': '80'},{'id': '210', 'type': 'if_statement', 'children': ['211', '218']},{'id': '211', 'type': 'comparison_operator', 'children': ['212', '213'], 'value': '=='},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'lvl'},{'id': '213', 'type': 'call', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '215', 'type': 'argument_list', 'children': ['216', '217']},{'id': '216', 'type': 'string', 'children': [], 'value': "'78'"},{'id': '217', 'type': 'integer', 'children': [], 'value': '16'},{'id': '218', 'type': 'block', 'children': ['219']},{'id': '219', 'type': 'expression_statement', 'children': ['220']},{'id': '220', 'type': 'assignment', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'lvl'},{'id': '222', 'type': 'integer', 'children': [], 'value': '1'},{'id': '223', 'type': 'if_statement', 'children': ['224', '227', '238']},{'id': '224', 'type': 'comparison_operator', 'children': ['225', '226'], 'value': '=='},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'lvl'},{'id': '226', 'type': 'integer', 'children': [], 'value': '1'},{'id': '227', 'type': 'block', 'children': ['228', '232']},{'id': '228', 'type': 'expression_statement', 'children': ['229']},{'id': '229', 'type': 'assignment', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'parent_node'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'last_section_node'},{'id': '232', 'type': 'expression_statement', 'children': ['233']},{'id': '233', 'type': 'call', 'children': ['234', '237']},{'id': '234', 'type': 'attribute', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'last_vars'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'clear'},{'id': '237', 'type': 'argument_list', 'children': []},{'id': '238', 'type': 'else_clause', 'children': ['239']},{'id': '239', 'type': 'block', 'children': ['240', '254']},{'id': '240', 'type': 'expression_statement', 'children': ['241']},{'id': '241', 'type': 'assignment', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'levels'},{'id': '243', 'type': 'call', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '245', 'type': 'argument_list', 'children': ['246', '251']},{'id': '246', 'type': 'call', 'children': ['247', '250']},{'id': '247', 'type': 'attribute', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'last_vars'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '250', 'type': 'argument_list', 'children': []},{'id': '251', 'type': 'keyword_argument', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '253', 'type': 'True', 'children': []},{'id': '254', 'type': 'for_statement', 'children': ['255', '256', '257']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'lv'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'levels'},{'id': '257', 'type': 'block', 'children': ['258']},{'id': '258', 'type': 'if_statement', 'children': ['259', '262']},{'id': '259', 'type': 'comparison_operator', 'children': ['260', '261'], 'value': '<'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'lv'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'lvl'},{'id': '262', 'type': 'block', 'children': ['263', '269']},{'id': '263', 'type': 'expression_statement', 'children': ['264']},{'id': '264', 'type': 'assignment', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'parent_node'},{'id': '266', 'type': 'subscript', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'last_vars'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'lv'},{'id': '269', 'type': 'break_statement', 'children': []},{'id': '270', 'type': 'if_statement', 'children': ['271', '273']},{'id': '271', 'type': 'not_operator', 'children': ['272']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'parent_node'},{'id': '273', 'type': 'block', 'children': ['274']},{'id': '274', 'type': 'return_statement', 'children': ['275']},{'id': '275', 'type': 'None', 'children': []},{'id': '276', 'type': 'if_statement', 'children': ['277', '291']},{'id': '277', 'type': 'boolean_operator', 'children': ['278', '280'], 'value': 'or'},{'id': '278', 'type': 'not_operator', 'children': ['279']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '280', 'type': 'comparison_operator', 'children': ['281', '290'], 'value': '=='},{'id': '281', 'type': 'call', 'children': ['282', '289']},{'id': '282', 'type': 'attribute', 'children': ['283', '288']},{'id': '283', 'type': 'call', 'children': ['284', '287']},{'id': '284', 'type': 'attribute', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '287', 'type': 'argument_list', 'children': []},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '289', 'type': 'argument_list', 'children': []},{'id': '290', 'type': 'string', 'children': [], 'value': "'PIC'"},{'id': '291', 'type': 'block', 'children': ['292']},{'id': '292', 'type': 'expression_statement', 'children': ['293']},{'id': '293', 'type': 'assignment', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '295', 'type': 'string', 'children': [], 'value': "'FILLER'"},{'id': '296', 'type': 'expression_statement', 'children': ['297']},{'id': '297', 'type': 'assignment', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '299', 'type': 'call', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'Name'},{'id': '301', 'type': 'argument_list', 'children': ['302', '307', '308', '309', '310']},{'id': '302', 'type': 'attribute', 'children': ['303', '306']},{'id': '303', 'type': 'attribute', 'children': ['304', '305']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'Name'},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'Type'},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'Variable'},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '311', 'type': 'expression_statement', 'children': ['312']},{'id': '312', 'type': 'call', 'children': ['313', '316']},{'id': '313', 'type': 'attribute', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'parent_node'},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'add_child'},{'id': '316', 'type': 'argument_list', 'children': ['317']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '318', 'type': 'expression_statement', 'children': ['319']},{'id': '319', 'type': 'assignment', 'children': ['320', '323']},{'id': '320', 'type': 'subscript', 'children': ['321', '322']},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'last_vars'},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'lvl'},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '324', 'type': 'expression_statement', 'children': ['325']},{'id': '325', 'type': 'assignment', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'levels'},{'id': '327', 'type': 'call', 'children': ['328', '329']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '329', 'type': 'argument_list', 'children': ['330', '335']},{'id': '330', 'type': 'call', 'children': ['331', '334']},{'id': '331', 'type': 'attribute', 'children': ['332', '333']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'last_vars'},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '334', 'type': 'argument_list', 'children': []},{'id': '335', 'type': 'keyword_argument', 'children': ['336', '337']},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '337', 'type': 'True', 'children': []},{'id': '338', 'type': 'for_statement', 'children': ['339', '340', '341']},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'levels'},{'id': '341', 'type': 'block', 'children': ['342']},{'id': '342', 'type': 'if_statement', 'children': ['343', '346']},{'id': '343', 'type': 'comparison_operator', 'children': ['344', '345'], 'value': '>'},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'lvl'},{'id': '346', 'type': 'block', 'children': ['347']},{'id': '347', 'type': 'expression_statement', 'children': ['348']},{'id': '348', 'type': 'call', 'children': ['349', '352']},{'id': '349', 'type': 'attribute', 'children': ['350', '351']},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'last_vars'},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '352', 'type': 'argument_list', 'children': ['353']},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '354', 'type': 'return_statement', 'children': ['355']},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'node'}
def parse_pic_field(l, c, last_section_node, last_vars, line): 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: 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: levels = sorted(last_vars.keys(), reverse=True) for lv in levels: if lv < lvl: parent_node = last_vars[lv] break if not parent_node: 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 levels = sorted(last_vars.keys(), reverse=True) for l in levels: if l > lvl: last_vars.pop(l) return node
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'getgrouploansurl'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'idgroup'},{'id': '5', 'type': 'list_splat_pattern', 'children': ['6']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '7', 'type': 'dictionary_splat_pattern', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '9', 'type': 'block', 'children': ['10', '14', '69', '75', '109']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'getparams'},{'id': '13', 'type': 'list', 'children': [], 'value': '[]'},{'id': '14', 'type': 'if_statement', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '16', 'type': 'block', 'children': ['17', '49']},{'id': '17', 'type': 'try_statement', 'children': ['18', '42']},{'id': '18', 'type': 'block', 'children': ['19']},{'id': '19', 'type': 'if_statement', 'children': ['20', '25', '33']},{'id': '20', 'type': 'comparison_operator', 'children': ['21', '24'], 'value': '=='},{'id': '21', 'type': 'subscript', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '23', 'type': 'string', 'children': [], 'value': '"fullDetails"'},{'id': '24', 'type': 'True', 'children': []},{'id': '25', 'type': 'block', 'children': ['26']},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'getparams'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'string', 'children': [], 'value': '"fullDetails=true"'},{'id': '33', 'type': 'else_clause', 'children': ['34']},{'id': '34', 'type': 'block', 'children': ['35']},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'call', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'getparams'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'string', 'children': [], 'value': '"fullDetails=false"'},{'id': '42', 'type': 'except_clause', 'children': ['43', '47']},{'id': '43', 'type': 'as_pattern', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '45', 'type': 'as_pattern_target', 'children': ['46']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'ex'},{'id': '47', 'type': 'block', 'children': ['48']},{'id': '48', 'type': 'pass_statement', 'children': []},{'id': '49', 'type': 'try_statement', 'children': ['50', '62']},{'id': '50', 'type': 'block', 'children': ['51']},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'call', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'getparams'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'binary_operator', 'children': ['58', '59'], 'value': '%'},{'id': '58', 'type': 'string', 'children': [], 'value': '"accountState=%s"'},{'id': '59', 'type': 'subscript', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '61', 'type': 'string', 'children': [], 'value': '"accountState"'},{'id': '62', 'type': 'except_clause', 'children': ['63', '67']},{'id': '63', 'type': 'as_pattern', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '65', 'type': 'as_pattern_target', 'children': ['66']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'ex'},{'id': '67', 'type': 'block', 'children': ['68']},{'id': '68', 'type': 'pass_statement', 'children': []},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'groupidparam'},{'id': '72', 'type': 'binary_operator', 'children': ['73', '74'], 'value': '+'},{'id': '73', 'type': 'string', 'children': [], 'value': '"/"'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'idgroup'},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'assignment', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '78', 'type': 'binary_operator', 'children': ['79', '92'], 'value': '+'},{'id': '79', 'type': 'binary_operator', 'children': ['80', '91'], 'value': '+'},{'id': '80', 'type': 'binary_operator', 'children': ['81', '90'], 'value': '+'},{'id': '81', 'type': 'binary_operator', 'children': ['82', '89'], 'value': '+'},{'id': '82', 'type': 'call', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'getmambuurl'},{'id': '84', 'type': 'argument_list', 'children': ['85', '87']},{'id': '85', 'type': 'list_splat', 'children': ['86']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '87', 'type': 'dictionary_splat', 'children': ['88']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '89', 'type': 'string', 'children': [], 'value': '"groups"'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'groupidparam'},{'id': '91', 'type': 'string', 'children': [], 'value': '"/loans"'},{'id': '92', 'type': '()', 'children': ['93']},{'id': '93', 'type': 'conditional_expression', 'children': ['94', '95', '101'], 'value': 'if'},{'id': '94', 'type': 'string', 'children': [], 'value': '""'},{'id': '95', 'type': 'comparison_operator', 'children': ['96', '100'], 'value': '=='},{'id': '96', 'type': 'call', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'getparams'},{'id': '100', 'type': 'integer', 'children': [], 'value': '0'},{'id': '101', 'type': 'binary_operator', 'children': ['102', '103'], 'value': '+'},{'id': '102', 'type': 'string', 'children': [], 'value': '"?"'},{'id': '103', 'type': 'call', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'string', 'children': [], 'value': '"&"'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'getparams'},{'id': '109', 'type': 'return_statement', 'children': ['110']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'url'}
def getgrouploansurl(idgroup, *args, **kwargs): 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
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'getclientloansurl'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'idclient'},{'id': '5', 'type': 'list_splat_pattern', 'children': ['6']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '7', 'type': 'dictionary_splat_pattern', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '9', 'type': 'block', 'children': ['10', '14', '69', '75', '109']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'getparams'},{'id': '13', 'type': 'list', 'children': [], 'value': '[]'},{'id': '14', 'type': 'if_statement', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '16', 'type': 'block', 'children': ['17', '49']},{'id': '17', 'type': 'try_statement', 'children': ['18', '42']},{'id': '18', 'type': 'block', 'children': ['19']},{'id': '19', 'type': 'if_statement', 'children': ['20', '25', '33']},{'id': '20', 'type': 'comparison_operator', 'children': ['21', '24'], 'value': '=='},{'id': '21', 'type': 'subscript', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '23', 'type': 'string', 'children': [], 'value': '"fullDetails"'},{'id': '24', 'type': 'True', 'children': []},{'id': '25', 'type': 'block', 'children': ['26']},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'getparams'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'string', 'children': [], 'value': '"fullDetails=true"'},{'id': '33', 'type': 'else_clause', 'children': ['34']},{'id': '34', 'type': 'block', 'children': ['35']},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'call', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'getparams'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'string', 'children': [], 'value': '"fullDetails=false"'},{'id': '42', 'type': 'except_clause', 'children': ['43', '47']},{'id': '43', 'type': 'as_pattern', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '45', 'type': 'as_pattern_target', 'children': ['46']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'ex'},{'id': '47', 'type': 'block', 'children': ['48']},{'id': '48', 'type': 'pass_statement', 'children': []},{'id': '49', 'type': 'try_statement', 'children': ['50', '62']},{'id': '50', 'type': 'block', 'children': ['51']},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'call', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'getparams'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'binary_operator', 'children': ['58', '59'], 'value': '%'},{'id': '58', 'type': 'string', 'children': [], 'value': '"accountState=%s"'},{'id': '59', 'type': 'subscript', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '61', 'type': 'string', 'children': [], 'value': '"accountState"'},{'id': '62', 'type': 'except_clause', 'children': ['63', '67']},{'id': '63', 'type': 'as_pattern', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '65', 'type': 'as_pattern_target', 'children': ['66']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'ex'},{'id': '67', 'type': 'block', 'children': ['68']},{'id': '68', 'type': 'pass_statement', 'children': []},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'clientidparam'},{'id': '72', 'type': 'binary_operator', 'children': ['73', '74'], 'value': '+'},{'id': '73', 'type': 'string', 'children': [], 'value': '"/"'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'idclient'},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'assignment', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '78', 'type': 'binary_operator', 'children': ['79', '92'], 'value': '+'},{'id': '79', 'type': 'binary_operator', 'children': ['80', '91'], 'value': '+'},{'id': '80', 'type': 'binary_operator', 'children': ['81', '90'], 'value': '+'},{'id': '81', 'type': 'binary_operator', 'children': ['82', '89'], 'value': '+'},{'id': '82', 'type': 'call', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'getmambuurl'},{'id': '84', 'type': 'argument_list', 'children': ['85', '87']},{'id': '85', 'type': 'list_splat', 'children': ['86']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '87', 'type': 'dictionary_splat', 'children': ['88']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '89', 'type': 'string', 'children': [], 'value': '"clients"'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'clientidparam'},{'id': '91', 'type': 'string', 'children': [], 'value': '"/loans"'},{'id': '92', 'type': '()', 'children': ['93']},{'id': '93', 'type': 'conditional_expression', 'children': ['94', '95', '101'], 'value': 'if'},{'id': '94', 'type': 'string', 'children': [], 'value': '""'},{'id': '95', 'type': 'comparison_operator', 'children': ['96', '100'], 'value': '=='},{'id': '96', 'type': 'call', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'getparams'},{'id': '100', 'type': 'integer', 'children': [], 'value': '0'},{'id': '101', 'type': 'binary_operator', 'children': ['102', '103'], 'value': '+'},{'id': '102', 'type': 'string', 'children': [], 'value': '"?"'},{'id': '103', 'type': 'call', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'string', 'children': [], 'value': '"&"'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'getparams'},{'id': '109', 'type': 'return_statement', 'children': ['110']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'url'}
def getclientloansurl(idclient, *args, **kwargs): 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
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'backup_db'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'callback'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'bool_func'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'output_fname'},{'id': '7', 'type': 'list_splat_pattern', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '9', 'type': 'dictionary_splat_pattern', 'children': ['10']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '11', 'type': 'block', 'children': ['12', '17', '32', '48', '66', '101', '111', '121', '128', '226', '264', '270', '313', '365', '370', '385', '405', '419', '457', '473', '494', '510']},{'id': '12', 'type': 'import_from_statement', 'children': ['13', '15']},{'id': '13', 'type': 'dotted_name', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '15', 'type': 'dotted_name', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '17', 'type': 'try_statement', 'children': ['18', '25']},{'id': '18', 'type': 'block', 'children': ['19']},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '22', 'type': 'subscript', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '24', 'type': 'string', 'children': [], 'value': "'verbose'"},{'id': '25', 'type': 'except_clause', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '27', 'type': 'block', 'children': ['28']},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '31', 'type': 'False', 'children': []},{'id': '32', 'type': 'try_statement', 'children': ['33', '40']},{'id': '33', 'type': 'block', 'children': ['34']},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'retries'},{'id': '37', 'type': 'subscript', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '39', 'type': 'string', 'children': [], 'value': "'retries'"},{'id': '40', 'type': 'except_clause', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'retries'},{'id': '46', 'type': 'unary_operator', 'children': ['47'], 'value': '-'},{'id': '47', 'type': 'integer', 'children': [], 'value': '1'},{'id': '48', 'type': 'try_statement', 'children': ['49', '59']},{'id': '49', 'type': 'block', 'children': ['50']},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'force_download_latest'},{'id': '53', 'type': 'call', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'bool'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'subscript', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '58', 'type': 'string', 'children': [], 'value': "'force_download_latest'"},{'id': '59', 'type': 'except_clause', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '61', 'type': 'block', 'children': ['62']},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'force_download_latest'},{'id': '65', 'type': 'False', 'children': []},{'id': '66', 'type': 'if_statement', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '68', 'type': 'block', 'children': ['69', '77', '95']},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '72', 'type': 'call', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '74', 'type': 'argument_list', 'children': ['75', '76']},{'id': '75', 'type': 'string', 'children': [], 'value': "'/tmp/log_mambu_backup'"},{'id': '76', 'type': 'string', 'children': [], 'value': "'a'"},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'call', 'children': ['79', '82']},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'binary_operator', 'children': ['84', '94'], 'value': '+'},{'id': '84', 'type': 'call', 'children': ['85', '92']},{'id': '85', 'type': 'attribute', 'children': ['86', '91']},{'id': '86', 'type': 'call', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '90', 'type': 'argument_list', 'children': []},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'strftime'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'string', 'children': [], 'value': "'%Y-%m-%d %H:%M:%S'"},{'id': '94', 'type': 'string', 'children': [], 'value': '" - Mambu DB Backup\\n"'},{'id': '95', 'type': 'expression_statement', 'children': ['96']},{'id': '96', 'type': 'call', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'flush'},{'id': '100', 'type': 'argument_list', 'children': []},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'assignment', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '104', 'type': 'call', 'children': ['105', '108']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '108', 'type': 'argument_list', 'children': ['109', '110']},{'id': '109', 'type': 'string', 'children': [], 'value': "'user'"},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'apiuser'},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'assignment', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'pwd'},{'id': '114', 'type': 'call', 'children': ['115', '118']},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '118', 'type': 'argument_list', 'children': ['119', '120']},{'id': '119', 'type': 'string', 'children': [], 'value': "'pwd'"},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'apipwd'},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'assignment', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '124', 'type': 'dictionary', 'children': ['125']},{'id': '125', 'type': 'pair', 'children': ['126', '127']},{'id': '126', 'type': 'string', 'children': [], 'value': "'callback'"},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'callback'},{'id': '128', 'type': 'try_statement', 'children': ['129', '188']},{'id': '129', 'type': 'block', 'children': ['130', '145', '165']},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'assignment', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'posturl'},{'id': '133', 'type': 'call', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'iriToUri'},{'id': '135', 'type': 'argument_list', 'children': ['136']},{'id': '136', 'type': 'binary_operator', 'children': ['137', '144'], 'value': '+'},{'id': '137', 'type': 'call', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'getmambuurl'},{'id': '139', 'type': 'argument_list', 'children': ['140', '142']},{'id': '140', 'type': 'list_splat', 'children': ['141']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '142', 'type': 'dictionary_splat', 'children': ['143']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '144', 'type': 'string', 'children': [], 'value': '"database/backup"'},{'id': '145', 'type': 'if_statement', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '147', 'type': 'block', 'children': ['148', '159']},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'call', 'children': ['150', '153']},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '153', 'type': 'argument_list', 'children': ['154']},{'id': '154', 'type': 'binary_operator', 'children': ['155', '158'], 'value': '+'},{'id': '155', 'type': 'binary_operator', 'children': ['156', '157'], 'value': '+'},{'id': '156', 'type': 'string', 'children': [], 'value': '"open url: "'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'posturl'},{'id': '158', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '159', 'type': 'expression_statement', 'children': ['160']},{'id': '160', 'type': 'call', 'children': ['161', '164']},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'flush'},{'id': '164', 'type': 'argument_list', 'children': []},{'id': '165', 'type': 'expression_statement', 'children': ['166']},{'id': '166', 'type': 'assignment', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'resp'},{'id': '168', 'type': 'call', 'children': ['169', '172']},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'requests'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'post'},{'id': '172', 'type': 'argument_list', 'children': ['173', '174', '177', '183']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'posturl'},{'id': '174', 'type': 'keyword_argument', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '177', 'type': 'keyword_argument', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '179', 'type': 'dictionary', 'children': ['180']},{'id': '180', 'type': 'pair', 'children': ['181', '182']},{'id': '181', 'type': 'string', 'children': [], 'value': "'content-type'"},{'id': '182', 'type': 'string', 'children': [], 'value': "'application/json'"},{'id': '183', 'type': 'keyword_argument', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'auth'},{'id': '185', 'type': 'tuple', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'apiuser'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'apipwd'},{'id': '188', 'type': 'except_clause', 'children': ['189', '193']},{'id': '189', 'type': 'as_pattern', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '191', 'type': 'as_pattern_target', 'children': ['192']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'ex'},{'id': '193', 'type': 'block', 'children': ['194', '203', '221']},{'id': '194', 'type': 'expression_statement', 'children': ['195']},{'id': '195', 'type': 'assignment', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'mess'},{'id': '197', 'type': 'binary_operator', 'children': ['198', '199'], 'value': '%'},{'id': '198', 'type': 'string', 'children': [], 'value': '"Error requesting backup: %s"'},{'id': '199', 'type': 'call', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'repr'},{'id': '201', 'type': 'argument_list', 'children': ['202']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'ex'},{'id': '203', 'type': 'if_statement', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '205', 'type': 'block', 'children': ['206', '215']},{'id': '206', 'type': 'expression_statement', 'children': ['207']},{'id': '207', 'type': 'call', 'children': ['208', '211']},{'id': '208', 'type': 'attribute', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '211', 'type': 'argument_list', 'children': ['212']},{'id': '212', 'type': 'binary_operator', 'children': ['213', '214'], 'value': '+'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'mess'},{'id': '214', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '215', 'type': 'expression_statement', 'children': ['216']},{'id': '216', 'type': 'call', 'children': ['217', '220']},{'id': '217', 'type': 'attribute', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '220', 'type': 'argument_list', 'children': []},{'id': '221', 'type': 'raise_statement', 'children': ['222']},{'id': '222', 'type': 'call', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'MambuError'},{'id': '224', 'type': 'argument_list', 'children': ['225']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'mess'},{'id': '226', 'type': 'if_statement', 'children': ['227', '232']},{'id': '227', 'type': 'comparison_operator', 'children': ['228', '231'], 'value': '!='},{'id': '228', 'type': 'attribute', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'resp'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '231', 'type': 'integer', 'children': [], 'value': '200'},{'id': '232', 'type': 'block', 'children': ['233', '241', '259']},{'id': '233', 'type': 'expression_statement', 'children': ['234']},{'id': '234', 'type': 'assignment', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'mess'},{'id': '236', 'type': 'binary_operator', 'children': ['237', '238'], 'value': '%'},{'id': '237', 'type': 'string', 'children': [], 'value': '"Error posting request for backup: %s"'},{'id': '238', 'type': 'attribute', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'resp'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '241', 'type': 'if_statement', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '243', 'type': 'block', 'children': ['244', '253']},{'id': '244', 'type': 'expression_statement', 'children': ['245']},{'id': '245', 'type': 'call', 'children': ['246', '249']},{'id': '246', 'type': 'attribute', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '249', 'type': 'argument_list', 'children': ['250']},{'id': '250', 'type': 'binary_operator', 'children': ['251', '252'], 'value': '+'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'mess'},{'id': '252', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '253', 'type': 'expression_statement', 'children': ['254']},{'id': '254', 'type': 'call', 'children': ['255', '258']},{'id': '255', 'type': 'attribute', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '258', 'type': 'argument_list', 'children': []},{'id': '259', 'type': 'raise_statement', 'children': ['260']},{'id': '260', 'type': 'call', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'MambuCommError'},{'id': '262', 'type': 'argument_list', 'children': ['263']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'mess'},{'id': '264', 'type': 'expression_statement', 'children': ['265']},{'id': '265', 'type': 'assignment', 'children': ['266', '269']},{'id': '266', 'type': 'subscript', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '268', 'type': 'string', 'children': [], 'value': "'latest'"},{'id': '269', 'type': 'True', 'children': []},{'id': '270', 'type': 'while_statement', 'children': ['271', '277']},{'id': '271', 'type': 'boolean_operator', 'children': ['272', '273'], 'value': 'and'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'retries'},{'id': '273', 'type': 'not_operator', 'children': ['274']},{'id': '274', 'type': 'call', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'bool_func'},{'id': '276', 'type': 'argument_list', 'children': []},{'id': '277', 'type': 'block', 'children': ['278', '294', '299', '303']},{'id': '278', 'type': 'if_statement', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '280', 'type': 'block', 'children': ['281', '288']},{'id': '281', 'type': 'expression_statement', 'children': ['282']},{'id': '282', 'type': 'call', 'children': ['283', '286']},{'id': '283', 'type': 'attribute', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '286', 'type': 'argument_list', 'children': ['287']},{'id': '287', 'type': 'string', 'children': [], 'value': '"waiting...\\n"'},{'id': '288', 'type': 'expression_statement', 'children': ['289']},{'id': '289', 'type': 'call', 'children': ['290', '293']},{'id': '290', 'type': 'attribute', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'flush'},{'id': '293', 'type': 'argument_list', 'children': []},{'id': '294', 'type': 'expression_statement', 'children': ['295']},{'id': '295', 'type': 'call', 'children': ['296', '297']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'sleep'},{'id': '297', 'type': 'argument_list', 'children': ['298']},{'id': '298', 'type': 'integer', 'children': [], 'value': '10'},{'id': '299', 'type': 'expression_statement', 'children': ['300']},{'id': '300', 'type': 'augmented_assignment', 'children': ['301', '302'], 'value': '-='},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'retries'},{'id': '302', 'type': 'integer', 'children': [], 'value': '1'},{'id': '303', 'type': 'if_statement', 'children': ['304', '307']},{'id': '304', 'type': 'comparison_operator', 'children': ['305', '306'], 'value': '<'},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'retries'},{'id': '306', 'type': 'integer', 'children': [], 'value': '0'},{'id': '307', 'type': 'block', 'children': ['308']},{'id': '308', 'type': 'expression_statement', 'children': ['309']},{'id': '309', 'type': 'assignment', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'retries'},{'id': '311', 'type': 'unary_operator', 'children': ['312'], 'value': '-'},{'id': '312', 'type': 'integer', 'children': [], 'value': '1'},{'id': '313', 'type': 'if_statement', 'children': ['314', '316']},{'id': '314', 'type': 'not_operator', 'children': ['315']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'retries'},{'id': '316', 'type': 'block', 'children': ['317', '321', '339']},{'id': '317', 'type': 'expression_statement', 'children': ['318']},{'id': '318', 'type': 'assignment', 'children': ['319', '320']},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'mess'},{'id': '320', 'type': 'string', 'children': [], 'value': '"Tired of waiting, giving up..."'},{'id': '321', 'type': 'if_statement', 'children': ['322', '323']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '323', 'type': 'block', 'children': ['324', '333']},{'id': '324', 'type': 'expression_statement', 'children': ['325']},{'id': '325', 'type': 'call', 'children': ['326', '329']},{'id': '326', 'type': 'attribute', 'children': ['327', '328']},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '329', 'type': 'argument_list', 'children': ['330']},{'id': '330', 'type': 'binary_operator', 'children': ['331', '332'], 'value': '+'},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'mess'},{'id': '332', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '333', 'type': 'expression_statement', 'children': ['334']},{'id': '334', 'type': 'call', 'children': ['335', '338']},{'id': '335', 'type': 'attribute', 'children': ['336', '337']},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'flush'},{'id': '338', 'type': 'argument_list', 'children': []},{'id': '339', 'type': 'if_statement', 'children': ['340', '342', '357']},{'id': '340', 'type': 'not_operator', 'children': ['341']},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'force_download_latest'},{'id': '342', 'type': 'block', 'children': ['343', '352']},{'id': '343', 'type': 'if_statement', 'children': ['344', '345']},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '345', 'type': 'block', 'children': ['346']},{'id': '346', 'type': 'expression_statement', 'children': ['347']},{'id': '347', 'type': 'call', 'children': ['348', '351']},{'id': '348', 'type': 'attribute', 'children': ['349', '350']},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '351', 'type': 'argument_list', 'children': []},{'id': '352', 'type': 'raise_statement', 'children': ['353']},{'id': '353', 'type': 'call', 'children': ['354', '355']},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'MambuError'},{'id': '355', 'type': 'argument_list', 'children': ['356']},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'mess'},{'id': '357', 'type': 'else_clause', 'children': ['358']},{'id': '358', 'type': 'block', 'children': ['359']},{'id': '359', 'type': 'expression_statement', 'children': ['360']},{'id': '360', 'type': 'assignment', 'children': ['361', '364']},{'id': '361', 'type': 'subscript', 'children': ['362', '363']},{'id': '362', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '363', 'type': 'string', 'children': [], 'value': "'latest'"},{'id': '364', 'type': 'False', 'children': []},{'id': '365', 'type': 'expression_statement', 'children': ['366']},{'id': '366', 'type': 'call', 'children': ['367', '368']},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'sleep'},{'id': '368', 'type': 'argument_list', 'children': ['369']},{'id': '369', 'type': 'integer', 'children': [], 'value': '30'},{'id': '370', 'type': 'expression_statement', 'children': ['371']},{'id': '371', 'type': 'assignment', 'children': ['372', '373']},{'id': '372', 'type': 'identifier', 'children': [], 'value': 'geturl'},{'id': '373', 'type': 'call', 'children': ['374', '375']},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'iriToUri'},{'id': '375', 'type': 'argument_list', 'children': ['376']},{'id': '376', 'type': 'binary_operator', 'children': ['377', '384'], 'value': '+'},{'id': '377', 'type': 'call', 'children': ['378', '379']},{'id': '378', 'type': 'identifier', 'children': [], 'value': 'getmambuurl'},{'id': '379', 'type': 'argument_list', 'children': ['380', '382']},{'id': '380', 'type': 'list_splat', 'children': ['381']},{'id': '381', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '382', 'type': 'dictionary_splat', 'children': ['383']},{'id': '383', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '384', 'type': 'string', 'children': [], 'value': '"database/backup/LATEST"'},{'id': '385', 'type': 'if_statement', 'children': ['386', '387']},{'id': '386', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '387', 'type': 'block', 'children': ['388', '399']},{'id': '388', 'type': 'expression_statement', 'children': ['389']},{'id': '389', 'type': 'call', 'children': ['390', '393']},{'id': '390', 'type': 'attribute', 'children': ['391', '392']},{'id': '391', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '393', 'type': 'argument_list', 'children': ['394']},{'id': '394', 'type': 'binary_operator', 'children': ['395', '398'], 'value': '+'},{'id': '395', 'type': 'binary_operator', 'children': ['396', '397'], 'value': '+'},{'id': '396', 'type': 'string', 'children': [], 'value': '"open url: "'},{'id': '397', 'type': 'identifier', 'children': [], 'value': 'geturl'},{'id': '398', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '399', 'type': 'expression_statement', 'children': ['400']},{'id': '400', 'type': 'call', 'children': ['401', '404']},{'id': '401', 'type': 'attribute', 'children': ['402', '403']},{'id': '402', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '403', 'type': 'identifier', 'children': [], 'value': 'flush'},{'id': '404', 'type': 'argument_list', 'children': []},{'id': '405', 'type': 'expression_statement', 'children': ['406']},{'id': '406', 'type': 'assignment', 'children': ['407', '408']},{'id': '407', 'type': 'identifier', 'children': [], 'value': 'resp'},{'id': '408', 'type': 'call', 'children': ['409', '412']},{'id': '409', 'type': 'attribute', 'children': ['410', '411']},{'id': '410', 'type': 'identifier', 'children': [], 'value': 'requests'},{'id': '411', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '412', 'type': 'argument_list', 'children': ['413', '414']},{'id': '413', 'type': 'identifier', 'children': [], 'value': 'geturl'},{'id': '414', 'type': 'keyword_argument', 'children': ['415', '416']},{'id': '415', 'type': 'identifier', 'children': [], 'value': 'auth'},{'id': '416', 'type': 'tuple', 'children': ['417', '418']},{'id': '417', 'type': 'identifier', 'children': [], 'value': 'apiuser'},{'id': '418', 'type': 'identifier', 'children': [], 'value': 'apipwd'},{'id': '419', 'type': 'if_statement', 'children': ['420', '425']},{'id': '420', 'type': 'comparison_operator', 'children': ['421', '424'], 'value': '!='},{'id': '421', 'type': 'attribute', 'children': ['422', '423']},{'id': '422', 'type': 'identifier', 'children': [], 'value': 'resp'},{'id': '423', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '424', 'type': 'integer', 'children': [], 'value': '200'},{'id': '425', 'type': 'block', 'children': ['426', '434', '452']},{'id': '426', 'type': 'expression_statement', 'children': ['427']},{'id': '427', 'type': 'assignment', 'children': ['428', '429']},{'id': '428', 'type': 'identifier', 'children': [], 'value': 'mess'},{'id': '429', 'type': 'binary_operator', 'children': ['430', '431'], 'value': '%'},{'id': '430', 'type': 'string', 'children': [], 'value': '"Error getting database backup: %s"'},{'id': '431', 'type': 'attribute', 'children': ['432', '433']},{'id': '432', 'type': 'identifier', 'children': [], 'value': 'resp'},{'id': '433', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '434', 'type': 'if_statement', 'children': ['435', '436']},{'id': '435', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '436', 'type': 'block', 'children': ['437', '446']},{'id': '437', 'type': 'expression_statement', 'children': ['438']},{'id': '438', 'type': 'call', 'children': ['439', '442']},{'id': '439', 'type': 'attribute', 'children': ['440', '441']},{'id': '440', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '441', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '442', 'type': 'argument_list', 'children': ['443']},{'id': '443', 'type': 'binary_operator', 'children': ['444', '445'], 'value': '+'},{'id': '444', 'type': 'identifier', 'children': [], 'value': 'mess'},{'id': '445', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '446', 'type': 'expression_statement', 'children': ['447']},{'id': '447', 'type': 'call', 'children': ['448', '451']},{'id': '448', 'type': 'attribute', 'children': ['449', '450']},{'id': '449', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '450', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '451', 'type': 'argument_list', 'children': []},{'id': '452', 'type': 'raise_statement', 'children': ['453']},{'id': '453', 'type': 'call', 'children': ['454', '455']},{'id': '454', 'type': 'identifier', 'children': [], 'value': 'MambuCommError'},{'id': '455', 'type': 'argument_list', 'children': ['456']},{'id': '456', 'type': 'identifier', 'children': [], 'value': 'mess'},{'id': '457', 'type': 'if_statement', 'children': ['458', '459']},{'id': '458', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '459', 'type': 'block', 'children': ['460', '467']},{'id': '460', 'type': 'expression_statement', 'children': ['461']},{'id': '461', 'type': 'call', 'children': ['462', '465']},{'id': '462', 'type': 'attribute', 'children': ['463', '464']},{'id': '463', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '464', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '465', 'type': 'argument_list', 'children': ['466']},{'id': '466', 'type': 'string', 'children': [], 'value': '"saving...\\n"'},{'id': '467', 'type': 'expression_statement', 'children': ['468']},{'id': '468', 'type': 'call', 'children': ['469', '472']},{'id': '469', 'type': 'attribute', 'children': ['470', '471']},{'id': '470', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '471', 'type': 'identifier', 'children': [], 'value': 'flush'},{'id': '472', 'type': 'argument_list', 'children': []},{'id': '473', 'type': 'with_statement', 'children': ['474', '484']},{'id': '474', 'type': 'with_clause', 'children': ['475']},{'id': '475', 'type': 'with_item', 'children': ['476']},{'id': '476', 'type': 'as_pattern', 'children': ['477', '482']},{'id': '477', 'type': 'call', 'children': ['478', '479']},{'id': '478', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '479', 'type': 'argument_list', 'children': ['480', '481']},{'id': '480', 'type': 'identifier', 'children': [], 'value': 'output_fname'},{'id': '481', 'type': 'string', 'children': [], 'value': '"w"'},{'id': '482', 'type': 'as_pattern_target', 'children': ['483']},{'id': '483', 'type': 'identifier', 'children': [], 'value': 'fw'},{'id': '484', 'type': 'block', 'children': ['485']},{'id': '485', 'type': 'expression_statement', 'children': ['486']},{'id': '486', 'type': 'call', 'children': ['487', '490']},{'id': '487', 'type': 'attribute', 'children': ['488', '489']},{'id': '488', 'type': 'identifier', 'children': [], 'value': 'fw'},{'id': '489', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '490', 'type': 'argument_list', 'children': ['491']},{'id': '491', 'type': 'attribute', 'children': ['492', '493']},{'id': '492', 'type': 'identifier', 'children': [], 'value': 'resp'},{'id': '493', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '494', 'type': 'if_statement', 'children': ['495', '496']},{'id': '495', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '496', 'type': 'block', 'children': ['497', '504']},{'id': '497', 'type': 'expression_statement', 'children': ['498']},{'id': '498', 'type': 'call', 'children': ['499', '502']},{'id': '499', 'type': 'attribute', 'children': ['500', '501']},{'id': '500', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '501', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '502', 'type': 'argument_list', 'children': ['503']},{'id': '503', 'type': 'string', 'children': [], 'value': '"DONE!\\n"'},{'id': '504', 'type': 'expression_statement', 'children': ['505']},{'id': '505', 'type': 'call', 'children': ['506', '509']},{'id': '506', 'type': 'attribute', 'children': ['507', '508']},{'id': '507', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '508', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '509', 'type': 'argument_list', 'children': []},{'id': '510', 'type': 'return_statement', 'children': ['511']},{'id': '511', 'type': 'identifier', 'children': [], 'value': 'data'}
def backup_db(callback, bool_func, output_fname, *args, **kwargs): 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
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'send'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'typed_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'stack'},{'id': '7', 'type': 'type', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'Layers'},{'id': '9', 'type': 'block', 'children': ['10', '25', '96', '135', '188', '224']},{'id': '10', 'type': 'if_statement', 'children': ['11', '17']},{'id': '11', 'type': 'not_operator', 'children': ['12']},{'id': '12', 'type': 'call', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '14', 'type': 'argument_list', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'stack'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'Stack'},{'id': '17', 'type': 'block', 'children': ['18']},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'stack'},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'Stack'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'stack'},{'id': '25', 'type': 'if_statement', 'children': ['26', '38']},{'id': '26', 'type': 'boolean_operator', 'children': ['27', '32'], 'value': 'and'},{'id': '27', 'type': 'comparison_operator', 'children': ['28', '29'], 'value': 'in'},{'id': '28', 'type': 'string', 'children': [], 'value': "'callback_query'"},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '31', 'type': 'identifier', 'children': [], 'value': '_update'},{'id': '32', 'type': 'call', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'stack'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'has_layer'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'Update'},{'id': '38', 'type': 'block', 'children': ['39', '48']},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '42', 'type': 'call', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'stack'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'get_layer'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'Update'},{'id': '48', 'type': 'try_statement', 'children': ['49', '60', '76']},{'id': '49', 'type': 'block', 'children': ['50']},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '53', 'type': 'subscript', 'children': ['54', '59']},{'id': '54', 'type': 'subscript', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '57', 'type': 'identifier', 'children': [], 'value': '_update'},{'id': '58', 'type': 'string', 'children': [], 'value': "'callback_query'"},{'id': '59', 'type': 'string', 'children': [], 'value': "'message'"},{'id': '60', 'type': 'except_clause', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '62', 'type': 'block', 'children': ['63']},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '68', '69']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'inline_message_id'},{'id': '68', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '69', 'type': 'subscript', 'children': ['70', '75']},{'id': '70', 'type': 'subscript', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '73', 'type': 'identifier', 'children': [], 'value': '_update'},{'id': '74', 'type': 'string', 'children': [], 'value': "'callback_query'"},{'id': '75', 'type': 'string', 'children': [], 'value': "'inline_message_id'"},{'id': '76', 'type': 'else_clause', 'children': ['77']},{'id': '77', 'type': 'block', 'children': ['78', '88']},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'chat_id'},{'id': '83', 'type': 'subscript', 'children': ['84', '87']},{'id': '84', 'type': 'subscript', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '86', 'type': 'string', 'children': [], 'value': "'chat'"},{'id': '87', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'assignment', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'message_id'},{'id': '93', 'type': 'subscript', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '95', 'type': 'string', 'children': [], 'value': "'message_id'"},{'id': '96', 'type': 'if_statement', 'children': ['97', '103']},{'id': '97', 'type': 'call', 'children': ['98', '101']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'stack'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'has_layer'},{'id': '101', 'type': 'argument_list', 'children': ['102']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'AnswerCallbackQuery'},{'id': '103', 'type': 'block', 'children': ['104', '115']},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'assignment', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '108', 'type': 'identifier', 'children': [], 'value': '_acq'},{'id': '109', 'type': 'call', 'children': ['110', '113']},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'stack'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'get_layer'},{'id': '113', 'type': 'argument_list', 'children': ['114']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'AnswerCallbackQuery'},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'assignment', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'stack'},{'id': '118', 'type': 'call', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'Stack'},{'id': '120', 'type': 'argument_list', 'children': ['121']},{'id': '121', 'type': 'list_comprehension', 'children': ['122', '123', '128']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '123', 'type': 'for_in_clause', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'stack'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'layers'},{'id': '128', 'type': 'if_clause', 'children': ['129']},{'id': '129', 'type': 'not_operator', 'children': ['130']},{'id': '130', 'type': 'call', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '132', 'type': 'argument_list', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'AnswerCallbackQuery'},{'id': '135', 'type': 'if_statement', 'children': ['136', '142']},{'id': '136', 'type': 'call', 'children': ['137', '140']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'stack'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'has_layer'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'Reply'},{'id': '142', 'type': 'block', 'children': ['143', '152']},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'assignment', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '146', 'type': 'call', 'children': ['147', '150']},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'stack'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'get_layer'},{'id': '150', 'type': 'argument_list', 'children': ['151']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'Reply'},{'id': '152', 'type': 'if_statement', 'children': ['153', '158', '169']},{'id': '153', 'type': 'comparison_operator', 'children': ['154', '155'], 'value': 'in'},{'id': '154', 'type': 'string', 'children': [], 'value': "'message'"},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '157', 'type': 'identifier', 'children': [], 'value': '_update'},{'id': '158', 'type': 'block', 'children': ['159']},{'id': '159', 'type': 'expression_statement', 'children': ['160']},{'id': '160', 'type': 'assignment', 'children': ['161', '164']},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '164', 'type': 'subscript', 'children': ['165', '168']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '167', 'type': 'identifier', 'children': [], 'value': '_update'},{'id': '168', 'type': 'string', 'children': [], 'value': "'message'"},{'id': '169', 'type': 'elif_clause', 'children': ['170', '175']},{'id': '170', 'type': 'comparison_operator', 'children': ['171', '172'], 'value': 'in'},{'id': '171', 'type': 'string', 'children': [], 'value': "'callback_query'"},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '174', 'type': 'identifier', 'children': [], 'value': '_update'},{'id': '175', 'type': 'block', 'children': ['176']},{'id': '176', 'type': 'expression_statement', 'children': ['177']},{'id': '177', 'type': 'assignment', 'children': ['178', '181']},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '181', 'type': 'subscript', 'children': ['182', '187']},{'id': '182', 'type': 'subscript', 'children': ['183', '186']},{'id': '183', 'type': 'attribute', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '185', 'type': 'identifier', 'children': [], 'value': '_update'},{'id': '186', 'type': 'string', 'children': [], 'value': "'callback_query'"},{'id': '187', 'type': 'string', 'children': [], 'value': "'message'"},{'id': '188', 'type': 'if_statement', 'children': ['189', '202']},{'id': '189', 'type': 'boolean_operator', 'children': ['190', '195', '196'], 'value': 'and'},{'id': '190', 'type': 'comparison_operator', 'children': ['191', '192'], 'value': 'in'},{'id': '191', 'type': 'string', 'children': [], 'value': "'inline_query'"},{'id': '192', 'type': 'attribute', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '194', 'type': 'identifier', 'children': [], 'value': '_update'},{'id': '195', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '196', 'type': 'call', 'children': ['197', '200']},{'id': '197', 'type': 'attribute', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'stack'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'has_layer'},{'id': '200', 'type': 'argument_list', 'children': ['201']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'AnswerInlineQuery'},{'id': '202', 'type': 'block', 'children': ['203', '212']},{'id': '203', 'type': 'expression_statement', 'children': ['204']},{'id': '204', 'type': 'assignment', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '206', 'type': 'call', 'children': ['207', '210']},{'id': '207', 'type': 'attribute', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'stack'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'get_layer'},{'id': '210', 'type': 'argument_list', 'children': ['211']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'AnswerInlineQuery'},{'id': '212', 'type': 'expression_statement', 'children': ['213']},{'id': '213', 'type': 'assignment', 'children': ['214', '217']},{'id': '214', 'type': 'attribute', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'inline_query_id'},{'id': '217', 'type': 'subscript', 'children': ['218', '223']},{'id': '218', 'type': 'subscript', 'children': ['219', '222']},{'id': '219', 'type': 'attribute', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '221', 'type': 'identifier', 'children': [], 'value': '_update'},{'id': '222', 'type': 'string', 'children': [], 'value': "'inline_query'"},{'id': '223', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '224', 'type': 'if_statement', 'children': ['225', '228']},{'id': '225', 'type': 'attribute', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'stack'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'layers'},{'id': '228', 'type': 'block', 'children': ['229']},{'id': '229', 'type': 'return_statement', 'children': ['230']},{'id': '230', 'type': 'call', 'children': ['231', '238']},{'id': '231', 'type': 'attribute', 'children': ['232', '237']},{'id': '232', 'type': 'call', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'super'},{'id': '234', 'type': 'argument_list', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'TelegramResponder'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '238', 'type': 'argument_list', 'children': ['239']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'stack'}
def send(self, stack: Layers): 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)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '22']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_send_text'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '9', '13']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'typed_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '7', 'type': 'type', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'Request'},{'id': '9', 'type': 'typed_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'stack'},{'id': '11', 'type': 'type', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'Stack'},{'id': '13', 'type': 'typed_default_parameter', 'children': ['14', '15', '21']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'parse_mode'},{'id': '15', 'type': 'type', 'children': ['16']},{'id': '16', 'type': 'generic_type', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'Optional'},{'id': '18', 'type': 'type_parameter', 'children': ['19']},{'id': '19', 'type': 'type', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'Text'},{'id': '21', 'type': 'None', 'children': []},{'id': '22', 'type': 'block', 'children': ['23', '27', '37', '77', '100', '113', '124', '132', '164']},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '26', 'type': 'list', 'children': [], 'value': '[]'},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'chat_id'},{'id': '30', 'type': 'call', 'children': ['31', '36']},{'id': '31', 'type': 'attribute', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'get_chat_id'},{'id': '36', 'type': 'argument_list', 'children': []},{'id': '37', 'type': 'for_statement', 'children': ['38', '39', '42']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'stack'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'layers'},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'if_statement', 'children': ['44', '58']},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '46', 'type': 'argument_list', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '48', 'type': 'tuple', 'children': ['49', '52', '55']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'lyr'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'Text'},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'lyr'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'RawText'},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'lyr'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'Markdown'},{'id': '58', 'type': 'block', 'children': ['59', '70']},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'assignment', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '62', 'type': 'await', 'children': ['63']},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'render'},{'id': '65', 'type': 'argument_list', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'call', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '77', 'type': 'for_statement', 'children': ['78', '79', '85']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'part'},{'id': '79', 'type': 'subscript', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '81', 'type': 'slice', 'children': ['82', '83']},{'id': '82', 'type': 'colon', 'children': []},{'id': '83', 'type': 'unary_operator', 'children': ['84'], 'value': '-'},{'id': '84', 'type': 'integer', 'children': [], 'value': '1'},{'id': '85', 'type': 'block', 'children': ['86']},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'await', 'children': ['88']},{'id': '88', 'type': 'call', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'call'},{'id': '92', 'type': 'argument_list', 'children': ['93', '94', '97']},{'id': '93', 'type': 'string', 'children': [], 'value': "'sendMessage'"},{'id': '94', 'type': 'keyword_argument', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'part'},{'id': '97', 'type': 'keyword_argument', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'chat_id'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'chat_id'},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '103', 'type': 'dictionary', 'children': ['104', '110']},{'id': '104', 'type': 'pair', 'children': ['105', '106']},{'id': '105', 'type': 'string', 'children': [], 'value': "'text'"},{'id': '106', 'type': 'subscript', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '108', 'type': 'unary_operator', 'children': ['109'], 'value': '-'},{'id': '109', 'type': 'integer', 'children': [], 'value': '1'},{'id': '110', 'type': 'pair', 'children': ['111', '112']},{'id': '111', 'type': 'string', 'children': [], 'value': "'chat_id'"},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'chat_id'},{'id': '113', 'type': 'if_statement', 'children': ['114', '117']},{'id': '114', 'type': 'comparison_operator', 'children': ['115', '116'], 'value': 'is'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'parse_mode'},{'id': '116', 'type': 'None', 'children': []},{'id': '117', 'type': 'block', 'children': ['118']},{'id': '118', 'type': 'expression_statement', 'children': ['119']},{'id': '119', 'type': 'assignment', 'children': ['120', '123']},{'id': '120', 'type': 'subscript', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '122', 'type': 'string', 'children': [], 'value': "'parse_mode'"},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'parse_mode'},{'id': '124', 'type': 'expression_statement', 'children': ['125']},{'id': '125', 'type': 'await', 'children': ['126']},{'id': '126', 'type': 'call', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'set_reply_markup'},{'id': '128', 'type': 'argument_list', 'children': ['129', '130', '131']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'stack'},{'id': '132', 'type': 'if_statement', 'children': ['133', '139']},{'id': '133', 'type': 'call', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'stack'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'has_layer'},{'id': '137', 'type': 'argument_list', 'children': ['138']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'Reply'},{'id': '139', 'type': 'block', 'children': ['140', '149']},{'id': '140', 'type': 'expression_statement', 'children': ['141']},{'id': '141', 'type': 'assignment', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'reply'},{'id': '143', 'type': 'call', 'children': ['144', '147']},{'id': '144', 'type': 'attribute', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'stack'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'get_layer'},{'id': '147', 'type': 'argument_list', 'children': ['148']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'Reply'},{'id': '149', 'type': 'if_statement', 'children': ['150', '153']},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'reply'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '153', 'type': 'block', 'children': ['154']},{'id': '154', 'type': 'expression_statement', 'children': ['155']},{'id': '155', 'type': 'assignment', 'children': ['156', '159']},{'id': '156', 'type': 'subscript', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '158', 'type': 'string', 'children': [], 'value': "'reply_to_message_id'"},{'id': '159', 'type': 'subscript', 'children': ['160', '163']},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'reply'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '163', 'type': 'string', 'children': [], 'value': "'message_id'"},{'id': '164', 'type': 'if_statement', 'children': ['165', '171', '220']},{'id': '165', 'type': 'call', 'children': ['166', '169']},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'stack'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'has_layer'},{'id': '169', 'type': 'argument_list', 'children': ['170']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'Update'},{'id': '171', 'type': 'block', 'children': ['172', '181', '208']},{'id': '172', 'type': 'expression_statement', 'children': ['173']},{'id': '173', 'type': 'assignment', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '175', 'type': 'call', 'children': ['176', '179']},{'id': '176', 'type': 'attribute', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'stack'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'get_layer'},{'id': '179', 'type': 'argument_list', 'children': ['180']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'Update'},{'id': '181', 'type': 'if_statement', 'children': ['182', '185', '198']},{'id': '182', 'type': 'attribute', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'inline_message_id'},{'id': '185', 'type': 'block', 'children': ['186', '194']},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'assignment', 'children': ['188', '191']},{'id': '188', 'type': 'subscript', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '190', 'type': 'string', 'children': [], 'value': "'inline_message_id'"},{'id': '191', 'type': 'attribute', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'inline_message_id'},{'id': '194', 'type': 'delete_statement', 'children': ['195']},{'id': '195', 'type': 'subscript', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '197', 'type': 'string', 'children': [], 'value': "'chat_id'"},{'id': '198', 'type': 'else_clause', 'children': ['199']},{'id': '199', 'type': 'block', 'children': ['200']},{'id': '200', 'type': 'expression_statement', 'children': ['201']},{'id': '201', 'type': 'assignment', 'children': ['202', '205']},{'id': '202', 'type': 'subscript', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '204', 'type': 'string', 'children': [], 'value': "'message_id'"},{'id': '205', 'type': 'attribute', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'message_id'},{'id': '208', 'type': 'expression_statement', 'children': ['209']},{'id': '209', 'type': 'await', 'children': ['210']},{'id': '210', 'type': 'call', 'children': ['211', '214']},{'id': '211', 'type': 'attribute', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'call'},{'id': '214', 'type': 'argument_list', 'children': ['215', '216', '218']},{'id': '215', 'type': 'string', 'children': [], 'value': "'editMessageText'"},{'id': '216', 'type': 'set', 'children': ['217']},{'id': '217', 'type': 'string', 'children': [], 'value': "'Bad Request: message is not modified'"},{'id': '218', 'type': 'dictionary_splat', 'children': ['219']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '220', 'type': 'else_clause', 'children': ['221']},{'id': '221', 'type': 'block', 'children': ['222']},{'id': '222', 'type': 'expression_statement', 'children': ['223']},{'id': '223', 'type': 'await', 'children': ['224']},{'id': '224', 'type': 'call', 'children': ['225', '228']},{'id': '225', 'type': 'attribute', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'call'},{'id': '228', 'type': 'argument_list', 'children': ['229', '230']},{'id': '229', 'type': 'string', 'children': [], 'value': "'sendMessage'"},{'id': '230', 'type': 'dictionary_splat', 'children': ['231']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'msg'}
async def _send_text(self, request: Request, stack: Stack, parse_mode: Optional[Text] = None): 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)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'setRepayments'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'list_splat_pattern', 'children': ['6']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '7', 'type': 'dictionary_splat_pattern', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '9', 'type': 'block', 'children': ['10', '33', '88', '102', '108']},{'id': '10', 'type': 'function_definition', 'children': ['11', '12', '14']},{'id': '11', 'type': 'function_name', 'children': [], 'value': 'duedate'},{'id': '12', 'type': 'parameters', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'repayment'},{'id': '14', 'type': 'block', 'children': ['15']},{'id': '15', 'type': 'try_statement', 'children': ['16', '21']},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'return_statement', 'children': ['18']},{'id': '18', 'type': 'subscript', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'repayment'},{'id': '20', 'type': 'string', 'children': [], 'value': "'dueDate'"},{'id': '21', 'type': 'except_clause', 'children': ['22', '26']},{'id': '22', 'type': 'as_pattern', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '24', 'type': 'as_pattern_target', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'kerr'},{'id': '26', 'type': 'block', 'children': ['27']},{'id': '27', 'type': 'return_statement', 'children': ['28']},{'id': '28', 'type': 'call', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '32', 'type': 'argument_list', 'children': []},{'id': '33', 'type': 'try_statement', 'children': ['34', '52']},{'id': '34', 'type': 'block', 'children': ['35']},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'reps'},{'id': '38', 'type': 'call', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'mamburepaymentsclass'},{'id': '42', 'type': 'argument_list', 'children': ['43', '48', '50']},{'id': '43', 'type': 'keyword_argument', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'entid'},{'id': '45', 'type': 'subscript', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '47', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '48', 'type': 'list_splat', 'children': ['49']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '50', 'type': 'dictionary_splat', 'children': ['51']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '52', 'type': 'except_clause', 'children': ['53', '57']},{'id': '53', 'type': 'as_pattern', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'AttributeError'},{'id': '55', 'type': 'as_pattern_target', 'children': ['56']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'ae'},{'id': '57', 'type': 'block', 'children': ['58', '65', '71']},{'id': '58', 'type': 'import_from_statement', 'children': ['59', '63']},{'id': '59', 'type': 'relative_import', 'children': ['60', '61']},{'id': '60', 'type': 'import_prefix', 'children': []},{'id': '61', 'type': 'dotted_name', 'children': ['62']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'mamburepayment'},{'id': '63', 'type': 'dotted_name', 'children': ['64']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'MambuRepayments'},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'mamburepaymentsclass'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'MambuRepayments'},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'assignment', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'reps'},{'id': '74', 'type': 'call', 'children': ['75', '78']},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'mamburepaymentsclass'},{'id': '78', 'type': 'argument_list', 'children': ['79', '84', '86']},{'id': '79', 'type': 'keyword_argument', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'entid'},{'id': '81', 'type': 'subscript', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '83', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '84', 'type': 'list_splat', 'children': ['85']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '86', 'type': 'dictionary_splat', 'children': ['87']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'assignment', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'reps'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'attrs'},{'id': '93', 'type': 'call', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '95', 'type': 'argument_list', 'children': ['96', '99']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'reps'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'attrs'},{'id': '99', 'type': 'keyword_argument', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'duedate'},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'assignment', 'children': ['104', '107']},{'id': '104', 'type': 'subscript', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '106', 'type': 'string', 'children': [], 'value': "'repayments'"},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'reps'},{'id': '108', 'type': 'return_statement', 'children': ['109']},{'id': '109', 'type': 'integer', 'children': [], 'value': '1'}
def setRepayments(self, *args, **kwargs): def duedate(repayment): 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
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'setTransactions'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'list_splat_pattern', 'children': ['6']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '7', 'type': 'dictionary_splat_pattern', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '9', 'type': 'block', 'children': ['10', '29', '84', '98', '104']},{'id': '10', 'type': 'function_definition', 'children': ['11', '12', '14']},{'id': '11', 'type': 'function_name', 'children': [], 'value': 'transactionid'},{'id': '12', 'type': 'parameters', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'transaction'},{'id': '14', 'type': 'block', 'children': ['15']},{'id': '15', 'type': 'try_statement', 'children': ['16', '21']},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'return_statement', 'children': ['18']},{'id': '18', 'type': 'subscript', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'transaction'},{'id': '20', 'type': 'string', 'children': [], 'value': "'transactionId'"},{'id': '21', 'type': 'except_clause', 'children': ['22', '26']},{'id': '22', 'type': 'as_pattern', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '24', 'type': 'as_pattern_target', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'kerr'},{'id': '26', 'type': 'block', 'children': ['27']},{'id': '27', 'type': 'return_statement', 'children': ['28']},{'id': '28', 'type': 'None', 'children': []},{'id': '29', 'type': 'try_statement', 'children': ['30', '48']},{'id': '30', 'type': 'block', 'children': ['31']},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'trans'},{'id': '34', 'type': 'call', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'mambutransactionsclass'},{'id': '38', 'type': 'argument_list', 'children': ['39', '44', '46']},{'id': '39', 'type': 'keyword_argument', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'entid'},{'id': '41', 'type': 'subscript', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '43', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '44', 'type': 'list_splat', 'children': ['45']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '46', 'type': 'dictionary_splat', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '48', 'type': 'except_clause', 'children': ['49', '53']},{'id': '49', 'type': 'as_pattern', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'AttributeError'},{'id': '51', 'type': 'as_pattern_target', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'ae'},{'id': '53', 'type': 'block', 'children': ['54', '61', '67']},{'id': '54', 'type': 'import_from_statement', 'children': ['55', '59']},{'id': '55', 'type': 'relative_import', 'children': ['56', '57']},{'id': '56', 'type': 'import_prefix', 'children': []},{'id': '57', 'type': 'dotted_name', 'children': ['58']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'mambutransaction'},{'id': '59', 'type': 'dotted_name', 'children': ['60']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'MambuTransactions'},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'mambutransactionsclass'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'MambuTransactions'},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'trans'},{'id': '70', 'type': 'call', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'mambutransactionsclass'},{'id': '74', 'type': 'argument_list', 'children': ['75', '80', '82']},{'id': '75', 'type': 'keyword_argument', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'entid'},{'id': '77', 'type': 'subscript', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '79', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '80', 'type': 'list_splat', 'children': ['81']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '82', 'type': 'dictionary_splat', 'children': ['83']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'trans'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'attrs'},{'id': '89', 'type': 'call', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '91', 'type': 'argument_list', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'trans'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'attrs'},{'id': '95', 'type': 'keyword_argument', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'transactionid'},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '103']},{'id': '100', 'type': 'subscript', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '102', 'type': 'string', 'children': [], 'value': "'transactions'"},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'trans'},{'id': '104', 'type': 'return_statement', 'children': ['105']},{'id': '105', 'type': 'integer', 'children': [], 'value': '1'}
def setTransactions(self, *args, **kwargs): def transactionid(transaction): 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
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_filter'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'environ'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '7', 'type': 'block', 'children': ['8', '64', '68', '91', '99', '119', '128', '135', '142', '150', '160', '171', '187', '202', '216', '231', '359', '373', '404', '413', '431']},{'id': '8', 'type': 'if_statement', 'children': ['9', '12']},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'queries'},{'id': '12', 'type': 'block', 'children': ['13', '20', '44', '53']},{'id': '13', 'type': 'if_statement', 'children': ['14', '17']},{'id': '14', 'type': 'comparison_operator', 'children': ['15', '16'], 'value': 'not'},{'id': '15', 'type': 'string', 'children': [], 'value': "'QUERY_STRING'"},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'environ'},{'id': '17', 'type': 'block', 'children': ['18']},{'id': '18', 'type': 'return_statement', 'children': ['19']},{'id': '19', 'type': 'False', 'children': []},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'available'},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '25', 'type': 'generator_expression', 'children': ['26', '34']},{'id': '26', 'type': 'subscript', 'children': ['27', '33']},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'qstr'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'partition'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'string', 'children': [], 'value': "'='"},{'id': '33', 'type': 'integer', 'children': [], 'value': '0'},{'id': '34', 'type': 'for_in_clause', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'qstr'},{'id': '36', 'type': 'call', 'children': ['37', '42']},{'id': '37', 'type': 'attribute', 'children': ['38', '41']},{'id': '38', 'type': 'subscript', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'environ'},{'id': '40', 'type': 'string', 'children': [], 'value': "'QUERY_STRING'"},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'string', 'children': [], 'value': "'&'"},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'required'},{'id': '47', 'type': 'call', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'queries'},{'id': '53', 'type': 'if_statement', 'children': ['54', '61']},{'id': '54', 'type': 'not_operator', 'children': ['55']},{'id': '55', 'type': 'call', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'required'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'issubset'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'available'},{'id': '61', 'type': 'block', 'children': ['62']},{'id': '62', 'type': 'return_statement', 'children': ['63']},{'id': '63', 'type': 'False', 'children': []},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'unused'},{'id': '67', 'type': 'dictionary', 'children': []},{'id': '68', 'type': 'for_statement', 'children': ['69', '72', '77']},{'id': '69', 'type': 'pattern_list', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '72', 'type': 'call', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '76', 'type': 'argument_list', 'children': []},{'id': '77', 'type': 'block', 'children': ['78']},{'id': '78', 'type': 'if_statement', 'children': ['79', '84']},{'id': '79', 'type': 'comparison_operator', 'children': ['80', '81'], 'value': 'not'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'use'},{'id': '84', 'type': 'block', 'children': ['85']},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'assignment', 'children': ['87', '90']},{'id': '87', 'type': 'subscript', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'unused'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '91', 'type': 'for_statement', 'children': ['92', '93', '94']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'unused'},{'id': '94', 'type': 'block', 'children': ['95']},{'id': '95', 'type': 'delete_statement', 'children': ['96']},{'id': '96', 'type': 'subscript', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '99', 'type': 'try_statement', 'children': ['100', '114']},{'id': '100', 'type': 'block', 'children': ['101']},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'assignment', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'additional'},{'id': '104', 'type': 'boolean_operator', 'children': ['105', '113'], 'value': 'or'},{'id': '105', 'type': 'call', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '109', 'type': 'argument_list', 'children': ['110', '111', '112']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'environ'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'unused'},{'id': '113', 'type': 'dictionary', 'children': []},{'id': '114', 'type': 'except_clause', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'DeferLimit'},{'id': '116', 'type': 'block', 'children': ['117']},{'id': '117', 'type': 'return_statement', 'children': ['118']},{'id': '118', 'type': 'False', 'children': []},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'assignment', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '122', 'type': 'call', 'children': ['123', '126']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '126', 'type': 'argument_list', 'children': ['127']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '128', 'type': 'expression_statement', 'children': ['129']},{'id': '129', 'type': 'call', 'children': ['130', '133']},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '133', 'type': 'argument_list', 'children': ['134']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'unused'},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'call', 'children': ['137', '140']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'additional'},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'assignment', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '145', 'type': 'call', 'children': ['146', '149']},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '149', 'type': 'argument_list', 'children': []},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'call', 'children': ['152', '157']},{'id': '152', 'type': 'attribute', 'children': ['153', '156']},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'expire'},{'id': '157', 'type': 'argument_list', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '159', 'type': 'integer', 'children': [], 'value': '60'},{'id': '160', 'type': 'expression_statement', 'children': ['161']},{'id': '161', 'type': 'assignment', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'update_uuid'},{'id': '163', 'type': 'call', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '165', 'type': 'argument_list', 'children': ['166']},{'id': '166', 'type': 'call', 'children': ['167', '170']},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'uuid4'},{'id': '170', 'type': 'argument_list', 'children': []},{'id': '171', 'type': 'expression_statement', 'children': ['172']},{'id': '172', 'type': 'assignment', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '174', 'type': 'dictionary', 'children': ['175', '178']},{'id': '175', 'type': 'pair', 'children': ['176', '177']},{'id': '176', 'type': 'string', 'children': [], 'value': "'uuid'"},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'update_uuid'},{'id': '178', 'type': 'pair', 'children': ['179', '180']},{'id': '179', 'type': 'string', 'children': [], 'value': "'update'"},{'id': '180', 'type': 'dictionary', 'children': ['181', '184']},{'id': '181', 'type': 'pair', 'children': ['182', '183']},{'id': '182', 'type': 'string', 'children': [], 'value': "'params'"},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '184', 'type': 'pair', 'children': ['185', '186']},{'id': '185', 'type': 'string', 'children': [], 'value': "'time'"},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '187', 'type': 'expression_statement', 'children': ['188']},{'id': '188', 'type': 'call', 'children': ['189', '194']},{'id': '189', 'type': 'attribute', 'children': ['190', '193']},{'id': '190', 'type': 'attribute', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'rpush'},{'id': '194', 'type': 'argument_list', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '196', 'type': 'call', 'children': ['197', '200']},{'id': '197', 'type': 'attribute', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'msgpack'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'dumps'},{'id': '200', 'type': 'argument_list', 'children': ['201']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '202', 'type': 'expression_statement', 'children': ['203']},{'id': '203', 'type': 'assignment', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'records'},{'id': '205', 'type': 'call', 'children': ['206', '211']},{'id': '206', 'type': 'attribute', 'children': ['207', '210']},{'id': '207', 'type': 'attribute', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'lrange'},{'id': '211', 'type': 'argument_list', 'children': ['212', '213', '214']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '213', 'type': 'integer', 'children': [], 'value': '0'},{'id': '214', 'type': 'unary_operator', 'children': ['215'], 'value': '-'},{'id': '215', 'type': 'integer', 'children': [], 'value': '1'},{'id': '216', 'type': 'expression_statement', 'children': ['217']},{'id': '217', 'type': 'assignment', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'loader'},{'id': '219', 'type': 'call', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'BucketLoader'},{'id': '221', 'type': 'argument_list', 'children': ['222', '225', '228', '229', '230']},{'id': '222', 'type': 'attribute', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'bucket_class'},{'id': '225', 'type': 'attribute', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'records'},{'id': '231', 'type': 'if_statement', 'children': ['232', '235']},{'id': '232', 'type': 'comparison_operator', 'children': ['233', '234'], 'value': 'in'},{'id': '233', 'type': 'string', 'children': [], 'value': "'turnstile.conf'"},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'environ'},{'id': '235', 'type': 'block', 'children': ['236', '244', '264', '284']},{'id': '236', 'type': 'expression_statement', 'children': ['237']},{'id': '237', 'type': 'assignment', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '239', 'type': 'subscript', 'children': ['240', '243']},{'id': '240', 'type': 'subscript', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'environ'},{'id': '242', 'type': 'string', 'children': [], 'value': "'turnstile.conf'"},{'id': '243', 'type': 'string', 'children': [], 'value': "'compactor'"},{'id': '244', 'type': 'try_statement', 'children': ['245', '255']},{'id': '245', 'type': 'block', 'children': ['246']},{'id': '246', 'type': 'expression_statement', 'children': ['247']},{'id': '247', 'type': 'assignment', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'max_updates'},{'id': '249', 'type': 'call', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '251', 'type': 'argument_list', 'children': ['252']},{'id': '252', 'type': 'subscript', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '254', 'type': 'string', 'children': [], 'value': "'max_updates'"},{'id': '255', 'type': 'except_clause', 'children': ['256', '259']},{'id': '256', 'type': 'tuple', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '259', 'type': 'block', 'children': ['260']},{'id': '260', 'type': 'expression_statement', 'children': ['261']},{'id': '261', 'type': 'assignment', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'max_updates'},{'id': '263', 'type': 'None', 'children': []},{'id': '264', 'type': 'try_statement', 'children': ['265', '275']},{'id': '265', 'type': 'block', 'children': ['266']},{'id': '266', 'type': 'expression_statement', 'children': ['267']},{'id': '267', 'type': 'assignment', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'max_age'},{'id': '269', 'type': 'call', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '271', 'type': 'argument_list', 'children': ['272']},{'id': '272', 'type': 'subscript', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '274', 'type': 'string', 'children': [], 'value': "'max_age'"},{'id': '275', 'type': 'except_clause', 'children': ['276', '279']},{'id': '276', 'type': 'tuple', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '279', 'type': 'block', 'children': ['280']},{'id': '280', 'type': 'expression_statement', 'children': ['281']},{'id': '281', 'type': 'assignment', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'max_age'},{'id': '283', 'type': 'integer', 'children': [], 'value': '600'},{'id': '284', 'type': 'if_statement', 'children': ['285', '295']},{'id': '285', 'type': 'boolean_operator', 'children': ['286', '287'], 'value': 'and'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'max_updates'},{'id': '287', 'type': 'call', 'children': ['288', '291']},{'id': '288', 'type': 'attribute', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'loader'},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'need_summary'},{'id': '291', 'type': 'argument_list', 'children': ['292', '293', '294']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'max_updates'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'max_age'},{'id': '295', 'type': 'block', 'children': ['296', '315', '330', '340']},{'id': '296', 'type': 'expression_statement', 'children': ['297']},{'id': '297', 'type': 'assignment', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'summarize'},{'id': '299', 'type': 'call', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '301', 'type': 'argument_list', 'children': ['302', '305']},{'id': '302', 'type': 'keyword_argument', 'children': ['303', '304']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'summarize'},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '305', 'type': 'keyword_argument', 'children': ['306', '307']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '307', 'type': 'call', 'children': ['308', '309']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '309', 'type': 'argument_list', 'children': ['310']},{'id': '310', 'type': 'call', 'children': ['311', '314']},{'id': '311', 'type': 'attribute', 'children': ['312', '313']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'uuid4'},{'id': '314', 'type': 'argument_list', 'children': []},{'id': '315', 'type': 'expression_statement', 'children': ['316']},{'id': '316', 'type': 'call', 'children': ['317', '322']},{'id': '317', 'type': 'attribute', 'children': ['318', '321']},{'id': '318', 'type': 'attribute', 'children': ['319', '320']},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'rpush'},{'id': '322', 'type': 'argument_list', 'children': ['323', '324']},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '324', 'type': 'call', 'children': ['325', '328']},{'id': '325', 'type': 'attribute', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'msgpack'},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'dumps'},{'id': '328', 'type': 'argument_list', 'children': ['329']},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'summarize'},{'id': '330', 'type': 'expression_statement', 'children': ['331']},{'id': '331', 'type': 'assignment', 'children': ['332', '333']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'compactor_key'},{'id': '333', 'type': 'call', 'children': ['334', '337']},{'id': '334', 'type': 'attribute', 'children': ['335', '336']},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '337', 'type': 'argument_list', 'children': ['338', '339']},{'id': '338', 'type': 'string', 'children': [], 'value': "'compactor_key'"},{'id': '339', 'type': 'string', 'children': [], 'value': "'compactor'"},{'id': '340', 'type': 'expression_statement', 'children': ['341']},{'id': '341', 'type': 'call', 'children': ['342', '347']},{'id': '342', 'type': 'attribute', 'children': ['343', '346']},{'id': '343', 'type': 'attribute', 'children': ['344', '345']},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'zadd'},{'id': '347', 'type': 'argument_list', 'children': ['348', '349', '358']},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'compactor_key'},{'id': '349', 'type': 'call', 'children': ['350', '351']},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '351', 'type': 'argument_list', 'children': ['352']},{'id': '352', 'type': 'call', 'children': ['353', '356']},{'id': '353', 'type': 'attribute', 'children': ['354', '355']},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'math'},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'ceil'},{'id': '356', 'type': 'argument_list', 'children': ['357']},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '359', 'type': 'expression_statement', 'children': ['360']},{'id': '360', 'type': 'call', 'children': ['361', '366']},{'id': '361', 'type': 'attribute', 'children': ['362', '365']},{'id': '362', 'type': 'attribute', 'children': ['363', '364']},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '364', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'expireat'},{'id': '366', 'type': 'argument_list', 'children': ['367', '368']},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '368', 'type': 'attribute', 'children': ['369', '372']},{'id': '369', 'type': 'attribute', 'children': ['370', '371']},{'id': '370', 'type': 'identifier', 'children': [], 'value': 'loader'},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'bucket'},{'id': '372', 'type': 'identifier', 'children': [], 'value': 'expire'},{'id': '373', 'type': 'if_statement', 'children': ['374', '379']},{'id': '374', 'type': 'comparison_operator', 'children': ['375', '378'], 'value': 'is'},{'id': '375', 'type': 'attribute', 'children': ['376', '377']},{'id': '376', 'type': 'identifier', 'children': [], 'value': 'loader'},{'id': '377', 'type': 'identifier', 'children': [], 'value': 'delay'},{'id': '378', 'type': 'None', 'children': []},{'id': '379', 'type': 'block', 'children': ['380', '388']},{'id': '380', 'type': 'expression_statement', 'children': ['381']},{'id': '381', 'type': 'call', 'children': ['382', '385']},{'id': '382', 'type': 'attribute', 'children': ['383', '384']},{'id': '383', 'type': 'identifier', 'children': [], 'value': 'environ'},{'id': '384', 'type': 'identifier', 'children': [], 'value': 'setdefault'},{'id': '385', 'type': 'argument_list', 'children': ['386', '387']},{'id': '386', 'type': 'string', 'children': [], 'value': "'turnstile.delay'"},{'id': '387', 'type': 'list', 'children': [], 'value': '[]'},{'id': '388', 'type': 'expression_statement', 'children': ['389']},{'id': '389', 'type': 'call', 'children': ['390', '395']},{'id': '390', 'type': 'attribute', 'children': ['391', '394']},{'id': '391', 'type': 'subscript', 'children': ['392', '393']},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'environ'},{'id': '393', 'type': 'string', 'children': [], 'value': "'turnstile.delay'"},{'id': '394', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '395', 'type': 'argument_list', 'children': ['396']},{'id': '396', 'type': 'tuple', 'children': ['397', '400', '401']},{'id': '397', 'type': 'attribute', 'children': ['398', '399']},{'id': '398', 'type': 'identifier', 'children': [], 'value': 'loader'},{'id': '399', 'type': 'identifier', 'children': [], 'value': 'delay'},{'id': '400', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '401', 'type': 'attribute', 'children': ['402', '403']},{'id': '402', 'type': 'identifier', 'children': [], 'value': 'loader'},{'id': '403', 'type': 'identifier', 'children': [], 'value': 'bucket'},{'id': '404', 'type': 'expression_statement', 'children': ['405']},{'id': '405', 'type': 'assignment', 'children': ['406', '407']},{'id': '406', 'type': 'identifier', 'children': [], 'value': 'set_name'},{'id': '407', 'type': 'call', 'children': ['408', '411']},{'id': '408', 'type': 'attribute', 'children': ['409', '410']},{'id': '409', 'type': 'identifier', 'children': [], 'value': 'environ'},{'id': '410', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '411', 'type': 'argument_list', 'children': ['412']},{'id': '412', 'type': 'string', 'children': [], 'value': "'turnstile.bucket_set'"},{'id': '413', 'type': 'if_statement', 'children': ['414', '415']},{'id': '414', 'type': 'identifier', 'children': [], 'value': 'set_name'},{'id': '415', 'type': 'block', 'children': ['416']},{'id': '416', 'type': 'expression_statement', 'children': ['417']},{'id': '417', 'type': 'call', 'children': ['418', '423']},{'id': '418', 'type': 'attribute', 'children': ['419', '422']},{'id': '419', 'type': 'attribute', 'children': ['420', '421']},{'id': '420', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '421', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '422', 'type': 'identifier', 'children': [], 'value': 'zadd'},{'id': '423', 'type': 'argument_list', 'children': ['424', '425', '430']},{'id': '424', 'type': 'identifier', 'children': [], 'value': 'set_name'},{'id': '425', 'type': 'attribute', 'children': ['426', '429']},{'id': '426', 'type': 'attribute', 'children': ['427', '428']},{'id': '427', 'type': 'identifier', 'children': [], 'value': 'loader'},{'id': '428', 'type': 'identifier', 'children': [], 'value': 'bucket'},{'id': '429', 'type': 'identifier', 'children': [], 'value': 'expire'},{'id': '430', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '431', 'type': 'return_statement', 'children': ['432']},{'id': '432', 'type': 'not_operator', 'children': ['433']},{'id': '433', 'type': 'attribute', 'children': ['434', '435']},{'id': '434', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '435', 'type': 'identifier', 'children': [], 'value': 'continue_scan'}
def _filter(self, environ, params): if self.queries: if 'QUERY_STRING' not in environ: return False available = set(qstr.partition('=')[0] for qstr in environ['QUERY_STRING'].split('&')) required = set(self.queries) if not required.issubset(available): return False unused = {} for key, value in params.items(): if key not in self.use: unused[key] = value for key in unused: del params[key] try: additional = self.filter(environ, params, unused) or {} except DeferLimit: return False key = self.key(params) params.update(unused) params.update(additional) now = time.time() self.db.expire(key, 60) update_uuid = str(uuid.uuid4()) update = { 'uuid': update_uuid, 'update': { 'params': params, 'time': now, }, } self.db.rpush(key, msgpack.dumps(update)) records = self.db.lrange(key, 0, -1) loader = BucketLoader(self.bucket_class, self.db, self, key, records) 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): summarize = dict(summarize=now, uuid=str(uuid.uuid4())) self.db.rpush(key, msgpack.dumps(summarize)) compactor_key = config.get('compactor_key', 'compactor') self.db.zadd(compactor_key, int(math.ceil(now)), key) self.db.expireat(key, loader.bucket.expire) if loader.delay is not None: environ.setdefault('turnstile.delay', []) environ['turnstile.delay'].append((loader.delay, self, loader.bucket)) set_name = environ.get('turnstile.bucket_set') if set_name: self.db.zadd(set_name, loader.bucket.expire, key) return not self.continue_scan
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '41']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'show'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26', '29', '32', '35', '38']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '7', 'type': 'string', 'children': [], 'value': "'dmenu'"},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'bottom'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'fast'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'case_insensitive'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'monitor'},{'id': '22', 'type': 'None', 'children': []},{'id': '23', 'type': 'default_parameter', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'prompt'},{'id': '25', 'type': 'None', 'children': []},{'id': '26', 'type': 'default_parameter', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'font'},{'id': '28', 'type': 'None', 'children': []},{'id': '29', 'type': 'default_parameter', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'background'},{'id': '31', 'type': 'None', 'children': []},{'id': '32', 'type': 'default_parameter', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'foreground'},{'id': '34', 'type': 'None', 'children': []},{'id': '35', 'type': 'default_parameter', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'background_selected'},{'id': '37', 'type': 'None', 'children': []},{'id': '38', 'type': 'default_parameter', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'foreground_selected'},{'id': '40', 'type': 'None', 'children': []},{'id': '41', 'type': 'block', 'children': ['42', '44', '49', '59', '69', '79', '96', '113', '127', '141', '155', '169', '183', '197', '238', '267', '289', '299', '306', '324']},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'string', 'children': [], 'value': '\'\'\'Present a dmenu to the user.\n Args:\n items (Iterable[str]): defines the menu items being presented to the user. items should not contain the newline character.\n command (Optional[str]): defines the path to the dmenu executable. Defaults to \'dmenu\'.\n bottom (Optional[bool]): dmenu appears at the bottom of the screen.\n fast (Optional[bool]): dmenu grabs the keyboard before reading stdin. This is faster, but will lock up X until stdin reaches end-of-file.\n case_insensitive (Optional[bool]): dmenu matches menu items case insensitively.\n lines (Optional[int]): dmenu lists items vertically, with the given number of lines.\n monitor (Optional[int]): dmenu is displayed on the monitor number supplied. Monitor numbers are starting from 0.\n prompt (Optional[str]): defines the prompt to be displayed to the left of the input field.\n font (Optional[str]): defines the font or font set used. eg. "fixed" or "Monospace-12:normal" (an xft font)\n background (Optional[str]): defines the normal background color.\n foreground (Optional[str]): defines the normal foreground color.\n background_selected (Optional[str]): defines the selected background color.\n foreground_selected (Optional[str]): defines the selected foreground color.\n Raises:\n DmenuCommandError\n DmenuUsageError\n Returns:\n The user\'s selected menu item, their own typed item, or None if they hit escape.\n Examples:\n >>> import dmenu\n >>> dmenu.show([\'a\', \'b\', \'c\'])\n \'a\'\n >>> dmenu.show([\'a\', \'b\', \'c\'], prompt=\'pick a letter\')\n \'b\'\n >>> dmenu.show([\'a\', \'b\', \'c\'])\n None\n >>> dmenu.show([\'a\', \'b\', \'c\'])\n \'d\'\n >>> dmenu.show([\'a\', \'b\', \'c\'], command=\'not_a_valid_dmenu\')\n Traceback (most recent call last):\n ...\n 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\'\n >>> dmenu.show([\'a\', \'b\', \'c\'], monitor=2)\n Traceback (most recent call last):\n ...\n dmenu.dmenu.DmenuUsageError: This version of dmenu does not support your usage ([\'dmenu\', \'-m\', \'2\']):\n usage: dmenu [-b] [-f] [-i] [-l lines] [-p prompt] [-fn font]\n [-nb color] [-nf color] [-sb color] [-sf color] [-v]\n Consider configuring show using partial application:\n >>> import functools\n >>> show = functools.partial(dmenu.show, bottom=True)\n >>> show([\'we\', \'show\', \'up\', \'below\'])\n >>> show([\'us\', \'too\'])\n \'\'\''},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '47', 'type': 'list', 'children': ['48'], 'value': '[command]'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '49', 'type': 'if_statement', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'bottom'},{'id': '51', 'type': 'block', 'children': ['52']},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'call', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'string', 'children': [], 'value': "'-b'"},{'id': '59', 'type': 'if_statement', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'fast'},{'id': '61', 'type': 'block', 'children': ['62']},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'call', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'id': '68', 'type': 'string', 'children': [], 'value': "'-f'"},{'id': '69', 'type': 'if_statement', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'case_insensitive'},{'id': '71', 'type': 'block', 'children': ['72']},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'call', 'children': ['74', '77']},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'string', 'children': [], 'value': "'-i'"},{'id': '79', 'type': 'if_statement', 'children': ['80', '83']},{'id': '80', 'type': 'comparison_operator', 'children': ['81', '82'], 'value': 'is'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '82', 'type': 'None', 'children': []},{'id': '83', 'type': 'block', 'children': ['84']},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'call', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'tuple', 'children': ['91', '92']},{'id': '91', 'type': 'string', 'children': [], 'value': "'-l'"},{'id': '92', 'type': 'call', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '96', 'type': 'if_statement', 'children': ['97', '100']},{'id': '97', 'type': 'comparison_operator', 'children': ['98', '99'], 'value': 'is'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'monitor'},{'id': '99', 'type': 'None', 'children': []},{'id': '100', 'type': 'block', 'children': ['101']},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'call', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'tuple', 'children': ['108', '109']},{'id': '108', 'type': 'string', 'children': [], 'value': "'-m'"},{'id': '109', 'type': 'call', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '111', 'type': 'argument_list', 'children': ['112']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'monitor'},{'id': '113', 'type': 'if_statement', 'children': ['114', '117']},{'id': '114', 'type': 'comparison_operator', 'children': ['115', '116'], 'value': 'is'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'prompt'},{'id': '116', 'type': 'None', 'children': []},{'id': '117', 'type': 'block', 'children': ['118']},{'id': '118', 'type': 'expression_statement', 'children': ['119']},{'id': '119', 'type': 'call', 'children': ['120', '123']},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '123', 'type': 'argument_list', 'children': ['124']},{'id': '124', 'type': 'tuple', 'children': ['125', '126']},{'id': '125', 'type': 'string', 'children': [], 'value': "'-p'"},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'prompt'},{'id': '127', 'type': 'if_statement', 'children': ['128', '131']},{'id': '128', 'type': 'comparison_operator', 'children': ['129', '130'], 'value': 'is'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'font'},{'id': '130', 'type': 'None', 'children': []},{'id': '131', 'type': 'block', 'children': ['132']},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'call', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '137', 'type': 'argument_list', 'children': ['138']},{'id': '138', 'type': 'tuple', 'children': ['139', '140']},{'id': '139', 'type': 'string', 'children': [], 'value': "'-fn'"},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'font'},{'id': '141', 'type': 'if_statement', 'children': ['142', '145']},{'id': '142', 'type': 'comparison_operator', 'children': ['143', '144'], 'value': 'is'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'background'},{'id': '144', 'type': 'None', 'children': []},{'id': '145', 'type': 'block', 'children': ['146']},{'id': '146', 'type': 'expression_statement', 'children': ['147']},{'id': '147', 'type': 'call', 'children': ['148', '151']},{'id': '148', 'type': 'attribute', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '151', 'type': 'argument_list', 'children': ['152']},{'id': '152', 'type': 'tuple', 'children': ['153', '154']},{'id': '153', 'type': 'string', 'children': [], 'value': "'-nb'"},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'background'},{'id': '155', 'type': 'if_statement', 'children': ['156', '159']},{'id': '156', 'type': 'comparison_operator', 'children': ['157', '158'], 'value': 'is'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'foreground'},{'id': '158', 'type': 'None', 'children': []},{'id': '159', 'type': 'block', 'children': ['160']},{'id': '160', 'type': 'expression_statement', 'children': ['161']},{'id': '161', 'type': 'call', 'children': ['162', '165']},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '165', 'type': 'argument_list', 'children': ['166']},{'id': '166', 'type': 'tuple', 'children': ['167', '168']},{'id': '167', 'type': 'string', 'children': [], 'value': "'-nf'"},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'foreground'},{'id': '169', 'type': 'if_statement', 'children': ['170', '173']},{'id': '170', 'type': 'comparison_operator', 'children': ['171', '172'], 'value': 'is'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'background_selected'},{'id': '172', 'type': 'None', 'children': []},{'id': '173', 'type': 'block', 'children': ['174']},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'id': '175', 'type': 'call', 'children': ['176', '179']},{'id': '176', 'type': 'attribute', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '179', 'type': 'argument_list', 'children': ['180']},{'id': '180', 'type': 'tuple', 'children': ['181', '182']},{'id': '181', 'type': 'string', 'children': [], 'value': "'-sb'"},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'background_selected'},{'id': '183', 'type': 'if_statement', 'children': ['184', '187']},{'id': '184', 'type': 'comparison_operator', 'children': ['185', '186'], 'value': 'is'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'foreground_selected'},{'id': '186', 'type': 'None', 'children': []},{'id': '187', 'type': 'block', 'children': ['188']},{'id': '188', 'type': 'expression_statement', 'children': ['189']},{'id': '189', 'type': 'call', 'children': ['190', '193']},{'id': '190', 'type': 'attribute', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '193', 'type': 'argument_list', 'children': ['194']},{'id': '194', 'type': 'tuple', 'children': ['195', '196']},{'id': '195', 'type': 'string', 'children': [], 'value': "'-sf'"},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'foreground_selected'},{'id': '197', 'type': 'try_statement', 'children': ['198', '226']},{'id': '198', 'type': 'block', 'children': ['199']},{'id': '199', 'type': 'expression_statement', 'children': ['200']},{'id': '200', 'type': 'assignment', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'proc'},{'id': '202', 'type': 'call', 'children': ['203', '206']},{'id': '203', 'type': 'attribute', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'subprocess'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'Popen'},{'id': '206', 'type': 'argument_list', 'children': ['207', '208', '211', '216', '221']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '208', 'type': 'keyword_argument', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'universal_newlines'},{'id': '210', 'type': 'True', 'children': []},{'id': '211', 'type': 'keyword_argument', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'stdin'},{'id': '213', 'type': 'attribute', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'subprocess'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'PIPE'},{'id': '216', 'type': 'keyword_argument', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '218', 'type': 'attribute', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'subprocess'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'PIPE'},{'id': '221', 'type': 'keyword_argument', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '223', 'type': 'attribute', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'subprocess'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'PIPE'},{'id': '226', 'type': 'except_clause', 'children': ['227', '231']},{'id': '227', 'type': 'as_pattern', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'OSError'},{'id': '229', 'type': 'as_pattern_target', 'children': ['230']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '231', 'type': 'block', 'children': ['232']},{'id': '232', 'type': 'raise_statement', 'children': ['233']},{'id': '233', 'type': 'call', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'DmenuCommandError'},{'id': '235', 'type': 'argument_list', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '238', 'type': 'with_statement', 'children': ['239', '244']},{'id': '239', 'type': 'with_clause', 'children': ['240']},{'id': '240', 'type': 'with_item', 'children': ['241']},{'id': '241', 'type': 'attribute', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'proc'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'stdin'},{'id': '244', 'type': 'block', 'children': ['245']},{'id': '245', 'type': 'for_statement', 'children': ['246', '247', '248']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '248', 'type': 'block', 'children': ['249', '258']},{'id': '249', 'type': 'expression_statement', 'children': ['250']},{'id': '250', 'type': 'call', 'children': ['251', '256']},{'id': '251', 'type': 'attribute', 'children': ['252', '255']},{'id': '252', 'type': 'attribute', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'proc'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'stdin'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '256', 'type': 'argument_list', 'children': ['257']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '258', 'type': 'expression_statement', 'children': ['259']},{'id': '259', 'type': 'call', 'children': ['260', '265']},{'id': '260', 'type': 'attribute', 'children': ['261', '264']},{'id': '261', 'type': 'attribute', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'proc'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'stdin'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '265', 'type': 'argument_list', 'children': ['266']},{'id': '266', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '267', 'type': 'if_statement', 'children': ['268', '275']},{'id': '268', 'type': 'comparison_operator', 'children': ['269', '274'], 'value': '=='},{'id': '269', 'type': 'call', 'children': ['270', '273']},{'id': '270', 'type': 'attribute', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'proc'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'wait'},{'id': '273', 'type': 'argument_list', 'children': []},{'id': '274', 'type': 'integer', 'children': [], 'value': '0'},{'id': '275', 'type': 'block', 'children': ['276']},{'id': '276', 'type': 'return_statement', 'children': ['277']},{'id': '277', 'type': 'call', 'children': ['278', '287']},{'id': '278', 'type': 'attribute', 'children': ['279', '286']},{'id': '279', 'type': 'call', 'children': ['280', '285']},{'id': '280', 'type': 'attribute', 'children': ['281', '284']},{'id': '281', 'type': 'attribute', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'proc'},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '285', 'type': 'argument_list', 'children': []},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'rstrip'},{'id': '287', 'type': 'argument_list', 'children': ['288']},{'id': '288', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '289', 'type': 'expression_statement', 'children': ['290']},{'id': '290', 'type': 'assignment', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '292', 'type': 'call', 'children': ['293', '298']},{'id': '293', 'type': 'attribute', 'children': ['294', '297']},{'id': '294', 'type': 'attribute', 'children': ['295', '296']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'proc'},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '298', 'type': 'argument_list', 'children': []},{'id': '299', 'type': 'if_statement', 'children': ['300', '303']},{'id': '300', 'type': 'comparison_operator', 'children': ['301', '302'], 'value': '=='},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '302', 'type': 'string', 'children': [], 'value': "''"},{'id': '303', 'type': 'block', 'children': ['304']},{'id': '304', 'type': 'return_statement', 'children': ['305']},{'id': '305', 'type': 'None', 'children': []},{'id': '306', 'type': 'if_statement', 'children': ['307', '317']},{'id': '307', 'type': 'call', 'children': ['308', '311']},{'id': '308', 'type': 'attribute', 'children': ['309', '310']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '311', 'type': 'argument_list', 'children': ['312', '313', '314']},{'id': '312', 'type': 'string', 'children': [], 'value': "'usage'"},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '314', 'type': 'attribute', 'children': ['315', '316']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'I'},{'id': '317', 'type': 'block', 'children': ['318']},{'id': '318', 'type': 'raise_statement', 'children': ['319']},{'id': '319', 'type': 'call', 'children': ['320', '321']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'DmenuUsageError'},{'id': '321', 'type': 'argument_list', 'children': ['322', '323']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '324', 'type': 'raise_statement', 'children': ['325']},{'id': '325', 'type': 'call', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'DmenuCommandError'},{'id': '327', 'type': 'argument_list', 'children': ['328', '329']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '329', 'type': 'identifier', 'children': [], 'value': '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. 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' >>> dmenu.show(['a', 'b', 'c'], prompt='pick a letter') 'b' >>> dmenu.show(['a', 'b', 'c']) None >>> dmenu.show(['a', 'b', 'c']) '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']) ''' 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: proc = subprocess.Popen( args, universal_newlines=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) except OSError as err: raise DmenuCommandError(args, err) with proc.stdin: for item in items: proc.stdin.write(item) proc.stdin.write('\n') if proc.wait() == 0: return proc.stdout.read().rstrip('\n') stderr = proc.stderr.read() if stderr == '': return None if re.match('usage', stderr, re.I): raise DmenuUsageError(args, stderr) raise DmenuCommandError(args, stderr)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'clean_names'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'ensure_unique_names'},{'id': '7', 'type': 'False', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'strip_prefix'},{'id': '10', 'type': 'False', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'make_database_safe'},{'id': '13', 'type': 'False', 'children': []},{'id': '14', 'type': 'block', 'children': ['15', '19', '167']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '18', 'type': 'dictionary', 'children': []},{'id': '19', 'type': 'for_statement', 'children': ['20', '21', '22']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '22', 'type': 'block', 'children': ['23', '75', '150']},{'id': '23', 'type': 'if_statement', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'strip_prefix'},{'id': '25', 'type': 'block', 'children': ['26', '47']},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '31']},{'id': '28', 'type': 'subscript', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '30', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '31', 'type': 'subscript', 'children': ['32', '35']},{'id': '32', 'type': 'subscript', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '34', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '35', 'type': 'slice', 'children': ['36', '46']},{'id': '36', 'type': 'binary_operator', 'children': ['37', '45'], 'value': '+'},{'id': '37', 'type': 'call', 'children': ['38', '43']},{'id': '38', 'type': 'attribute', 'children': ['39', '42']},{'id': '39', 'type': 'subscript', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '41', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '45', 'type': 'integer', 'children': [], 'value': '1'},{'id': '46', 'type': 'colon', 'children': []},{'id': '47', 'type': 'if_statement', 'children': ['48', '53']},{'id': '48', 'type': 'comparison_operator', 'children': ['49', '52'], 'value': 'is'},{'id': '49', 'type': 'subscript', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '51', 'type': 'string', 'children': [], 'value': "'indexed_by'"},{'id': '52', 'type': 'None', 'children': []},{'id': '53', 'type': 'block', 'children': ['54']},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '59']},{'id': '56', 'type': 'subscript', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '58', 'type': 'string', 'children': [], 'value': "'indexed_by'"},{'id': '59', 'type': 'subscript', 'children': ['60', '63']},{'id': '60', 'type': 'subscript', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '62', 'type': 'string', 'children': [], 'value': "'indexed_by'"},{'id': '63', 'type': 'slice', 'children': ['64', '74']},{'id': '64', 'type': 'binary_operator', 'children': ['65', '73'], 'value': '+'},{'id': '65', 'type': 'call', 'children': ['66', '71']},{'id': '66', 'type': 'attribute', 'children': ['67', '70']},{'id': '67', 'type': 'subscript', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '69', 'type': 'string', 'children': [], 'value': "'indexed_by'"},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '73', 'type': 'integer', 'children': [], 'value': '1'},{'id': '74', 'type': 'colon', 'children': []},{'id': '75', 'type': 'if_statement', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'ensure_unique_names'},{'id': '77', 'type': 'block', 'children': ['78', '82', '108', '130']},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '81', 'type': 'integer', 'children': [], 'value': '1'},{'id': '82', 'type': 'while_statement', 'children': ['83', '103']},{'id': '83', 'type': 'comparison_operator', 'children': ['84', '102'], 'value': 'in'},{'id': '84', 'type': '()', 'children': ['85']},{'id': '85', 'type': 'conditional_expression', 'children': ['86', '89', '92'], 'value': 'if'},{'id': '86', 'type': 'subscript', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '88', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '89', 'type': 'comparison_operator', 'children': ['90', '91'], 'value': '=='},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '91', 'type': 'integer', 'children': [], 'value': '1'},{'id': '92', 'type': 'binary_operator', 'children': ['93', '98'], 'value': '+'},{'id': '93', 'type': 'binary_operator', 'children': ['94', '97'], 'value': '+'},{'id': '94', 'type': 'subscript', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '96', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '97', 'type': 'string', 'children': [], 'value': '"-"'},{'id': '98', 'type': 'call', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '103', 'type': 'block', 'children': ['104']},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'augmented_assignment', 'children': ['106', '107'], 'value': '+='},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '107', 'type': 'integer', 'children': [], 'value': '1'},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'assignment', 'children': ['110', '129']},{'id': '110', 'type': 'subscript', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '112', 'type': 'conditional_expression', 'children': ['113', '116', '119'], 'value': 'if'},{'id': '113', 'type': 'subscript', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '115', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '116', 'type': 'comparison_operator', 'children': ['117', '118'], 'value': '=='},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '118', 'type': 'integer', 'children': [], 'value': '1'},{'id': '119', 'type': 'binary_operator', 'children': ['120', '125'], 'value': '+'},{'id': '120', 'type': 'binary_operator', 'children': ['121', '124'], 'value': '+'},{'id': '121', 'type': 'subscript', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '123', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '124', 'type': 'string', 'children': [], 'value': '"-"'},{'id': '125', 'type': 'call', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '127', 'type': 'argument_list', 'children': ['128']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '129', 'type': 'integer', 'children': [], 'value': '1'},{'id': '130', 'type': 'if_statement', 'children': ['131', '134']},{'id': '131', 'type': 'comparison_operator', 'children': ['132', '133'], 'value': '>'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '133', 'type': 'integer', 'children': [], 'value': '1'},{'id': '134', 'type': 'block', 'children': ['135']},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'assignment', 'children': ['137', '140']},{'id': '137', 'type': 'subscript', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '139', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '140', 'type': 'binary_operator', 'children': ['141', '146'], 'value': '+'},{'id': '141', 'type': 'binary_operator', 'children': ['142', '145'], 'value': '+'},{'id': '142', 'type': 'subscript', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '144', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '145', 'type': 'string', 'children': [], 'value': '"-"'},{'id': '146', 'type': 'call', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '148', 'type': 'argument_list', 'children': ['149']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '150', 'type': 'if_statement', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'make_database_safe'},{'id': '152', 'type': 'block', 'children': ['153']},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'assignment', 'children': ['155', '158']},{'id': '155', 'type': 'subscript', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '157', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '158', 'type': 'call', 'children': ['159', '164']},{'id': '159', 'type': 'attribute', 'children': ['160', '163']},{'id': '160', 'type': 'subscript', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '162', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '164', 'type': 'argument_list', 'children': ['165', '166']},{'id': '165', 'type': 'string', 'children': [], 'value': '"-"'},{'id': '166', 'type': 'string', 'children': [], 'value': '"_"'},{'id': '167', 'type': 'return_statement', 'children': ['168']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'lines'}
def clean_names(lines, ensure_unique_names=False, strip_prefix=False, make_database_safe=False): 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
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'do_help'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '6', 'type': 'block', 'children': ['7']},{'id': '7', 'type': 'if_statement', 'children': ['8', '9', '85']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '9', 'type': 'block', 'children': ['10', '81']},{'id': '10', 'type': 'try_statement', 'children': ['11', '22']},{'id': '11', 'type': 'block', 'children': ['12']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '17', 'type': 'argument_list', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '19', 'type': 'binary_operator', 'children': ['20', '21'], 'value': '+'},{'id': '20', 'type': 'string', 'children': [], 'value': "'help_'"},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '22', 'type': 'except_clause', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'AttributeError'},{'id': '24', 'type': 'block', 'children': ['25', '61', '80']},{'id': '25', 'type': 'try_statement', 'children': ['26', '57']},{'id': '26', 'type': 'block', 'children': ['27', '39']},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'doc'},{'id': '30', 'type': 'attribute', 'children': ['31', '38']},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '33', 'type': 'argument_list', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '35', 'type': 'binary_operator', 'children': ['36', '37'], 'value': '+'},{'id': '36', 'type': 'string', 'children': [], 'value': "'do_'"},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '38', 'type': 'identifier', 'children': [], 'value': '__doc__'},{'id': '39', 'type': 'if_statement', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'doc'},{'id': '41', 'type': 'block', 'children': ['42', '56']},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'call', 'children': ['44', '49']},{'id': '44', 'type': 'attribute', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'binary_operator', 'children': ['51', '52'], 'value': '%'},{'id': '51', 'type': 'string', 'children': [], 'value': '"%s\\n"'},{'id': '52', 'type': 'call', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'doc'},{'id': '56', 'type': 'return_statement', 'children': []},{'id': '57', 'type': 'except_clause', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'AttributeError'},{'id': '59', 'type': 'block', 'children': ['60']},{'id': '60', 'type': 'pass_statement', 'children': []},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'call', 'children': ['63', '68']},{'id': '63', 'type': 'attribute', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'binary_operator', 'children': ['70', '71'], 'value': '%'},{'id': '70', 'type': 'string', 'children': [], 'value': '"%s\\n"'},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'binary_operator', 'children': ['75', '78'], 'value': '%'},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'nohelp'},{'id': '78', 'type': 'tuple', 'children': ['79']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '80', 'type': 'return_statement', 'children': []},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'call', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '84', 'type': 'argument_list', 'children': []},{'id': '85', 'type': 'else_clause', 'children': ['86']},{'id': '86', 'type': 'block', 'children': ['87', '95', '99', '103', '107', '130', '136', '140', '212', '228', '240', '259', '271']},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '90', 'type': 'call', 'children': ['91', '94']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'get_names'},{'id': '94', 'type': 'argument_list', 'children': []},{'id': '95', 'type': 'expression_statement', 'children': ['96']},{'id': '96', 'type': 'assignment', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'cmds_doc'},{'id': '98', 'type': 'list', 'children': [], 'value': '[]'},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'assignment', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'cmds_undoc'},{'id': '102', 'type': 'list', 'children': [], 'value': '[]'},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'help_page'},{'id': '106', 'type': 'dictionary', 'children': []},{'id': '107', 'type': 'for_statement', 'children': ['108', '109', '110']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '110', 'type': 'block', 'children': ['111']},{'id': '111', 'type': 'if_statement', 'children': ['112', '119']},{'id': '112', 'type': 'comparison_operator', 'children': ['113', '118'], 'value': '=='},{'id': '113', 'type': 'subscript', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '115', 'type': 'slice', 'children': ['116', '117']},{'id': '116', 'type': 'colon', 'children': []},{'id': '117', 'type': 'integer', 'children': [], 'value': '5'},{'id': '118', 'type': 'string', 'children': [], 'value': "'help_'"},{'id': '119', 'type': 'block', 'children': ['120']},{'id': '120', 'type': 'expression_statement', 'children': ['121']},{'id': '121', 'type': 'assignment', 'children': ['122', '129']},{'id': '122', 'type': 'subscript', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'help_page'},{'id': '124', 'type': 'subscript', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '126', 'type': 'slice', 'children': ['127', '128']},{'id': '127', 'type': 'integer', 'children': [], 'value': '5'},{'id': '128', 'type': 'colon', 'children': []},{'id': '129', 'type': 'integer', 'children': [], 'value': '1'},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'call', 'children': ['132', '135']},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '135', 'type': 'argument_list', 'children': []},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'assignment', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'prevname'},{'id': '139', 'type': 'string', 'children': [], 'value': "''"},{'id': '140', 'type': 'for_statement', 'children': ['141', '142', '143']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '143', 'type': 'block', 'children': ['144']},{'id': '144', 'type': 'if_statement', 'children': ['145', '152']},{'id': '145', 'type': 'comparison_operator', 'children': ['146', '151'], 'value': '=='},{'id': '146', 'type': 'subscript', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '148', 'type': 'slice', 'children': ['149', '150']},{'id': '149', 'type': 'colon', 'children': []},{'id': '150', 'type': 'integer', 'children': [], 'value': '3'},{'id': '151', 'type': 'string', 'children': [], 'value': "'do_'"},{'id': '152', 'type': 'block', 'children': ['153', '159', '163', '171']},{'id': '153', 'type': 'if_statement', 'children': ['154', '157']},{'id': '154', 'type': 'comparison_operator', 'children': ['155', '156'], 'value': '=='},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'prevname'},{'id': '157', 'type': 'block', 'children': ['158']},{'id': '158', 'type': 'continue_statement', 'children': []},{'id': '159', 'type': 'expression_statement', 'children': ['160']},{'id': '160', 'type': 'assignment', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'prevname'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'assignment', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '166', 'type': 'subscript', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '168', 'type': 'slice', 'children': ['169', '170']},{'id': '169', 'type': 'integer', 'children': [], 'value': '3'},{'id': '170', 'type': 'colon', 'children': []},{'id': '171', 'type': 'if_statement', 'children': ['172', '175', '187', '203']},{'id': '172', 'type': 'comparison_operator', 'children': ['173', '174'], 'value': 'in'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'help_page'},{'id': '175', 'type': 'block', 'children': ['176', '183']},{'id': '176', 'type': 'expression_statement', 'children': ['177']},{'id': '177', 'type': 'call', 'children': ['178', '181']},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'cmds_doc'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '181', 'type': 'argument_list', 'children': ['182']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '183', 'type': 'delete_statement', 'children': ['184']},{'id': '184', 'type': 'subscript', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'help_page'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '187', 'type': 'elif_clause', 'children': ['188', '195']},{'id': '188', 'type': 'attribute', 'children': ['189', '194']},{'id': '189', 'type': 'call', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '191', 'type': 'argument_list', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '194', 'type': 'identifier', 'children': [], 'value': '__doc__'},{'id': '195', 'type': 'block', 'children': ['196']},{'id': '196', 'type': 'expression_statement', 'children': ['197']},{'id': '197', 'type': 'call', 'children': ['198', '201']},{'id': '198', 'type': 'attribute', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'cmds_doc'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '201', 'type': 'argument_list', 'children': ['202']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '203', 'type': 'else_clause', 'children': ['204']},{'id': '204', 'type': 'block', 'children': ['205']},{'id': '205', 'type': 'expression_statement', 'children': ['206']},{'id': '206', 'type': 'call', 'children': ['207', '210']},{'id': '207', 'type': 'attribute', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'cmds_undoc'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '210', 'type': 'argument_list', 'children': ['211']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '212', 'type': 'expression_statement', 'children': ['213']},{'id': '213', 'type': 'call', 'children': ['214', '219']},{'id': '214', 'type': 'attribute', 'children': ['215', '218']},{'id': '215', 'type': 'attribute', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '219', 'type': 'argument_list', 'children': ['220']},{'id': '220', 'type': 'binary_operator', 'children': ['221', '222'], 'value': '%'},{'id': '221', 'type': 'string', 'children': [], 'value': '"%s\\n"'},{'id': '222', 'type': 'call', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '224', 'type': 'argument_list', 'children': ['225']},{'id': '225', 'type': 'attribute', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'doc_leader'},{'id': '228', 'type': 'expression_statement', 'children': ['229']},{'id': '229', 'type': 'call', 'children': ['230', '233']},{'id': '230', 'type': 'attribute', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'print_topics'},{'id': '233', 'type': 'argument_list', 'children': ['234', '237', '238', '239']},{'id': '234', 'type': 'attribute', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'doc_header'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'cmds_doc'},{'id': '238', 'type': 'integer', 'children': [], 'value': '15'},{'id': '239', 'type': 'integer', 'children': [], 'value': '80'},{'id': '240', 'type': 'expression_statement', 'children': ['241']},{'id': '241', 'type': 'call', 'children': ['242', '245']},{'id': '242', 'type': 'attribute', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'print_topics'},{'id': '245', 'type': 'argument_list', 'children': ['246', '249', '257', '258']},{'id': '246', 'type': 'attribute', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'misc_header'},{'id': '249', 'type': 'call', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '251', 'type': 'argument_list', 'children': ['252']},{'id': '252', 'type': 'call', 'children': ['253', '256']},{'id': '253', 'type': 'attribute', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'help_page'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '256', 'type': 'argument_list', 'children': []},{'id': '257', 'type': 'integer', 'children': [], 'value': '15'},{'id': '258', 'type': 'integer', 'children': [], 'value': '80'},{'id': '259', 'type': 'expression_statement', 'children': ['260']},{'id': '260', 'type': 'call', 'children': ['261', '264']},{'id': '261', 'type': 'attribute', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'print_topics'},{'id': '264', 'type': 'argument_list', 'children': ['265', '268', '269', '270']},{'id': '265', 'type': 'attribute', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'undoc_header'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'cmds_undoc'},{'id': '269', 'type': 'integer', 'children': [], 'value': '15'},{'id': '270', 'type': 'integer', 'children': [], 'value': '80'},{'id': '271', 'type': 'for_statement', 'children': ['272', '273', '276']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'topic'},{'id': '273', 'type': 'attribute', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'command_topics'},{'id': '276', 'type': 'block', 'children': ['277', '285']},{'id': '277', 'type': 'expression_statement', 'children': ['278']},{'id': '278', 'type': 'assignment', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'topic_cmds'},{'id': '280', 'type': 'subscript', 'children': ['281', '284']},{'id': '281', 'type': 'attribute', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'command_topics'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'topic'},{'id': '285', 'type': 'expression_statement', 'children': ['286']},{'id': '286', 'type': 'call', 'children': ['287', '290']},{'id': '287', 'type': 'attribute', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'print_topics'},{'id': '290', 'type': 'argument_list', 'children': ['291', '299', '300', '301']},{'id': '291', 'type': 'call', 'children': ['292', '295']},{'id': '292', 'type': 'attribute', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'string'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'capwords'},{'id': '295', 'type': 'argument_list', 'children': ['296']},{'id': '296', 'type': 'binary_operator', 'children': ['297', '298'], 'value': '+'},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'topic'},{'id': '298', 'type': 'string', 'children': [], 'value': '" commands"'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'topic_cmds'},{'id': '300', 'type': 'integer', 'children': [], 'value': '15'},{'id': '301', 'type': 'integer', 'children': [], 'value': '80'}
def do_help(self, arg): if arg: 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() 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)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'make_echoicefield'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '7', '10']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'echoices'},{'id': '5', 'type': 'list_splat_pattern', 'children': ['6']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'klass_name'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'dictionary_splat_pattern', 'children': ['11']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '12', 'type': 'block', 'children': ['13', '19', '27', '80', '112', '142', '151', '163']},{'id': '13', 'type': 'assert_statement', 'children': ['14']},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'issubclass'},{'id': '16', 'type': 'argument_list', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'echoices'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'EChoice'},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'value_type'},{'id': '22', 'type': 'call', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'echoices'},{'id': '25', 'type': 'identifier', 'children': [], 'value': '__getvaluetype__'},{'id': '26', 'type': 'argument_list', 'children': []},{'id': '27', 'type': 'if_statement', 'children': ['28', '31', '38', '49', '60', '71']},{'id': '28', 'type': 'comparison_operator', 'children': ['29', '30'], 'value': 'is'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'value_type'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '31', 'type': 'block', 'children': ['32']},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'cls_'},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'CharField'},{'id': '38', 'type': 'elif_clause', 'children': ['39', '42']},{'id': '39', 'type': 'comparison_operator', 'children': ['40', '41'], 'value': 'is'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'value_type'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'cls_'},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'IntegerField'},{'id': '49', 'type': 'elif_clause', 'children': ['50', '53']},{'id': '50', 'type': 'comparison_operator', 'children': ['51', '52'], 'value': 'is'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'value_type'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '53', 'type': 'block', 'children': ['54']},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'cls_'},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'FloatField'},{'id': '60', 'type': 'elif_clause', 'children': ['61', '64']},{'id': '61', 'type': 'comparison_operator', 'children': ['62', '63'], 'value': 'is'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'value_type'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'bool'},{'id': '64', 'type': 'block', 'children': ['65']},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'cls_'},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'BooleanField'},{'id': '71', 'type': 'else_clause', 'children': ['72']},{'id': '72', 'type': 'block', 'children': ['73']},{'id': '73', 'type': 'raise_statement', 'children': ['74']},{'id': '74', 'type': 'call', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'NotImplementedError'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'concatenated_string', 'children': ['78', '79']},{'id': '78', 'type': 'string', 'children': [], 'value': '"Please open an issue if you wish your value type to be supported: "'},{'id': '79', 'type': 'string', 'children': [], 'value': '"https://github.com/mbourqui/django-echoices/issues/new"'},{'id': '80', 'type': 'if_statement', 'children': ['81', '94']},{'id': '81', 'type': 'boolean_operator', 'children': ['82', '83'], 'value': 'and'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'klass_name'},{'id': '83', 'type': 'comparison_operator', 'children': ['84', '90'], 'value': '<'},{'id': '84', 'type': 'call', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'StrictVersion'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'call', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'django_version'},{'id': '89', 'type': 'argument_list', 'children': []},{'id': '90', 'type': 'call', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'StrictVersion'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'string', 'children': [], 'value': "'1.9.0'"},{'id': '94', 'type': 'block', 'children': ['95']},{'id': '95', 'type': 'expression_statement', 'children': ['96']},{'id': '96', 'type': 'call', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'warnings'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'warn'},{'id': '100', 'type': 'argument_list', 'children': ['101', '111']},{'id': '101', 'type': 'call', 'children': ['102', '107']},{'id': '102', 'type': 'attribute', 'children': ['103', '106']},{'id': '103', 'type': 'concatenated_string', 'children': ['104', '105']},{'id': '104', 'type': 'string', 'children': [], 'value': '"Django < 1.9 throws an \'ImportError\' if the class name is not defined in the module. "'},{'id': '105', 'type': 'string', 'children': [], 'value': '"The provided klass_name will be replaced by {}"'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'EChoiceField'},{'id': '110', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'RuntimeWarning'},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'assignment', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'klass_name'},{'id': '115', 'type': 'conditional_expression', 'children': ['116', '119', '130', '131'], 'value': 'if'},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'EChoiceField'},{'id': '118', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '119', 'type': 'comparison_operator', 'children': ['120', '126'], 'value': '<'},{'id': '120', 'type': 'call', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'StrictVersion'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'call', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'django_version'},{'id': '125', 'type': 'argument_list', 'children': []},{'id': '126', 'type': 'call', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'StrictVersion'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'id': '129', 'type': 'string', 'children': [], 'value': "'1.9.0'"},{'id': '130', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '131', 'type': 'conditional_expression', 'children': ['132', '133', '134'], 'value': 'if'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'klass_name'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'klass_name'},{'id': '134', 'type': 'call', 'children': ['135', '138']},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'string', 'children': [], 'value': '"{}Field"'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'echoices'},{'id': '141', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'assignment', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '145', 'type': 'call', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '147', 'type': 'argument_list', 'children': ['148']},{'id': '148', 'type': 'attribute', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'cls_'},{'id': '150', 'type': 'identifier', 'children': [], 'value': '__dict__'},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'call', 'children': ['153', '156']},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '156', 'type': 'argument_list', 'children': ['157']},{'id': '157', 'type': 'call', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '159', 'type': 'argument_list', 'children': ['160']},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'EChoiceField'},{'id': '162', 'type': 'identifier', 'children': [], 'value': '__dict__'},{'id': '163', 'type': 'return_statement', 'children': ['164']},{'id': '164', 'type': 'call', 'children': ['165', '172']},{'id': '165', 'type': 'call', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '167', 'type': 'argument_list', 'children': ['168', '169', '171']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'klass_name'},{'id': '169', 'type': 'tuple', 'children': ['170']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'cls_'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '172', 'type': 'argument_list', 'children': ['173', '174', '176']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'echoices'},{'id': '174', 'type': 'list_splat', 'children': ['175']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '176', 'type': 'dictionary_splat', 'children': ['177']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'kwargs'}
def make_echoicefield(echoices, *args, klass_name=None, **kwargs): 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)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '30']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'make_dummy'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '17', '20', '23', '26', '28']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'relations'},{'id': '7', 'type': 'dictionary', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'datetime_default'},{'id': '10', 'type': 'call', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'dt'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'strptime'},{'id': '14', 'type': 'argument_list', 'children': ['15', '16']},{'id': '15', 'type': 'string', 'children': [], 'value': "'1901-01-01'"},{'id': '16', 'type': 'string', 'children': [], 'value': "'%Y-%m-%d'"},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'varchar_default'},{'id': '19', 'type': 'string', 'children': [], 'value': '""'},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'integer_default'},{'id': '22', 'type': 'integer', 'children': [], 'value': '0'},{'id': '23', 'type': 'default_parameter', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'numeric_default'},{'id': '25', 'type': 'float', 'children': [], 'value': '0.0'},{'id': '26', 'type': 'list_splat_pattern', 'children': ['27']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '28', 'type': 'dictionary_splat_pattern', 'children': ['29']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '30', 'type': 'block', 'children': ['31', '50', '57', '99', '118']},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'init_data'},{'id': '34', 'type': 'dictionary', 'children': ['35', '38', '41', '44', '47']},{'id': '35', 'type': 'pair', 'children': ['36', '37']},{'id': '36', 'type': 'string', 'children': [], 'value': "'DATETIME'"},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'datetime_default'},{'id': '38', 'type': 'pair', 'children': ['39', '40']},{'id': '39', 'type': 'string', 'children': [], 'value': "'VARCHAR'"},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'varchar_default'},{'id': '41', 'type': 'pair', 'children': ['42', '43']},{'id': '42', 'type': 'string', 'children': [], 'value': "'INTEGER'"},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'integer_default'},{'id': '44', 'type': 'pair', 'children': ['45', '46']},{'id': '45', 'type': 'string', 'children': [], 'value': "'NUMERIC(50, 10)'"},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'numeric_default'},{'id': '47', 'type': 'pair', 'children': ['48', '49']},{'id': '48', 'type': 'string', 'children': [], 'value': "'TEXT'"},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'varchar_default'},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '53', 'type': 'call', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '57', 'type': 'for_statement', 'children': ['58', '59', '64']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '59', 'type': 'attribute', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '62', 'type': 'identifier', 'children': [], 'value': '__table__'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '64', 'type': 'block', 'children': ['65']},{'id': '65', 'type': 'try_statement', 'children': ['66', '80']},{'id': '66', 'type': 'block', 'children': ['67']},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'call', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'setattr'},{'id': '70', 'type': 'argument_list', 'children': ['71', '72', '75']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '75', 'type': 'subscript', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '80', 'type': 'except_clause', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '82', 'type': 'block', 'children': ['83']},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'call', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'setattr'},{'id': '86', 'type': 'argument_list', 'children': ['87', '88', '91']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '91', 'type': 'subscript', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'init_data'},{'id': '93', 'type': 'call', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '99', 'type': 'for_statement', 'children': ['100', '103', '108']},{'id': '100', 'type': 'pattern_list', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '103', 'type': 'call', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'relations'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '107', 'type': 'argument_list', 'children': []},{'id': '108', 'type': 'block', 'children': ['109']},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'call', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'setattr'},{'id': '112', 'type': 'argument_list', 'children': ['113', '114', '115']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '115', 'type': 'subscript', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '117', 'type': 'integer', 'children': [], 'value': '0'},{'id': '118', 'type': 'return_statement', 'children': ['119']},{'id': '119', 'type': 'identifier', 'children': [], 'value': '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 ): init_data = { 'DATETIME' : datetime_default, 'VARCHAR' : varchar_default, 'INTEGER' : integer_default, 'NUMERIC(50, 10)' : numeric_default, 'TEXT' : varchar_default, } table = type(instance) for col in table.__table__.columns: 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(): setattr(instance, k, v[0]) return instance
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'read_headers'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'rfile'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'hdict'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '18', '155']},{'id': '9', 'type': 'if_statement', 'children': ['10', '13']},{'id': '10', 'type': 'comparison_operator', 'children': ['11', '12'], 'value': 'is'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'hdict'},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'block', 'children': ['14']},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'hdict'},{'id': '17', 'type': 'dictionary', 'children': []},{'id': '18', 'type': 'while_statement', 'children': ['19', '20']},{'id': '19', 'type': 'True', 'children': []},{'id': '20', 'type': 'block', 'children': ['21', '29', '38', '44', '58', '121', '149']},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '24', 'type': 'call', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'rfile'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'readline'},{'id': '28', 'type': 'argument_list', 'children': []},{'id': '29', 'type': 'if_statement', 'children': ['30', '32']},{'id': '30', 'type': 'not_operator', 'children': ['31']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '32', 'type': 'block', 'children': ['33']},{'id': '33', 'type': 'raise_statement', 'children': ['34']},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'string', 'children': [], 'value': '"Illegal end of headers."'},{'id': '38', 'type': 'if_statement', 'children': ['39', '42']},{'id': '39', 'type': 'comparison_operator', 'children': ['40', '41'], 'value': '=='},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'CRLF'},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'break_statement', 'children': []},{'id': '44', 'type': 'if_statement', 'children': ['45', '52']},{'id': '45', 'type': 'not_operator', 'children': ['46']},{'id': '46', 'type': 'call', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'endswith'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'CRLF'},{'id': '52', 'type': 'block', 'children': ['53']},{'id': '53', 'type': 'raise_statement', 'children': ['54']},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'string', 'children': [], 'value': '"HTTP requires CRLF terminators"'},{'id': '58', 'type': 'if_statement', 'children': ['59', '64', '73']},{'id': '59', 'type': 'comparison_operator', 'children': ['60', '63'], 'value': 'in'},{'id': '60', 'type': 'subscript', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '62', 'type': 'integer', 'children': [], 'value': '0'},{'id': '63', 'type': 'string', 'children': [], 'value': "' \\t'"},{'id': '64', 'type': 'block', 'children': ['65']},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '68', 'type': 'call', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '72', 'type': 'argument_list', 'children': []},{'id': '73', 'type': 'else_clause', 'children': ['74']},{'id': '74', 'type': 'block', 'children': ['75', '97', '109', '117']},{'id': '75', 'type': 'try_statement', 'children': ['76', '89']},{'id': '76', 'type': 'block', 'children': ['77']},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '82']},{'id': '79', 'type': 'pattern_list', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '82', 'type': 'call', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '86', 'type': 'argument_list', 'children': ['87', '88']},{'id': '87', 'type': 'string', 'children': [], 'value': '":"'},{'id': '88', 'type': 'integer', 'children': [], 'value': '1'},{'id': '89', 'type': 'except_clause', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '91', 'type': 'block', 'children': ['92']},{'id': '92', 'type': 'raise_statement', 'children': ['93']},{'id': '93', 'type': 'call', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'string', 'children': [], 'value': '"Illegal header line."'},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '100', 'type': 'call', 'children': ['101', '108']},{'id': '101', 'type': 'attribute', 'children': ['102', '107']},{'id': '102', 'type': 'call', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '106', 'type': 'argument_list', 'children': []},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '108', 'type': 'argument_list', 'children': []},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '112', 'type': 'call', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '116', 'type': 'argument_list', 'children': []},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'hname'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '121', 'type': 'if_statement', 'children': ['122', '125']},{'id': '122', 'type': 'comparison_operator', 'children': ['123', '124'], 'value': 'in'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'comma_separated_headers'},{'id': '125', 'type': 'block', 'children': ['126', '135']},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'assignment', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'existing'},{'id': '129', 'type': 'call', 'children': ['130', '133']},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'hdict'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '133', 'type': 'argument_list', 'children': ['134']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'hname'},{'id': '135', 'type': 'if_statement', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'existing'},{'id': '137', 'type': 'block', 'children': ['138']},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'assignment', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '141', 'type': 'call', 'children': ['142', '145']},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'string', 'children': [], 'value': '", "'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '145', 'type': 'argument_list', 'children': ['146']},{'id': '146', 'type': 'tuple', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'existing'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'assignment', 'children': ['151', '154']},{'id': '151', 'type': 'subscript', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'hdict'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'hname'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '155', 'type': 'return_statement', 'children': ['156']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'hdict'}
def read_headers(rfile, hdict=None): if hdict is None: hdict = {} while True: line = rfile.readline() if not line: raise ValueError("Illegal end of headers.") if line == CRLF: break if not line.endswith(CRLF): raise ValueError("HTTP requires CRLF terminators") if line[0] in ' \t': v = line.strip() else: try: k, v = line.split(":", 1) except ValueError: raise ValueError("Illegal header line.") 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
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'send_headers'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '22', '35', '105', '152', '190', '210', '230', '247', '268', '275']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'hkeys'},{'id': '9', 'type': 'list_comprehension', 'children': ['10', '15']},{'id': '10', 'type': 'call', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '14', 'type': 'argument_list', 'children': []},{'id': '15', 'type': 'for_in_clause', 'children': ['16', '19']},{'id': '16', 'type': 'pattern_list', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'outheaders'},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'subscript', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '32', 'type': 'slice', 'children': ['33', '34']},{'id': '33', 'type': 'colon', 'children': []},{'id': '34', 'type': 'integer', 'children': [], 'value': '3'},{'id': '35', 'type': 'if_statement', 'children': ['36', '39', '46']},{'id': '36', 'type': 'comparison_operator', 'children': ['37', '38'], 'value': '=='},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '38', 'type': 'integer', 'children': [], 'value': '413'},{'id': '39', 'type': 'block', 'children': ['40']},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'close_connection'},{'id': '45', 'type': 'True', 'children': []},{'id': '46', 'type': 'elif_clause', 'children': ['47', '50']},{'id': '47', 'type': 'comparison_operator', 'children': ['48', '49'], 'value': 'not'},{'id': '48', 'type': 'string', 'children': [], 'value': '"content-length"'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'hkeys'},{'id': '50', 'type': 'block', 'children': ['51']},{'id': '51', 'type': 'if_statement', 'children': ['52', '62', '64']},{'id': '52', 'type': 'boolean_operator', 'children': ['53', '56'], 'value': 'or'},{'id': '53', 'type': 'comparison_operator', 'children': ['54', '55'], 'value': '<'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '55', 'type': 'integer', 'children': [], 'value': '200'},{'id': '56', 'type': 'comparison_operator', 'children': ['57', '58'], 'value': 'in'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '58', 'type': 'tuple', 'children': ['59', '60', '61']},{'id': '59', 'type': 'integer', 'children': [], 'value': '204'},{'id': '60', 'type': 'integer', 'children': [], 'value': '205'},{'id': '61', 'type': 'integer', 'children': [], 'value': '304'},{'id': '62', 'type': 'block', 'children': ['63']},{'id': '63', 'type': 'pass_statement', 'children': []},{'id': '64', 'type': 'else_clause', 'children': ['65']},{'id': '65', 'type': 'block', 'children': ['66']},{'id': '66', 'type': 'if_statement', 'children': ['67', '79', '97']},{'id': '67', 'type': '()', 'children': ['68']},{'id': '68', 'type': 'boolean_operator', 'children': ['69', '74'], 'value': 'and'},{'id': '69', 'type': 'comparison_operator', 'children': ['70', '73'], 'value': '=='},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'response_protocol'},{'id': '73', 'type': 'string', 'children': [], 'value': "'HTTP/1.1'"},{'id': '74', 'type': 'comparison_operator', 'children': ['75', '78'], 'value': '!='},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '78', 'type': 'string', 'children': [], 'value': "'HEAD'"},{'id': '79', 'type': 'block', 'children': ['80', '86']},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'chunked_write'},{'id': '85', 'type': 'True', 'children': []},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'call', 'children': ['88', '93']},{'id': '88', 'type': 'attribute', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'outheaders'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'tuple', 'children': ['95', '96']},{'id': '95', 'type': 'string', 'children': [], 'value': '"Transfer-Encoding"'},{'id': '96', 'type': 'string', 'children': [], 'value': '"chunked"'},{'id': '97', 'type': 'else_clause', 'children': ['98']},{'id': '98', 'type': 'block', 'children': ['99']},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'assignment', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'close_connection'},{'id': '104', 'type': 'True', 'children': []},{'id': '105', 'type': 'if_statement', 'children': ['106', '109']},{'id': '106', 'type': 'comparison_operator', 'children': ['107', '108'], 'value': 'not'},{'id': '107', 'type': 'string', 'children': [], 'value': '"connection"'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'hkeys'},{'id': '109', 'type': 'block', 'children': ['110']},{'id': '110', 'type': 'if_statement', 'children': ['111', '116', '133']},{'id': '111', 'type': 'comparison_operator', 'children': ['112', '115'], 'value': '=='},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'response_protocol'},{'id': '115', 'type': 'string', 'children': [], 'value': "'HTTP/1.1'"},{'id': '116', 'type': 'block', 'children': ['117']},{'id': '117', 'type': 'if_statement', 'children': ['118', '121']},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'close_connection'},{'id': '121', 'type': 'block', 'children': ['122']},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'call', 'children': ['124', '129']},{'id': '124', 'type': 'attribute', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'outheaders'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '129', 'type': 'argument_list', 'children': ['130']},{'id': '130', 'type': 'tuple', 'children': ['131', '132']},{'id': '131', 'type': 'string', 'children': [], 'value': '"Connection"'},{'id': '132', 'type': 'string', 'children': [], 'value': '"close"'},{'id': '133', 'type': 'else_clause', 'children': ['134']},{'id': '134', 'type': 'block', 'children': ['135']},{'id': '135', 'type': 'if_statement', 'children': ['136', '140']},{'id': '136', 'type': 'not_operator', 'children': ['137']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'close_connection'},{'id': '140', 'type': 'block', 'children': ['141']},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'call', 'children': ['143', '148']},{'id': '143', 'type': 'attribute', 'children': ['144', '147']},{'id': '144', 'type': 'attribute', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'outheaders'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '148', 'type': 'argument_list', 'children': ['149']},{'id': '149', 'type': 'tuple', 'children': ['150', '151']},{'id': '150', 'type': 'string', 'children': [], 'value': '"Connection"'},{'id': '151', 'type': 'string', 'children': [], 'value': '"Keep-Alive"'},{'id': '152', 'type': 'if_statement', 'children': ['153', '164']},{'id': '153', 'type': 'boolean_operator', 'children': ['154', '159'], 'value': 'and'},{'id': '154', 'type': '()', 'children': ['155']},{'id': '155', 'type': 'not_operator', 'children': ['156']},{'id': '156', 'type': 'attribute', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'close_connection'},{'id': '159', 'type': '()', 'children': ['160']},{'id': '160', 'type': 'not_operator', 'children': ['161']},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'chunked_read'},{'id': '164', 'type': 'block', 'children': ['165', '176']},{'id': '165', 'type': 'expression_statement', 'children': ['166']},{'id': '166', 'type': 'assignment', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'remaining'},{'id': '168', 'type': 'call', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '170', 'type': 'argument_list', 'children': ['171', '174', '175']},{'id': '171', 'type': 'attribute', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'rfile'},{'id': '174', 'type': 'string', 'children': [], 'value': "'remaining'"},{'id': '175', 'type': 'integer', 'children': [], 'value': '0'},{'id': '176', 'type': 'if_statement', 'children': ['177', '180']},{'id': '177', 'type': 'comparison_operator', 'children': ['178', '179'], 'value': '>'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'remaining'},{'id': '179', 'type': 'integer', 'children': [], 'value': '0'},{'id': '180', 'type': 'block', 'children': ['181']},{'id': '181', 'type': 'expression_statement', 'children': ['182']},{'id': '182', 'type': 'call', 'children': ['183', '188']},{'id': '183', 'type': 'attribute', 'children': ['184', '187']},{'id': '184', 'type': 'attribute', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'rfile'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '188', 'type': 'argument_list', 'children': ['189']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'remaining'},{'id': '190', 'type': 'if_statement', 'children': ['191', '194']},{'id': '191', 'type': 'comparison_operator', 'children': ['192', '193'], 'value': 'not'},{'id': '192', 'type': 'string', 'children': [], 'value': '"date"'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'hkeys'},{'id': '194', 'type': 'block', 'children': ['195']},{'id': '195', 'type': 'expression_statement', 'children': ['196']},{'id': '196', 'type': 'call', 'children': ['197', '202']},{'id': '197', 'type': 'attribute', 'children': ['198', '201']},{'id': '198', 'type': 'attribute', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'outheaders'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '202', 'type': 'argument_list', 'children': ['203']},{'id': '203', 'type': 'tuple', 'children': ['204', '205']},{'id': '204', 'type': 'string', 'children': [], 'value': '"Date"'},{'id': '205', 'type': 'call', 'children': ['206', '209']},{'id': '206', 'type': 'attribute', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'rfc822'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'formatdate'},{'id': '209', 'type': 'argument_list', 'children': []},{'id': '210', 'type': 'if_statement', 'children': ['211', '214']},{'id': '211', 'type': 'comparison_operator', 'children': ['212', '213'], 'value': 'not'},{'id': '212', 'type': 'string', 'children': [], 'value': '"server"'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'hkeys'},{'id': '214', 'type': 'block', 'children': ['215']},{'id': '215', 'type': 'expression_statement', 'children': ['216']},{'id': '216', 'type': 'call', 'children': ['217', '222']},{'id': '217', 'type': 'attribute', 'children': ['218', '221']},{'id': '218', 'type': 'attribute', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'outheaders'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '222', 'type': 'argument_list', 'children': ['223']},{'id': '223', 'type': 'tuple', 'children': ['224', '225']},{'id': '224', 'type': 'string', 'children': [], 'value': '"Server"'},{'id': '225', 'type': 'attribute', 'children': ['226', '229']},{'id': '226', 'type': 'attribute', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'server'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'server_name'},{'id': '230', 'type': 'expression_statement', 'children': ['231']},{'id': '231', 'type': 'assignment', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'buf'},{'id': '233', 'type': 'list', 'children': ['234'], 'value': '[self.server.protocol + " " + self.status + CRLF]'},{'id': '234', 'type': 'binary_operator', 'children': ['235', '246'], 'value': '+'},{'id': '235', 'type': 'binary_operator', 'children': ['236', '243'], 'value': '+'},{'id': '236', 'type': 'binary_operator', 'children': ['237', '242'], 'value': '+'},{'id': '237', 'type': 'attribute', 'children': ['238', '241']},{'id': '238', 'type': 'attribute', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'server'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'protocol'},{'id': '242', 'type': 'string', 'children': [], 'value': '" "'},{'id': '243', 'type': 'attribute', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'CRLF'},{'id': '247', 'type': 'for_statement', 'children': ['248', '251', '254']},{'id': '248', 'type': 'pattern_list', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '251', 'type': 'attribute', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'outheaders'},{'id': '254', 'type': 'block', 'children': ['255']},{'id': '255', 'type': 'expression_statement', 'children': ['256']},{'id': '256', 'type': 'call', 'children': ['257', '260']},{'id': '257', 'type': 'attribute', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'buf'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '260', 'type': 'argument_list', 'children': ['261']},{'id': '261', 'type': 'binary_operator', 'children': ['262', '267'], 'value': '+'},{'id': '262', 'type': 'binary_operator', 'children': ['263', '266'], 'value': '+'},{'id': '263', 'type': 'binary_operator', 'children': ['264', '265'], 'value': '+'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '265', 'type': 'string', 'children': [], 'value': '": "'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'CRLF'},{'id': '268', 'type': 'expression_statement', 'children': ['269']},{'id': '269', 'type': 'call', 'children': ['270', '273']},{'id': '270', 'type': 'attribute', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'buf'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '273', 'type': 'argument_list', 'children': ['274']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'CRLF'},{'id': '275', 'type': 'expression_statement', 'children': ['276']},{'id': '276', 'type': 'call', 'children': ['277', '284']},{'id': '277', 'type': 'attribute', 'children': ['278', '283']},{'id': '278', 'type': 'attribute', 'children': ['279', '282']},{'id': '279', 'type': 'attribute', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'conn'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'wfile'},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'sendall'},{'id': '284', 'type': 'argument_list', 'children': ['285']},{'id': '285', 'type': 'call', 'children': ['286', '289']},{'id': '286', 'type': 'attribute', 'children': ['287', '288']},{'id': '287', 'type': 'string', 'children': [], 'value': '""'},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '289', 'type': 'argument_list', 'children': ['290']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'buf'}
def send_headers(self): hkeys = [key.lower() for key, value in self.outheaders] status = int(self.status[:3]) if status == 413: self.close_connection = True elif "content-length" not in hkeys: if status < 200 or status in (204, 205, 304): pass else: if (self.response_protocol == 'HTTP/1.1' and self.method != 'HEAD'): self.chunked_write = True self.outheaders.append(("Transfer-Encoding", "chunked")) else: self.close_connection = True if "connection" not in hkeys: if self.response_protocol == 'HTTP/1.1': if self.close_connection: self.outheaders.append(("Connection", "close")) else: if not self.close_connection: self.outheaders.append(("Connection", "Keep-Alive")) if (not self.close_connection) and (not self.chunked_read): 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))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'setActivities'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'list_splat_pattern', 'children': ['6']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '7', 'type': 'dictionary_splat_pattern', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '9', 'type': 'block', 'children': ['10', '31', '86', '100', '106']},{'id': '10', 'type': 'function_definition', 'children': ['11', '12', '14']},{'id': '11', 'type': 'function_name', 'children': [], 'value': 'activityDate'},{'id': '12', 'type': 'parameters', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'activity'},{'id': '14', 'type': 'block', 'children': ['15']},{'id': '15', 'type': 'try_statement', 'children': ['16', '23']},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'return_statement', 'children': ['18']},{'id': '18', 'type': 'subscript', 'children': ['19', '22']},{'id': '19', 'type': 'subscript', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'activity'},{'id': '21', 'type': 'string', 'children': [], 'value': "'activity'"},{'id': '22', 'type': 'string', 'children': [], 'value': "'timestamp'"},{'id': '23', 'type': 'except_clause', 'children': ['24', '28']},{'id': '24', 'type': 'as_pattern', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '26', 'type': 'as_pattern_target', 'children': ['27']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'kerr'},{'id': '28', 'type': 'block', 'children': ['29']},{'id': '29', 'type': 'return_statement', 'children': ['30']},{'id': '30', 'type': 'None', 'children': []},{'id': '31', 'type': 'try_statement', 'children': ['32', '50']},{'id': '32', 'type': 'block', 'children': ['33']},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'activities'},{'id': '36', 'type': 'call', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'mambuactivitiesclass'},{'id': '40', 'type': 'argument_list', 'children': ['41', '46', '48']},{'id': '41', 'type': 'keyword_argument', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'groupId'},{'id': '43', 'type': 'subscript', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '45', 'type': 'string', 'children': [], 'value': "'encodedKey'"},{'id': '46', 'type': 'list_splat', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '48', 'type': 'dictionary_splat', 'children': ['49']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '50', 'type': 'except_clause', 'children': ['51', '55']},{'id': '51', 'type': 'as_pattern', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'AttributeError'},{'id': '53', 'type': 'as_pattern_target', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'ae'},{'id': '55', 'type': 'block', 'children': ['56', '63', '69']},{'id': '56', 'type': 'import_from_statement', 'children': ['57', '61']},{'id': '57', 'type': 'relative_import', 'children': ['58', '59']},{'id': '58', 'type': 'import_prefix', 'children': []},{'id': '59', 'type': 'dotted_name', 'children': ['60']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'mambuactivity'},{'id': '61', 'type': 'dotted_name', 'children': ['62']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'MambuActivities'},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'mambuactivitiesclass'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'MambuActivities'},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'activities'},{'id': '72', 'type': 'call', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'mambuactivitiesclass'},{'id': '76', 'type': 'argument_list', 'children': ['77', '82', '84']},{'id': '77', 'type': 'keyword_argument', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'groupId'},{'id': '79', 'type': 'subscript', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '81', 'type': 'string', 'children': [], 'value': "'encodedKey'"},{'id': '82', 'type': 'list_splat', 'children': ['83']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '84', 'type': 'dictionary_splat', 'children': ['85']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'assignment', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'activities'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'attrs'},{'id': '91', 'type': 'call', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '93', 'type': 'argument_list', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'activities'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'attrs'},{'id': '97', 'type': 'keyword_argument', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'activityDate'},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '105']},{'id': '102', 'type': 'subscript', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '104', 'type': 'string', 'children': [], 'value': "'activities'"},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'activities'},{'id': '106', 'type': 'return_statement', 'children': ['107']},{'id': '107', 'type': 'integer', 'children': [], 'value': '1'}
def setActivities(self, *args, **kwargs): def activityDate(activity): 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
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'connect'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'list_splat_pattern', 'children': ['6']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '7', 'type': 'dictionary_splat_pattern', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '9', 'type': 'block', 'children': ['10', '15', '27', '51', '55', '62', '68', '72', '76', '454', '482']},{'id': '10', 'type': 'import_from_statement', 'children': ['11', '13']},{'id': '11', 'type': 'dotted_name', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '13', 'type': 'dotted_name', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'deepcopy'},{'id': '15', 'type': 'if_statement', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '17', 'type': 'block', 'children': ['18']},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '22', 'type': 'identifier', 'children': [], 'value': '__args'},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'deepcopy'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '27', 'type': 'if_statement', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '29', 'type': 'block', 'children': ['30']},{'id': '30', 'type': 'for_statement', 'children': ['31', '34', '39']},{'id': '31', 'type': 'pattern_list', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '34', 'type': 'call', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '38', 'type': 'argument_list', 'children': []},{'id': '39', 'type': 'block', 'children': ['40']},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '47']},{'id': '42', 'type': 'subscript', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '45', 'type': 'identifier', 'children': [], 'value': '__kwargs'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '47', 'type': 'call', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'deepcopy'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'jsresp'},{'id': '54', 'type': 'dictionary', 'children': []},{'id': '55', 'type': 'if_statement', 'children': ['56', '60']},{'id': '56', 'type': 'not_operator', 'children': ['57']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '59', 'type': 'identifier', 'children': [], 'value': '__urlfunc'},{'id': '60', 'type': 'block', 'children': ['61']},{'id': '61', 'type': 'return_statement', 'children': []},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '67', 'type': 'identifier', 'children': [], 'value': '__offset'},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'window'},{'id': '71', 'type': 'True', 'children': []},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'jsresp'},{'id': '75', 'type': 'dictionary', 'children': []},{'id': '76', 'type': 'while_statement', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'window'},{'id': '78', 'type': 'block', 'children': ['79', '103', '107', '418', '424']},{'id': '79', 'type': 'if_statement', 'children': ['80', '90', '95']},{'id': '80', 'type': 'boolean_operator', 'children': ['81', '85'], 'value': 'or'},{'id': '81', 'type': 'not_operator', 'children': ['82']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '84', 'type': 'identifier', 'children': [], 'value': '__limit'},{'id': '85', 'type': 'comparison_operator', 'children': ['86', '89'], 'value': '>'},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '88', 'type': 'identifier', 'children': [], 'value': '__limit'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'OUT_OF_BOUNDS_PAGINATION_LIMIT_VALUE'},{'id': '90', 'type': 'block', 'children': ['91']},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'OUT_OF_BOUNDS_PAGINATION_LIMIT_VALUE'},{'id': '95', 'type': 'else_clause', 'children': ['96']},{'id': '96', 'type': 'block', 'children': ['97']},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '102', 'type': 'identifier', 'children': [], 'value': '__limit'},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'retries'},{'id': '106', 'type': 'integer', 'children': [], 'value': '0'},{'id': '107', 'type': 'while_statement', 'children': ['108', '113', '411']},{'id': '108', 'type': 'comparison_operator', 'children': ['109', '110'], 'value': '<'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'retries'},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'MambuStruct'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'RETRIES'},{'id': '113', 'type': 'block', 'children': ['114']},{'id': '114', 'type': 'try_statement', 'children': ['115', '384', '392', '403']},{'id': '115', 'type': 'block', 'children': ['116', '128', '140', '287', '300', '383']},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'assignment', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '119', 'type': 'call', 'children': ['120', '125']},{'id': '120', 'type': 'attribute', 'children': ['121', '124']},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '123', 'type': 'identifier', 'children': [], 'value': '__kwargs'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '125', 'type': 'argument_list', 'children': ['126', '127']},{'id': '126', 'type': 'string', 'children': [], 'value': "'user'"},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'apiuser'},{'id': '128', 'type': 'expression_statement', 'children': ['129']},{'id': '129', 'type': 'assignment', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'pwd'},{'id': '131', 'type': 'call', 'children': ['132', '137']},{'id': '132', 'type': 'attribute', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '135', 'type': 'identifier', 'children': [], 'value': '__kwargs'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '137', 'type': 'argument_list', 'children': ['138', '139']},{'id': '138', 'type': 'string', 'children': [], 'value': "'pwd'"},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'apipwd'},{'id': '140', 'type': 'if_statement', 'children': ['141', '144', '243']},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '143', 'type': 'identifier', 'children': [], 'value': '__data'},{'id': '144', 'type': 'block', 'children': ['145', '152', '166', '194']},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'assignment', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '148', 'type': 'dictionary', 'children': ['149']},{'id': '149', 'type': 'pair', 'children': ['150', '151']},{'id': '150', 'type': 'string', 'children': [], 'value': "'content-type'"},{'id': '151', 'type': 'string', 'children': [], 'value': "'application/json'"},{'id': '152', 'type': 'expression_statement', 'children': ['153']},{'id': '153', 'type': 'assignment', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '155', 'type': 'call', 'children': ['156', '159']},{'id': '156', 'type': 'attribute', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'dumps'},{'id': '159', 'type': 'argument_list', 'children': ['160']},{'id': '160', 'type': 'call', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'encoded_dict'},{'id': '162', 'type': 'argument_list', 'children': ['163']},{'id': '163', 'type': 'attribute', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '165', 'type': 'identifier', 'children': [], 'value': '__data'},{'id': '166', 'type': 'expression_statement', 'children': ['167']},{'id': '167', 'type': 'assignment', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '169', 'type': 'call', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'iriToUri'},{'id': '171', 'type': 'argument_list', 'children': ['172']},{'id': '172', 'type': 'call', 'children': ['173', '176']},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '175', 'type': 'identifier', 'children': [], 'value': '__urlfunc'},{'id': '176', 'type': 'argument_list', 'children': ['177', '180', '183', '186', '190']},{'id': '177', 'type': 'attribute', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'entid'},{'id': '180', 'type': 'keyword_argument', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '183', 'type': 'keyword_argument', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '186', 'type': 'list_splat', 'children': ['187']},{'id': '187', 'type': 'attribute', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '189', 'type': 'identifier', 'children': [], 'value': '__args'},{'id': '190', 'type': 'dictionary_splat', 'children': ['191']},{'id': '191', 'type': 'attribute', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '193', 'type': 'identifier', 'children': [], 'value': '__kwargs'},{'id': '194', 'type': 'if_statement', 'children': ['195', '200', '221']},{'id': '195', 'type': 'comparison_operator', 'children': ['196', '199'], 'value': '=='},{'id': '196', 'type': 'attribute', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '198', 'type': 'identifier', 'children': [], 'value': '__method'},{'id': '199', 'type': 'string', 'children': [], 'value': '"PATCH"'},{'id': '200', 'type': 'block', 'children': ['201']},{'id': '201', 'type': 'expression_statement', 'children': ['202']},{'id': '202', 'type': 'assignment', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'resp'},{'id': '204', 'type': 'call', 'children': ['205', '208']},{'id': '205', 'type': 'attribute', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'requests'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'patch'},{'id': '208', 'type': 'argument_list', 'children': ['209', '210', '213', '216']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '210', 'type': 'keyword_argument', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '213', 'type': 'keyword_argument', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '216', 'type': 'keyword_argument', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'auth'},{'id': '218', 'type': 'tuple', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'pwd'},{'id': '221', 'type': 'else_clause', 'children': ['222']},{'id': '222', 'type': 'block', 'children': ['223']},{'id': '223', 'type': 'expression_statement', 'children': ['224']},{'id': '224', 'type': 'assignment', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'resp'},{'id': '226', 'type': 'call', 'children': ['227', '230']},{'id': '227', 'type': 'attribute', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'requests'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'post'},{'id': '230', 'type': 'argument_list', 'children': ['231', '232', '235', '238']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '232', 'type': 'keyword_argument', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '235', 'type': 'keyword_argument', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '238', 'type': 'keyword_argument', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'auth'},{'id': '240', 'type': 'tuple', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'pwd'},{'id': '243', 'type': 'else_clause', 'children': ['244']},{'id': '244', 'type': 'block', 'children': ['245', '273']},{'id': '245', 'type': 'expression_statement', 'children': ['246']},{'id': '246', 'type': 'assignment', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '248', 'type': 'call', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'iriToUri'},{'id': '250', 'type': 'argument_list', 'children': ['251']},{'id': '251', 'type': 'call', 'children': ['252', '255']},{'id': '252', 'type': 'attribute', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '254', 'type': 'identifier', 'children': [], 'value': '__urlfunc'},{'id': '255', 'type': 'argument_list', 'children': ['256', '259', '262', '265', '269']},{'id': '256', 'type': 'attribute', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'entid'},{'id': '259', 'type': 'keyword_argument', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '262', 'type': 'keyword_argument', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '265', 'type': 'list_splat', 'children': ['266']},{'id': '266', 'type': 'attribute', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '268', 'type': 'identifier', 'children': [], 'value': '__args'},{'id': '269', 'type': 'dictionary_splat', 'children': ['270']},{'id': '270', 'type': 'attribute', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '272', 'type': 'identifier', 'children': [], 'value': '__kwargs'},{'id': '273', 'type': 'expression_statement', 'children': ['274']},{'id': '274', 'type': 'assignment', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'resp'},{'id': '276', 'type': 'call', 'children': ['277', '280']},{'id': '277', 'type': 'attribute', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'requests'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '280', 'type': 'argument_list', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '282', 'type': 'keyword_argument', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'auth'},{'id': '284', 'type': 'tuple', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'pwd'},{'id': '287', 'type': 'expression_statement', 'children': ['288']},{'id': '288', 'type': 'call', 'children': ['289', '294']},{'id': '289', 'type': 'attribute', 'children': ['290', '293']},{'id': '290', 'type': 'attribute', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'rc'},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '294', 'type': 'argument_list', 'children': ['295']},{'id': '295', 'type': 'call', 'children': ['296', '299']},{'id': '296', 'type': 'attribute', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '299', 'type': 'argument_list', 'children': []},{'id': '300', 'type': 'try_statement', 'children': ['301', '359', '367']},{'id': '301', 'type': 'block', 'children': ['302', '313']},{'id': '302', 'type': 'expression_statement', 'children': ['303']},{'id': '303', 'type': 'assignment', 'children': ['304', '305']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'jsonresp'},{'id': '305', 'type': 'call', 'children': ['306', '309']},{'id': '306', 'type': 'attribute', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'loads'},{'id': '309', 'type': 'argument_list', 'children': ['310']},{'id': '310', 'type': 'attribute', 'children': ['311', '312']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'resp'},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '313', 'type': 'if_statement', 'children': ['314', '320', '349']},{'id': '314', 'type': 'comparison_operator', 'children': ['315', '319'], 'value': '=='},{'id': '315', 'type': 'call', 'children': ['316', '317']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '317', 'type': 'argument_list', 'children': ['318']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'jsonresp'},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '320', 'type': 'block', 'children': ['321', '337']},{'id': '321', 'type': 'try_statement', 'children': ['322', '330']},{'id': '322', 'type': 'block', 'children': ['323']},{'id': '323', 'type': 'expression_statement', 'children': ['324']},{'id': '324', 'type': 'call', 'children': ['325', '328']},{'id': '325', 'type': 'attribute', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'jsresp'},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '328', 'type': 'argument_list', 'children': ['329']},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'jsonresp'},{'id': '330', 'type': 'except_clause', 'children': ['331', '332']},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'AttributeError'},{'id': '332', 'type': 'block', 'children': ['333']},{'id': '333', 'type': 'expression_statement', 'children': ['334']},{'id': '334', 'type': 'assignment', 'children': ['335', '336']},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'jsresp'},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'jsonresp'},{'id': '337', 'type': 'if_statement', 'children': ['338', '344']},{'id': '338', 'type': 'comparison_operator', 'children': ['339', '343'], 'value': '<'},{'id': '339', 'type': 'call', 'children': ['340', '341']},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '341', 'type': 'argument_list', 'children': ['342']},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'jsonresp'},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '344', 'type': 'block', 'children': ['345']},{'id': '345', 'type': 'expression_statement', 'children': ['346']},{'id': '346', 'type': 'assignment', 'children': ['347', '348']},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'window'},{'id': '348', 'type': 'False', 'children': []},{'id': '349', 'type': 'else_clause', 'children': ['350']},{'id': '350', 'type': 'block', 'children': ['351', '355']},{'id': '351', 'type': 'expression_statement', 'children': ['352']},{'id': '352', 'type': 'assignment', 'children': ['353', '354']},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'jsresp'},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'jsonresp'},{'id': '355', 'type': 'expression_statement', 'children': ['356']},{'id': '356', 'type': 'assignment', 'children': ['357', '358']},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'window'},{'id': '358', 'type': 'False', 'children': []},{'id': '359', 'type': 'except_clause', 'children': ['360', '364']},{'id': '360', 'type': 'as_pattern', 'children': ['361', '362']},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '362', 'type': 'as_pattern_target', 'children': ['363']},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'ex'},{'id': '364', 'type': 'block', 'children': ['365']},{'id': '365', 'type': 'raise_statement', 'children': ['366']},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'ex'},{'id': '367', 'type': 'except_clause', 'children': ['368', '372']},{'id': '368', 'type': 'as_pattern', 'children': ['369', '370']},{'id': '369', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '370', 'type': 'as_pattern_target', 'children': ['371']},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'ex'},{'id': '372', 'type': 'block', 'children': ['373']},{'id': '373', 'type': 'raise_statement', 'children': ['374']},{'id': '374', 'type': 'call', 'children': ['375', '376']},{'id': '375', 'type': 'identifier', 'children': [], 'value': 'MambuError'},{'id': '376', 'type': 'argument_list', 'children': ['377']},{'id': '377', 'type': 'binary_operator', 'children': ['378', '379'], 'value': '%'},{'id': '378', 'type': 'string', 'children': [], 'value': '"JSON Error: %s"'},{'id': '379', 'type': 'call', 'children': ['380', '381']},{'id': '380', 'type': 'identifier', 'children': [], 'value': 'repr'},{'id': '381', 'type': 'argument_list', 'children': ['382']},{'id': '382', 'type': 'identifier', 'children': [], 'value': 'ex'},{'id': '383', 'type': 'break_statement', 'children': []},{'id': '384', 'type': 'except_clause', 'children': ['385', '389']},{'id': '385', 'type': 'as_pattern', 'children': ['386', '387']},{'id': '386', 'type': 'identifier', 'children': [], 'value': 'MambuError'},{'id': '387', 'type': 'as_pattern_target', 'children': ['388']},{'id': '388', 'type': 'identifier', 'children': [], 'value': 'merr'},{'id': '389', 'type': 'block', 'children': ['390']},{'id': '390', 'type': 'raise_statement', 'children': ['391']},{'id': '391', 'type': 'identifier', 'children': [], 'value': 'merr'},{'id': '392', 'type': 'except_clause', 'children': ['393', '398']},{'id': '393', 'type': 'attribute', 'children': ['394', '397']},{'id': '394', 'type': 'attribute', 'children': ['395', '396']},{'id': '395', 'type': 'identifier', 'children': [], 'value': 'requests'},{'id': '396', 'type': 'identifier', 'children': [], 'value': 'exceptions'},{'id': '397', 'type': 'identifier', 'children': [], 'value': 'RequestException'},{'id': '398', 'type': 'block', 'children': ['399']},{'id': '399', 'type': 'expression_statement', 'children': ['400']},{'id': '400', 'type': 'augmented_assignment', 'children': ['401', '402'], 'value': '+='},{'id': '401', 'type': 'identifier', 'children': [], 'value': 'retries'},{'id': '402', 'type': 'integer', 'children': [], 'value': '1'},{'id': '403', 'type': 'except_clause', 'children': ['404', '408']},{'id': '404', 'type': 'as_pattern', 'children': ['405', '406']},{'id': '405', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '406', 'type': 'as_pattern_target', 'children': ['407']},{'id': '407', 'type': 'identifier', 'children': [], 'value': 'ex'},{'id': '408', 'type': 'block', 'children': ['409']},{'id': '409', 'type': 'raise_statement', 'children': ['410']},{'id': '410', 'type': 'identifier', 'children': [], 'value': 'ex'},{'id': '411', 'type': 'else_clause', 'children': ['412']},{'id': '412', 'type': 'block', 'children': ['413']},{'id': '413', 'type': 'raise_statement', 'children': ['414']},{'id': '414', 'type': 'call', 'children': ['415', '416']},{'id': '415', 'type': 'identifier', 'children': [], 'value': 'MambuCommError'},{'id': '416', 'type': 'argument_list', 'children': ['417']},{'id': '417', 'type': 'string', 'children': [], 'value': '"ERROR I can\'t communicate with Mambu"'},{'id': '418', 'type': 'expression_statement', 'children': ['419']},{'id': '419', 'type': 'assignment', 'children': ['420', '421']},{'id': '420', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '421', 'type': 'binary_operator', 'children': ['422', '423'], 'value': '+'},{'id': '422', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '423', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '424', 'type': 'if_statement', 'children': ['425', '428']},{'id': '425', 'type': 'attribute', 'children': ['426', '427']},{'id': '426', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '427', 'type': 'identifier', 'children': [], 'value': '__limit'},{'id': '428', 'type': 'block', 'children': ['429', '435']},{'id': '429', 'type': 'expression_statement', 'children': ['430']},{'id': '430', 'type': 'augmented_assignment', 'children': ['431', '434'], 'value': '-='},{'id': '431', 'type': 'attribute', 'children': ['432', '433']},{'id': '432', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '433', 'type': 'identifier', 'children': [], 'value': '__limit'},{'id': '434', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '435', 'type': 'if_statement', 'children': ['436', '441']},{'id': '436', 'type': 'comparison_operator', 'children': ['437', '440'], 'value': '<='},{'id': '437', 'type': 'attribute', 'children': ['438', '439']},{'id': '438', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '439', 'type': 'identifier', 'children': [], 'value': '__limit'},{'id': '440', 'type': 'integer', 'children': [], 'value': '0'},{'id': '441', 'type': 'block', 'children': ['442', '446']},{'id': '442', 'type': 'expression_statement', 'children': ['443']},{'id': '443', 'type': 'assignment', 'children': ['444', '445']},{'id': '444', 'type': 'identifier', 'children': [], 'value': 'window'},{'id': '445', 'type': 'False', 'children': []},{'id': '446', 'type': 'expression_statement', 'children': ['447']},{'id': '447', 'type': 'assignment', 'children': ['448', '451']},{'id': '448', 'type': 'attribute', 'children': ['449', '450']},{'id': '449', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '450', 'type': 'identifier', 'children': [], 'value': '__limit'},{'id': '451', 'type': 'attribute', 'children': ['452', '453']},{'id': '452', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '453', 'type': 'identifier', 'children': [], 'value': '__inilimit'},{'id': '454', 'type': 'try_statement', 'children': ['455', '478']},{'id': '455', 'type': 'block', 'children': ['456']},{'id': '456', 'type': 'if_statement', 'children': ['457', '470']},{'id': '457', 'type': 'boolean_operator', 'children': ['458', '465'], 'value': 'and'},{'id': '458', 'type': 'boolean_operator', 'children': ['459', '462'], 'value': 'and'},{'id': '459', 'type': 'comparison_operator', 'children': ['460', '461'], 'value': 'in'},{'id': '460', 'type': 'string', 'children': [], 'value': "u'returnCode'"},{'id': '461', 'type': 'identifier', 'children': [], 'value': 'jsresp'},{'id': '462', 'type': 'comparison_operator', 'children': ['463', '464'], 'value': 'in'},{'id': '463', 'type': 'string', 'children': [], 'value': "u'returnStatus'"},{'id': '464', 'type': 'identifier', 'children': [], 'value': 'jsresp'},{'id': '465', 'type': 'comparison_operator', 'children': ['466', '469'], 'value': '!='},{'id': '466', 'type': 'subscript', 'children': ['467', '468']},{'id': '467', 'type': 'identifier', 'children': [], 'value': 'jsresp'},{'id': '468', 'type': 'string', 'children': [], 'value': "u'returnCode'"},{'id': '469', 'type': 'integer', 'children': [], 'value': '0'},{'id': '470', 'type': 'block', 'children': ['471']},{'id': '471', 'type': 'raise_statement', 'children': ['472']},{'id': '472', 'type': 'call', 'children': ['473', '474']},{'id': '473', 'type': 'identifier', 'children': [], 'value': 'MambuError'},{'id': '474', 'type': 'argument_list', 'children': ['475']},{'id': '475', 'type': 'subscript', 'children': ['476', '477']},{'id': '476', 'type': 'identifier', 'children': [], 'value': 'jsresp'},{'id': '477', 'type': 'string', 'children': [], 'value': "u'returnStatus'"},{'id': '478', 'type': 'except_clause', 'children': ['479', '480']},{'id': '479', 'type': 'identifier', 'children': [], 'value': 'AttributeError'},{'id': '480', 'type': 'block', 'children': ['481']},{'id': '481', 'type': 'pass_statement', 'children': []},{'id': '482', 'type': 'if_statement', 'children': ['483', '488']},{'id': '483', 'type': 'comparison_operator', 'children': ['484', '487'], 'value': '!='},{'id': '484', 'type': 'attribute', 'children': ['485', '486']},{'id': '485', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '486', 'type': 'identifier', 'children': [], 'value': '__method'},{'id': '487', 'type': 'string', 'children': [], 'value': '"PATCH"'},{'id': '488', 'type': 'block', 'children': ['489']},{'id': '489', 'type': 'expression_statement', 'children': ['490']},{'id': '490', 'type': 'call', 'children': ['491', '494']},{'id': '491', 'type': 'attribute', 'children': ['492', '493']},{'id': '492', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '493', 'type': 'identifier', 'children': [], 'value': 'init'},{'id': '494', 'type': 'argument_list', 'children': ['495', '498', '502']},{'id': '495', 'type': 'keyword_argument', 'children': ['496', '497']},{'id': '496', 'type': 'identifier', 'children': [], 'value': 'attrs'},{'id': '497', 'type': 'identifier', 'children': [], 'value': 'jsresp'},{'id': '498', 'type': 'list_splat', 'children': ['499']},{'id': '499', 'type': 'attribute', 'children': ['500', '501']},{'id': '500', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '501', 'type': 'identifier', 'children': [], 'value': '__args'},{'id': '502', 'type': 'dictionary_splat', 'children': ['503']},{'id': '503', 'type': 'attribute', 'children': ['504', '505']},{'id': '504', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '505', 'type': 'identifier', 'children': [], 'value': '__kwargs'}
def connect(self, *args, **kwargs): 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 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 retries = 0 while retries < MambuStruct.RETRIES: try: 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)) if self.__method=="PATCH": resp = requests.patch(url, data=data, headers=headers, auth=(user, pwd)) else: resp = requests.post(url, data=data, headers=headers, auth=(user, pwd)) else: url = iriToUri(self.__urlfunc(self.entid, limit=limit, offset=offset, *self.__args, **self.__kwargs)) resp = requests.get(url, auth=(user, pwd)) self.rc.add(datetime.now()) try: jsonresp = json.loads(resp.content) if type(jsonresp) == list: try: jsresp.extend(jsonresp) except AttributeError: jsresp=jsonresp if len(jsonresp) < limit: window = False else: jsresp = jsonresp window = False except ValueError as ex: raise ex except Exception as ex: raise MambuError("JSON Error: %s" % repr(ex)) 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") 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)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '37']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'GetDirections'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13', '16', '19', '22', '25', '28', '31', '34']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'origin'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'destination'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'sensor'},{'id': '9', 'type': 'False', 'children': []},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'default_parameter', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'waypoints'},{'id': '15', 'type': 'None', 'children': []},{'id': '16', 'type': 'default_parameter', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'alternatives'},{'id': '18', 'type': 'None', 'children': []},{'id': '19', 'type': 'default_parameter', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'avoid'},{'id': '21', 'type': 'None', 'children': []},{'id': '22', 'type': 'default_parameter', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'language'},{'id': '24', 'type': 'None', 'children': []},{'id': '25', 'type': 'default_parameter', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'units'},{'id': '27', 'type': 'None', 'children': []},{'id': '28', 'type': 'default_parameter', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'region'},{'id': '30', 'type': 'None', 'children': []},{'id': '31', 'type': 'default_parameter', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'departure_time'},{'id': '33', 'type': 'None', 'children': []},{'id': '34', 'type': 'default_parameter', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'arrival_time'},{'id': '36', 'type': 'None', 'children': []},{'id': '37', 'type': 'block', 'children': ['38', '40', '60', '69', '78', '87', '96', '105', '114', '123', '132', '141', '167']},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'string', 'children': [], 'value': "'''Get Directions Service\n Pls refer to the Google Maps Web API for the details of the remained parameters\n '''"},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '43', 'type': 'dictionary', 'children': ['44', '47', '50']},{'id': '44', 'type': 'pair', 'children': ['45', '46']},{'id': '45', 'type': 'string', 'children': [], 'value': "'origin'"},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'origin'},{'id': '47', 'type': 'pair', 'children': ['48', '49']},{'id': '48', 'type': 'string', 'children': [], 'value': "'destination'"},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'destination'},{'id': '50', 'type': 'pair', 'children': ['51', '52']},{'id': '51', 'type': 'string', 'children': [], 'value': "'sensor'"},{'id': '52', 'type': 'call', 'children': ['53', '59']},{'id': '53', 'type': 'attribute', 'children': ['54', '58']},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'sensor'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '59', 'type': 'argument_list', 'children': []},{'id': '60', 'type': 'if_statement', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '62', 'type': 'block', 'children': ['63']},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '68']},{'id': '65', 'type': 'subscript', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '67', 'type': 'string', 'children': [], 'value': "'mode'"},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '69', 'type': 'if_statement', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'waypoints'},{'id': '71', 'type': 'block', 'children': ['72']},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '77']},{'id': '74', 'type': 'subscript', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '76', 'type': 'string', 'children': [], 'value': "'waypoints'"},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'waypoints'},{'id': '78', 'type': 'if_statement', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'alternatives'},{'id': '80', 'type': 'block', 'children': ['81']},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '86']},{'id': '83', 'type': 'subscript', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '85', 'type': 'string', 'children': [], 'value': "'alternatives'"},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'alternatives'},{'id': '87', 'type': 'if_statement', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'avoid'},{'id': '89', 'type': 'block', 'children': ['90']},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '95']},{'id': '92', 'type': 'subscript', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '94', 'type': 'string', 'children': [], 'value': "'avoid'"},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'avoid'},{'id': '96', 'type': 'if_statement', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'language'},{'id': '98', 'type': 'block', 'children': ['99']},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'assignment', 'children': ['101', '104']},{'id': '101', 'type': 'subscript', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '103', 'type': 'string', 'children': [], 'value': "'language'"},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'language'},{'id': '105', 'type': 'if_statement', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'units'},{'id': '107', 'type': 'block', 'children': ['108']},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'assignment', 'children': ['110', '113']},{'id': '110', 'type': 'subscript', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '112', 'type': 'string', 'children': [], 'value': "'units'"},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'units'},{'id': '114', 'type': 'if_statement', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'region'},{'id': '116', 'type': 'block', 'children': ['117']},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '122']},{'id': '119', 'type': 'subscript', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '121', 'type': 'string', 'children': [], 'value': "'region'"},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'region'},{'id': '123', 'type': 'if_statement', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'departure_time'},{'id': '125', 'type': 'block', 'children': ['126']},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'assignment', 'children': ['128', '131']},{'id': '128', 'type': 'subscript', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '130', 'type': 'string', 'children': [], 'value': "'departure_time'"},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'departure_time'},{'id': '132', 'type': 'if_statement', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'arrival_time'},{'id': '134', 'type': 'block', 'children': ['135']},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'assignment', 'children': ['137', '140']},{'id': '137', 'type': 'subscript', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '139', 'type': 'string', 'children': [], 'value': "'arrival_time'"},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'arrival_time'},{'id': '141', 'type': 'if_statement', 'children': ['142', '146', '156']},{'id': '142', 'type': 'not_operator', 'children': ['143']},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'premier'},{'id': '146', 'type': 'block', 'children': ['147']},{'id': '147', 'type': 'expression_statement', 'children': ['148']},{'id': '148', 'type': 'assignment', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '150', 'type': 'call', 'children': ['151', '154']},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'get_url'},{'id': '154', 'type': 'argument_list', 'children': ['155']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '156', 'type': 'else_clause', 'children': ['157']},{'id': '157', 'type': 'block', 'children': ['158']},{'id': '158', 'type': 'expression_statement', 'children': ['159']},{'id': '159', 'type': 'assignment', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '161', 'type': 'call', 'children': ['162', '165']},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'get_signed_url'},{'id': '165', 'type': 'argument_list', 'children': ['166']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '167', 'type': 'return_statement', 'children': ['168']},{'id': '168', 'type': 'call', 'children': ['169', '172']},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'GetService_url'},{'id': '172', 'type': 'argument_list', 'children': ['173']},{'id': '173', 'type': 'identifier', 'children': [], 'value': '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)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'compactor'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '5', 'type': 'block', 'children': ['6', '15', '23', '29', '49', '59', '66']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '9', 'type': 'call', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'get_database'},{'id': '13', 'type': 'argument_list', 'children': ['14']},{'id': '14', 'type': 'string', 'children': [], 'value': "'compactor'"},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'limit_map'},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'LimitContainer'},{'id': '20', 'type': 'argument_list', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '26', 'type': 'subscript', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '28', 'type': 'string', 'children': [], 'value': "'compactor'"},{'id': '29', 'type': 'if_statement', 'children': ['30', '38']},{'id': '30', 'type': 'comparison_operator', 'children': ['31', '37'], 'value': '<='},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'get_int'},{'id': '33', 'type': 'argument_list', 'children': ['34', '35', '36']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '35', 'type': 'string', 'children': [], 'value': "'max_updates'"},{'id': '36', 'type': 'integer', 'children': [], 'value': '0'},{'id': '37', 'type': 'integer', 'children': [], 'value': '0'},{'id': '38', 'type': 'block', 'children': ['39']},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'call', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'LOG'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'concatenated_string', 'children': ['46', '47', '48']},{'id': '46', 'type': 'string', 'children': [], 'value': '"Compaction is not enabled. Enable it by "'},{'id': '47', 'type': 'string', 'children': [], 'value': '"setting a positive integer value for "'},{'id': '48', 'type': 'string', 'children': [], 'value': '"\'compactor.max_updates\' in the configuration."'},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'key_getter'},{'id': '52', 'type': 'call', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'GetBucketKey'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'factory'},{'id': '56', 'type': 'argument_list', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'call', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'LOG'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'string', 'children': [], 'value': '"Compactor initialized"'},{'id': '66', 'type': 'while_statement', 'children': ['67', '68']},{'id': '67', 'type': 'True', 'children': []},{'id': '68', 'type': 'block', 'children': ['69', '100', '108', '133', '142']},{'id': '69', 'type': 'try_statement', 'children': ['70', '84']},{'id': '70', 'type': 'block', 'children': ['71']},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'assignment', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'buck_key'},{'id': '74', 'type': 'call', 'children': ['75', '80']},{'id': '75', 'type': 'attribute', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'limits'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'BucketKey'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'decode'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'call', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'key_getter'},{'id': '83', 'type': 'argument_list', 'children': []},{'id': '84', 'type': 'except_clause', 'children': ['85', '89']},{'id': '85', 'type': 'as_pattern', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '87', 'type': 'as_pattern_target', 'children': ['88']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'exc'},{'id': '89', 'type': 'block', 'children': ['90', '99']},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'call', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'LOG'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'binary_operator', 'children': ['97', '98'], 'value': '%'},{'id': '97', 'type': 'string', 'children': [], 'value': '"Error interpreting bucket key: %s"'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'exc'},{'id': '99', 'type': 'continue_statement', 'children': []},{'id': '100', 'type': 'if_statement', 'children': ['101', '106']},{'id': '101', 'type': 'comparison_operator', 'children': ['102', '105'], 'value': '<'},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'buck_key'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '105', 'type': 'integer', 'children': [], 'value': '2'},{'id': '106', 'type': 'block', 'children': ['107']},{'id': '107', 'type': 'continue_statement', 'children': []},{'id': '108', 'type': 'try_statement', 'children': ['109', '118']},{'id': '109', 'type': 'block', 'children': ['110']},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'assignment', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '113', 'type': 'subscript', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'limit_map'},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'buck_key'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '118', 'type': 'except_clause', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '120', 'type': 'block', 'children': ['121', '132']},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'call', 'children': ['123', '126']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'LOG'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '126', 'type': 'argument_list', 'children': ['127']},{'id': '127', 'type': 'binary_operator', 'children': ['128', '129'], 'value': '%'},{'id': '128', 'type': 'string', 'children': [], 'value': '"Unable to compact bucket for limit %s"'},{'id': '129', 'type': 'attribute', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'buck_key'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '132', 'type': 'continue_statement', 'children': []},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'call', 'children': ['135', '138']},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'LOG'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'binary_operator', 'children': ['140', '141'], 'value': '%'},{'id': '140', 'type': 'string', 'children': [], 'value': '"Compacting bucket %s"'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'buck_key'},{'id': '142', 'type': 'try_statement', 'children': ['143', '151', '163']},{'id': '143', 'type': 'block', 'children': ['144']},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'call', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'compact_bucket'},{'id': '147', 'type': 'argument_list', 'children': ['148', '149', '150']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'buck_key'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '151', 'type': 'except_clause', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '153', 'type': 'block', 'children': ['154']},{'id': '154', 'type': 'expression_statement', 'children': ['155']},{'id': '155', 'type': 'call', 'children': ['156', '159']},{'id': '156', 'type': 'attribute', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'LOG'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'exception'},{'id': '159', 'type': 'argument_list', 'children': ['160']},{'id': '160', 'type': 'binary_operator', 'children': ['161', '162'], 'value': '%'},{'id': '161', 'type': 'string', 'children': [], 'value': '"Failed to compact bucket %s"'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'buck_key'},{'id': '163', 'type': 'else_clause', 'children': ['164']},{'id': '164', 'type': 'block', 'children': ['165']},{'id': '165', 'type': 'expression_statement', 'children': ['166']},{'id': '166', 'type': 'call', 'children': ['167', '170']},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'LOG'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '170', 'type': 'argument_list', 'children': ['171']},{'id': '171', 'type': 'binary_operator', 'children': ['172', '173'], 'value': '%'},{'id': '172', 'type': 'string', 'children': [], 'value': '"Finished compacting bucket %s"'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'buck_key'}
def compactor(conf): db = conf.get_database('compactor') limit_map = LimitContainer(conf, db) config = conf['compactor'] if get_int(config, 'max_updates', 0) <= 0: LOG.warning("Compaction is not enabled. Enable it by " "setting a positive integer value for " "'compactor.max_updates' in the configuration.") key_getter = GetBucketKey.factory(config, db) LOG.info("Compactor initialized") while True: try: buck_key = limits.BucketKey.decode(key_getter()) except ValueError as exc: LOG.warning("Error interpreting bucket key: %s" % exc) continue if buck_key.version < 2: continue try: limit = limit_map[buck_key.uuid] except KeyError: LOG.warning("Unable to compact bucket for limit %s" % buck_key.uuid) continue LOG.debug("Compacting bucket %s" % buck_key) 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)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '6', 'type': 'block', 'children': ['7']},{'id': '7', 'type': 'with_statement', 'children': ['8', '13']},{'id': '8', 'type': 'with_clause', 'children': ['9']},{'id': '9', 'type': 'with_item', 'children': ['10']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'lock'},{'id': '13', 'type': 'block', 'children': ['14', '39', '45', '51', '60']},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '17', 'type': 'call', 'children': ['18', '23']},{'id': '18', 'type': 'attribute', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'zrangebyscore'},{'id': '23', 'type': 'argument_list', 'children': ['24', '27', '28', '33', '36']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '27', 'type': 'integer', 'children': [], 'value': '0'},{'id': '28', 'type': 'binary_operator', 'children': ['29', '30'], 'value': '-'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'min_age'},{'id': '33', 'type': 'keyword_argument', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '35', 'type': 'integer', 'children': [], 'value': '0'},{'id': '36', 'type': 'keyword_argument', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'num'},{'id': '38', 'type': 'integer', 'children': [], 'value': '1'},{'id': '39', 'type': 'if_statement', 'children': ['40', '42']},{'id': '40', 'type': 'not_operator', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'return_statement', 'children': ['44']},{'id': '44', 'type': 'None', 'children': []},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '48', 'type': 'subscript', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '50', 'type': 'integer', 'children': [], 'value': '0'},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'call', 'children': ['53', '58']},{'id': '53', 'type': 'attribute', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'zrem'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '60', 'type': 'return_statement', 'children': ['61']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'item'}
def get(self, now): with self.lock: items = self.db.zrangebyscore(self.key, 0, now - self.min_age, start=0, num=1) if not items: return None item = items[0] self.db.zrem(item) return item
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '6', 'type': 'block', 'children': ['7', '29']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '10', 'type': 'call', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'script'},{'id': '14', 'type': 'argument_list', 'children': ['15', '21']},{'id': '15', 'type': 'keyword_argument', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '17', 'type': 'list', 'children': ['18'], 'value': '[self.key]'},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '21', 'type': 'keyword_argument', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '23', 'type': 'list', 'children': ['24'], 'value': '[now - self.min_age]'},{'id': '24', 'type': 'binary_operator', 'children': ['25', '26'], 'value': '-'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'min_age'},{'id': '29', 'type': 'return_statement', 'children': ['30']},{'id': '30', 'type': 'conditional_expression', 'children': ['31', '34', '35'], 'value': 'if'},{'id': '31', 'type': 'subscript', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '33', 'type': 'integer', 'children': [], 'value': '0'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '35', 'type': 'None', 'children': []}
def get(self, now): items = self.script(keys=[self.key], args=[now - self.min_age]) return items[0] if items else None
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '4']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'main_cli'},{'id': '3', 'type': 'parameters', 'children': []},{'id': '4', 'type': 'block', 'children': ['5', '11', '17', '23', '29', '35', '41', '45', '100']},{'id': '5', 'type': 'expression_statement', 'children': ['6']},{'id': '6', 'type': 'assignment', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '8', 'type': 'call', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': '_cli_argument_parser'},{'id': '10', 'type': 'argument_list', 'children': []},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'delta_secs'},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'delay'},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'i2cbus'},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'bus'},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'i2c_address'},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'address'},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'sensor_key'},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'sensor'},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'sensor_params'},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '44', 'type': 'dictionary', 'children': []},{'id': '45', 'type': 'if_statement', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'sensor_params'},{'id': '47', 'type': 'block', 'children': ['48', '86']},{'id': '48', 'type': 'function_definition', 'children': ['49', '50', '52']},{'id': '49', 'type': 'function_name', 'children': [], 'value': '_parse_param'},{'id': '50', 'type': 'parameters', 'children': ['51']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'str_param'},{'id': '52', 'type': 'block', 'children': ['53', '64', '77']},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '58']},{'id': '55', 'type': 'pattern_list', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '58', 'type': 'call', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'str_param'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'string', 'children': [], 'value': "'='"},{'id': '64', 'type': 'try_statement', 'children': ['65', '73']},{'id': '65', 'type': 'block', 'children': ['66']},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'assignment', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '69', 'type': 'call', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '73', 'type': 'except_clause', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '75', 'type': 'block', 'children': ['76']},{'id': '76', 'type': 'pass_statement', 'children': []},{'id': '77', 'type': 'return_statement', 'children': ['78']},{'id': '78', 'type': 'dictionary', 'children': ['79']},{'id': '79', 'type': 'pair', 'children': ['80', '85']},{'id': '80', 'type': 'call', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '84', 'type': 'argument_list', 'children': []},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'list_comprehension', 'children': ['88', '97']},{'id': '88', 'type': 'call', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'call', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': '_parse_param'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'sp'},{'id': '97', 'type': 'for_in_clause', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'sp'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'sensor_params'},{'id': '100', 'type': 'if_statement', 'children': ['101', '102', '244']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'sensor_key'},{'id': '102', 'type': 'block', 'children': ['103', '108', '143', '171', '191', '201']},{'id': '103', 'type': 'import_from_statement', 'children': ['104', '106']},{'id': '104', 'type': 'dotted_name', 'children': ['105']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '106', 'type': 'dotted_name', 'children': ['107']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'sleep'},{'id': '108', 'type': 'try_statement', 'children': ['109', '122']},{'id': '109', 'type': 'block', 'children': ['110', '113']},{'id': '110', 'type': 'import_statement', 'children': ['111']},{'id': '111', 'type': 'dotted_name', 'children': ['112']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'smbus'},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'assignment', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'bus_handler'},{'id': '116', 'type': 'call', 'children': ['117', '120']},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'smbus'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'SMBus'},{'id': '120', 'type': 'argument_list', 'children': ['121']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'i2cbus'},{'id': '122', 'type': 'except_clause', 'children': ['123', '127']},{'id': '123', 'type': 'as_pattern', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'ImportError'},{'id': '125', 'type': 'as_pattern_target', 'children': ['126']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'exc'},{'id': '127', 'type': 'block', 'children': ['128', '135']},{'id': '128', 'type': 'expression_statement', 'children': ['129']},{'id': '129', 'type': 'call', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '131', 'type': 'argument_list', 'children': ['132', '133', '134']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'exc'},{'id': '133', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '134', 'type': 'string', 'children': [], 'value': '"Please install smbus-cffi before."'},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'call', 'children': ['137', '140']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'exit'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'unary_operator', 'children': ['142'], 'value': '-'},{'id': '142', 'type': 'integer', 'children': [], 'value': '1'},{'id': '143', 'type': 'try_statement', 'children': ['144', '153']},{'id': '144', 'type': 'block', 'children': ['145']},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'assignment', 'children': ['147', '150']},{'id': '147', 'type': 'pattern_list', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'sensor_handler'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'i2c_default_address'},{'id': '150', 'type': 'subscript', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'SENSORS'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'sensor_key'},{'id': '153', 'type': 'except_clause', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '155', 'type': 'block', 'children': ['156', '163']},{'id': '156', 'type': 'expression_statement', 'children': ['157']},{'id': '157', 'type': 'call', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '159', 'type': 'argument_list', 'children': ['160']},{'id': '160', 'type': 'binary_operator', 'children': ['161', '162'], 'value': '%'},{'id': '161', 'type': 'string', 'children': [], 'value': '"\'%s\' is not recognized as an implemented i2c sensor."'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'sensor_key'},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'call', 'children': ['165', '168']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'exit'},{'id': '168', 'type': 'argument_list', 'children': ['169']},{'id': '169', 'type': 'unary_operator', 'children': ['170'], 'value': '-'},{'id': '170', 'type': 'integer', 'children': [], 'value': '1'},{'id': '171', 'type': 'if_statement', 'children': ['172', '173', '185']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'i2c_address'},{'id': '173', 'type': 'block', 'children': ['174']},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'id': '175', 'type': 'assignment', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'i2c_address'},{'id': '177', 'type': 'call', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'hex'},{'id': '179', 'type': 'argument_list', 'children': ['180']},{'id': '180', 'type': 'call', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '182', 'type': 'argument_list', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'i2c_address'},{'id': '184', 'type': 'integer', 'children': [], 'value': '0'},{'id': '185', 'type': 'else_clause', 'children': ['186']},{'id': '186', 'type': 'block', 'children': ['187']},{'id': '187', 'type': 'expression_statement', 'children': ['188']},{'id': '188', 'type': 'assignment', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'i2c_address'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'i2c_default_address'},{'id': '191', 'type': 'expression_statement', 'children': ['192']},{'id': '192', 'type': 'assignment', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'sensor'},{'id': '194', 'type': 'call', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'sensor_handler'},{'id': '196', 'type': 'argument_list', 'children': ['197', '198', '199']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'bus_handler'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'i2c_address'},{'id': '199', 'type': 'dictionary_splat', 'children': ['200']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '201', 'type': 'try_statement', 'children': ['202', '236']},{'id': '202', 'type': 'block', 'children': ['203']},{'id': '203', 'type': 'while_statement', 'children': ['204', '205']},{'id': '204', 'type': 'True', 'children': []},{'id': '205', 'type': 'block', 'children': ['206', '212', '224', '231']},{'id': '206', 'type': 'expression_statement', 'children': ['207']},{'id': '207', 'type': 'call', 'children': ['208', '211']},{'id': '208', 'type': 'attribute', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'sensor'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '211', 'type': 'argument_list', 'children': []},{'id': '212', 'type': 'if_statement', 'children': ['213', '217']},{'id': '213', 'type': 'not_operator', 'children': ['214']},{'id': '214', 'type': 'attribute', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'sensor'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'sample_ok'},{'id': '217', 'type': 'block', 'children': ['218', '223']},{'id': '218', 'type': 'expression_statement', 'children': ['219']},{'id': '219', 'type': 'call', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '221', 'type': 'argument_list', 'children': ['222']},{'id': '222', 'type': 'string', 'children': [], 'value': '"An error has occured."'},{'id': '223', 'type': 'break_statement', 'children': []},{'id': '224', 'type': 'expression_statement', 'children': ['225']},{'id': '225', 'type': 'call', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '227', 'type': 'argument_list', 'children': ['228']},{'id': '228', 'type': 'attribute', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'sensor'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'current_state_str'},{'id': '231', 'type': 'expression_statement', 'children': ['232']},{'id': '232', 'type': 'call', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'sleep'},{'id': '234', 'type': 'argument_list', 'children': ['235']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'delta_secs'},{'id': '236', 'type': 'except_clause', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'KeyboardInterrupt'},{'id': '238', 'type': 'block', 'children': ['239']},{'id': '239', 'type': 'expression_statement', 'children': ['240']},{'id': '240', 'type': 'call', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '242', 'type': 'argument_list', 'children': ['243']},{'id': '243', 'type': 'string', 'children': [], 'value': '"Bye!"'},{'id': '244', 'type': 'else_clause', 'children': ['245']},{'id': '245', 'type': 'block', 'children': ['246', '251', '260', '307', '344']},{'id': '246', 'type': 'import_from_statement', 'children': ['247', '249']},{'id': '247', 'type': 'dotted_name', 'children': ['248']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'subprocess'},{'id': '249', 'type': 'dotted_name', 'children': ['250']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'check_output'},{'id': '251', 'type': 'expression_statement', 'children': ['252']},{'id': '252', 'type': 'assignment', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '254', 'type': 'call', 'children': ['255', '258']},{'id': '255', 'type': 'attribute', 'children': ['256', '257']},{'id': '256', 'type': 'string', 'children': [], 'value': "'/usr/sbin/i2cdetect -y {}'"},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '258', 'type': 'argument_list', 'children': ['259']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'i2cbus'},{'id': '260', 'type': 'try_statement', 'children': ['261', '291']},{'id': '261', 'type': 'block', 'children': ['262', '273']},{'id': '262', 'type': 'expression_statement', 'children': ['263']},{'id': '263', 'type': 'assignment', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '265', 'type': 'call', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'check_output'},{'id': '267', 'type': 'argument_list', 'children': ['268']},{'id': '268', 'type': 'call', 'children': ['269', '272']},{'id': '269', 'type': 'attribute', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '272', 'type': 'argument_list', 'children': []},{'id': '273', 'type': 'expression_statement', 'children': ['274']},{'id': '274', 'type': 'call', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '276', 'type': 'argument_list', 'children': ['277']},{'id': '277', 'type': 'call', 'children': ['278', '283']},{'id': '278', 'type': 'attribute', 'children': ['279', '282']},{'id': '279', 'type': 'concatenated_string', 'children': ['280', '281']},{'id': '280', 'type': 'string', 'children': [], 'value': '"Running i2cdetect utility in i2c bus {}:\\n"'},{'id': '281', 'type': 'string', 'children': [], 'value': '"The command \'{}\' has returned:\\n{}"'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '283', 'type': 'argument_list', 'children': ['284', '285', '286']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'i2cbus'},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '286', 'type': 'call', 'children': ['287', '290']},{'id': '287', 'type': 'attribute', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'decode'},{'id': '290', 'type': 'argument_list', 'children': []},{'id': '291', 'type': 'except_clause', 'children': ['292', '293']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'FileNotFoundError'},{'id': '293', 'type': 'block', 'children': ['294', '299']},{'id': '294', 'type': 'expression_statement', 'children': ['295']},{'id': '295', 'type': 'call', 'children': ['296', '297']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '297', 'type': 'argument_list', 'children': ['298']},{'id': '298', 'type': 'string', 'children': [], 'value': '"Please install i2cdetect before."'},{'id': '299', 'type': 'expression_statement', 'children': ['300']},{'id': '300', 'type': 'call', 'children': ['301', '304']},{'id': '301', 'type': 'attribute', 'children': ['302', '303']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'exit'},{'id': '304', 'type': 'argument_list', 'children': ['305']},{'id': '305', 'type': 'unary_operator', 'children': ['306'], 'value': '-'},{'id': '306', 'type': 'integer', 'children': [], 'value': '1'},{'id': '307', 'type': 'expression_statement', 'children': ['308']},{'id': '308', 'type': 'assignment', 'children': ['309', '310']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'addresses'},{'id': '310', 'type': 'list_comprehension', 'children': ['311', '314', '329', '340']},{'id': '311', 'type': 'binary_operator', 'children': ['312', '313'], 'value': '+'},{'id': '312', 'type': 'string', 'children': [], 'value': "'0x'"},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '314', 'type': 'for_in_clause', 'children': ['315', '316']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '316', 'type': 'subscript', 'children': ['317', '326']},{'id': '317', 'type': 'call', 'children': ['318', '325']},{'id': '318', 'type': 'attribute', 'children': ['319', '324']},{'id': '319', 'type': 'call', 'children': ['320', '323']},{'id': '320', 'type': 'attribute', 'children': ['321', '322']},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'decode'},{'id': '323', 'type': 'argument_list', 'children': []},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'splitlines'},{'id': '325', 'type': 'argument_list', 'children': []},{'id': '326', 'type': 'slice', 'children': ['327', '328']},{'id': '327', 'type': 'integer', 'children': [], 'value': '1'},{'id': '328', 'type': 'colon', 'children': []},{'id': '329', 'type': 'for_in_clause', 'children': ['330', '331']},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '331', 'type': 'subscript', 'children': ['332', '337']},{'id': '332', 'type': 'call', 'children': ['333', '336']},{'id': '333', 'type': 'attribute', 'children': ['334', '335']},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '336', 'type': 'argument_list', 'children': []},{'id': '337', 'type': 'slice', 'children': ['338', '339']},{'id': '338', 'type': 'integer', 'children': [], 'value': '1'},{'id': '339', 'type': 'colon', 'children': []},{'id': '340', 'type': 'if_clause', 'children': ['341']},{'id': '341', 'type': 'comparison_operator', 'children': ['342', '343'], 'value': '!='},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '343', 'type': 'string', 'children': [], 'value': "'--'"},{'id': '344', 'type': 'if_statement', 'children': ['345', '346', '366']},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'addresses'},{'id': '346', 'type': 'block', 'children': ['347']},{'id': '347', 'type': 'expression_statement', 'children': ['348']},{'id': '348', 'type': 'call', 'children': ['349', '350']},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '350', 'type': 'argument_list', 'children': ['351']},{'id': '351', 'type': 'call', 'children': ['352', '355']},{'id': '352', 'type': 'attribute', 'children': ['353', '354']},{'id': '353', 'type': 'string', 'children': [], 'value': '"{} sensors detected in {}"'},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '355', 'type': 'argument_list', 'children': ['356', '360']},{'id': '356', 'type': 'call', 'children': ['357', '358']},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '358', 'type': 'argument_list', 'children': ['359']},{'id': '359', 'type': 'identifier', 'children': [], 'value': 'addresses'},{'id': '360', 'type': 'call', 'children': ['361', '364']},{'id': '361', 'type': 'attribute', 'children': ['362', '363']},{'id': '362', 'type': 'string', 'children': [], 'value': "', '"},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '364', 'type': 'argument_list', 'children': ['365']},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'addresses'},{'id': '366', 'type': 'else_clause', 'children': ['367']},{'id': '367', 'type': 'block', 'children': ['368']},{'id': '368', 'type': 'expression_statement', 'children': ['369']},{'id': '369', 'type': 'call', 'children': ['370', '371']},{'id': '370', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '371', 'type': 'argument_list', 'children': ['372']},{'id': '372', 'type': 'string', 'children': [], 'value': '"No i2c sensors detected."'}
def main_cli(): 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 try: import smbus bus_handler = smbus.SMBus(i2cbus) except ImportError as exc: print(exc, "\n", "Please install smbus-cffi before.") sys.exit(-1) 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 = sensor_handler(bus_handler, i2c_address, **params) 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: 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) 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.")
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'variant_support'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'variants'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'allele_support_df'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'ignore_missing'},{'id': '8', 'type': 'False', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '12', '26', '41', '59', '72', '81', '119', '126', '141', '338', '364']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'string', 'children': [], 'value': "'''\n Collect the read evidence support for the given variants.\n Parameters\n ----------\n variants : iterable of varcode.Variant\n allele_support_df : dataframe\n Allele support dataframe, as output by the varlens-allele-support tool.\n It should have columns: source, contig, interbase_start, interbase_end,\n allele. The remaining columns are interpreted as read counts of various\n subsets of reads (e.g. all reads, non-duplicate reads, etc.)\n ignore_missing : boolean\n If True, then varaints with no allele counts will be interpreted as\n having 0 depth. If False, then an exception will be raised if any\n variants have no allele counts.\n Returns\n ----------\n A pandas.Panel4D frame with these axes:\n labels (axis=0) : the type of read being counted, i.e. the read count\n fields in allele_support_df.\n items (axis=1) : the type of measurement (num_alt, num_ref, num_other,\n total_depth, alt_fraction, any_alt_fraction)\n major axis (axis=2) : the variants\n minor axis (axis=3) : the sources\n '''"},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'missing'},{'id': '15', 'type': 'list_comprehension', 'children': ['16', '17', '20']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '17', 'type': 'for_in_clause', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'EXPECTED_COLUMNS'},{'id': '20', 'type': 'if_clause', 'children': ['21']},{'id': '21', 'type': 'comparison_operator', 'children': ['22', '23'], 'value': 'not'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'allele_support_df'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '26', 'type': 'if_statement', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'missing'},{'id': '28', 'type': 'block', 'children': ['29']},{'id': '29', 'type': 'raise_statement', 'children': ['30']},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'binary_operator', 'children': ['34', '35'], 'value': '%'},{'id': '34', 'type': 'string', 'children': [], 'value': '"Missing columns: %s"'},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'string', 'children': [], 'value': '" "'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'missing'},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '48']},{'id': '43', 'type': 'subscript', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'allele_support_df'},{'id': '45', 'type': 'list', 'children': ['46', '47'], 'value': '["interbase_start", "interbase_end"]'},{'id': '46', 'type': 'string', 'children': [], 'value': '"interbase_start"'},{'id': '47', 'type': 'string', 'children': [], 'value': '"interbase_end"'},{'id': '48', 'type': '()', 'children': ['49']},{'id': '49', 'type': 'call', 'children': ['50', '57']},{'id': '50', 'type': 'attribute', 'children': ['51', '56']},{'id': '51', 'type': 'subscript', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'allele_support_df'},{'id': '53', 'type': 'list', 'children': ['54', '55'], 'value': '["interbase_start", "interbase_end"]'},{'id': '54', 'type': 'string', 'children': [], 'value': '"interbase_start"'},{'id': '55', 'type': 'string', 'children': [], 'value': '"interbase_end"'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'astype'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'assignment', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'sources'},{'id': '62', 'type': 'call', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'call', 'children': ['66', '71']},{'id': '66', 'type': 'attribute', 'children': ['67', '70']},{'id': '67', 'type': 'subscript', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'allele_support_df'},{'id': '69', 'type': 'string', 'children': [], 'value': '"source"'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'unique'},{'id': '71', 'type': 'argument_list', 'children': []},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'allele_support_dict'},{'id': '75', 'type': 'call', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'collections'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'defaultdict'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '81', 'type': 'for_statement', 'children': ['82', '85', '90']},{'id': '82', 'type': 'tuple_pattern', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '85', 'type': 'call', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'allele_support_df'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'iterrows'},{'id': '89', 'type': 'argument_list', 'children': []},{'id': '90', 'type': 'block', 'children': ['91', '107']},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '94', 'type': 'tuple', 'children': ['95', '98', '101', '104']},{'id': '95', 'type': 'subscript', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '97', 'type': 'string', 'children': [], 'value': "'source'"},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'contig'},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'interbase_start'},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'interbase_end'},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '116']},{'id': '109', 'type': 'subscript', 'children': ['110', '113']},{'id': '110', 'type': 'subscript', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'allele_support_dict'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'allele'},{'id': '116', 'type': 'subscript', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '118', 'type': 'string', 'children': [], 'value': '"count"'},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'assignment', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'allele_support_dict'},{'id': '122', 'type': 'call', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'allele_support_dict'},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'assignment', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'dataframe_dicts'},{'id': '129', 'type': 'call', 'children': ['130', '133']},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'collections'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'defaultdict'},{'id': '133', 'type': 'argument_list', 'children': ['134']},{'id': '134', 'type': 'lambda', 'children': ['135']},{'id': '135', 'type': 'call', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'collections'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'defaultdict'},{'id': '139', 'type': 'argument_list', 'children': ['140']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '141', 'type': 'for_statement', 'children': ['142', '143', '144']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'variants'},{'id': '144', 'type': 'block', 'children': ['145']},{'id': '145', 'type': 'for_statement', 'children': ['146', '147', '148']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'sources'},{'id': '148', 'type': 'block', 'children': ['149', '165', '209', '221', '233', '244', '252', '263', '274', '285', '296', '316']},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'assignment', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '152', 'type': 'tuple', 'children': ['153', '154', '157', '162']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'contig'},{'id': '157', 'type': 'binary_operator', 'children': ['158', '161'], 'value': '-'},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '161', 'type': 'integer', 'children': [], 'value': '1'},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '165', 'type': 'try_statement', 'children': ['166', '173']},{'id': '166', 'type': 'block', 'children': ['167']},{'id': '167', 'type': 'expression_statement', 'children': ['168']},{'id': '168', 'type': 'assignment', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'alleles'},{'id': '170', 'type': 'subscript', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'allele_support_dict'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '173', 'type': 'except_clause', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '175', 'type': 'block', 'children': ['176', '188']},{'id': '176', 'type': 'expression_statement', 'children': ['177']},{'id': '177', 'type': 'assignment', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '179', 'type': '()', 'children': ['180']},{'id': '180', 'type': 'binary_operator', 'children': ['181', '182'], 'value': '%'},{'id': '181', 'type': 'string', 'children': [], 'value': '"No allele counts in source %s for variant %s"'},{'id': '182', 'type': 'tuple', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '184', 'type': 'call', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '186', 'type': 'argument_list', 'children': ['187']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '188', 'type': 'if_statement', 'children': ['189', '190', '202']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'ignore_missing'},{'id': '190', 'type': 'block', 'children': ['191', '198']},{'id': '191', 'type': 'expression_statement', 'children': ['192']},{'id': '192', 'type': 'call', 'children': ['193', '196']},{'id': '193', 'type': 'attribute', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '196', 'type': 'argument_list', 'children': ['197']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '198', 'type': 'expression_statement', 'children': ['199']},{'id': '199', 'type': 'assignment', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'alleles'},{'id': '201', 'type': 'dictionary', 'children': []},{'id': '202', 'type': 'else_clause', 'children': ['203']},{'id': '203', 'type': 'block', 'children': ['204']},{'id': '204', 'type': 'raise_statement', 'children': ['205']},{'id': '205', 'type': 'call', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '207', 'type': 'argument_list', 'children': ['208']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '209', 'type': 'expression_statement', 'children': ['210']},{'id': '210', 'type': 'assignment', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'alt'},{'id': '212', 'type': 'call', 'children': ['213', '216']},{'id': '213', 'type': 'attribute', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'alleles'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '216', 'type': 'argument_list', 'children': ['217', '220']},{'id': '217', 'type': 'attribute', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'alt'},{'id': '220', 'type': 'integer', 'children': [], 'value': '0'},{'id': '221', 'type': 'expression_statement', 'children': ['222']},{'id': '222', 'type': 'assignment', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'ref'},{'id': '224', 'type': 'call', 'children': ['225', '228']},{'id': '225', 'type': 'attribute', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'alleles'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '228', 'type': 'argument_list', 'children': ['229', '232']},{'id': '229', 'type': 'attribute', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'ref'},{'id': '232', 'type': 'integer', 'children': [], 'value': '0'},{'id': '233', 'type': 'expression_statement', 'children': ['234']},{'id': '234', 'type': 'assignment', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'total'},{'id': '236', 'type': 'call', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '238', 'type': 'argument_list', 'children': ['239']},{'id': '239', 'type': 'call', 'children': ['240', '243']},{'id': '240', 'type': 'attribute', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'alleles'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '243', 'type': 'argument_list', 'children': []},{'id': '244', 'type': 'expression_statement', 'children': ['245']},{'id': '245', 'type': 'assignment', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '247', 'type': 'binary_operator', 'children': ['248', '251'], 'value': '-'},{'id': '248', 'type': 'binary_operator', 'children': ['249', '250'], 'value': '-'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'total'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'alt'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'ref'},{'id': '252', 'type': 'expression_statement', 'children': ['253']},{'id': '253', 'type': 'call', 'children': ['254', '261']},{'id': '254', 'type': 'attribute', 'children': ['255', '260']},{'id': '255', 'type': 'subscript', 'children': ['256', '259']},{'id': '256', 'type': 'subscript', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'dataframe_dicts'},{'id': '258', 'type': 'string', 'children': [], 'value': '"num_alt"'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '261', 'type': 'argument_list', 'children': ['262']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'alt'},{'id': '263', 'type': 'expression_statement', 'children': ['264']},{'id': '264', 'type': 'call', 'children': ['265', '272']},{'id': '265', 'type': 'attribute', 'children': ['266', '271']},{'id': '266', 'type': 'subscript', 'children': ['267', '270']},{'id': '267', 'type': 'subscript', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'dataframe_dicts'},{'id': '269', 'type': 'string', 'children': [], 'value': '"num_ref"'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '272', 'type': 'argument_list', 'children': ['273']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'ref'},{'id': '274', 'type': 'expression_statement', 'children': ['275']},{'id': '275', 'type': 'call', 'children': ['276', '283']},{'id': '276', 'type': 'attribute', 'children': ['277', '282']},{'id': '277', 'type': 'subscript', 'children': ['278', '281']},{'id': '278', 'type': 'subscript', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'dataframe_dicts'},{'id': '280', 'type': 'string', 'children': [], 'value': '"num_other"'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '283', 'type': 'argument_list', 'children': ['284']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '285', 'type': 'expression_statement', 'children': ['286']},{'id': '286', 'type': 'call', 'children': ['287', '294']},{'id': '287', 'type': 'attribute', 'children': ['288', '293']},{'id': '288', 'type': 'subscript', 'children': ['289', '292']},{'id': '289', 'type': 'subscript', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'dataframe_dicts'},{'id': '291', 'type': 'string', 'children': [], 'value': '"total_depth"'},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '294', 'type': 'argument_list', 'children': ['295']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'total'},{'id': '296', 'type': 'expression_statement', 'children': ['297']},{'id': '297', 'type': 'call', 'children': ['298', '305']},{'id': '298', 'type': 'attribute', 'children': ['299', '304']},{'id': '299', 'type': 'subscript', 'children': ['300', '303']},{'id': '300', 'type': 'subscript', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'dataframe_dicts'},{'id': '302', 'type': 'string', 'children': [], 'value': '"alt_fraction"'},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '305', 'type': 'argument_list', 'children': ['306']},{'id': '306', 'type': 'binary_operator', 'children': ['307', '311'], 'value': '/'},{'id': '307', 'type': 'call', 'children': ['308', '309']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '309', 'type': 'argument_list', 'children': ['310']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'alt'},{'id': '311', 'type': 'call', 'children': ['312', '313']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '313', 'type': 'argument_list', 'children': ['314', '315']},{'id': '314', 'type': 'integer', 'children': [], 'value': '1'},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'total'},{'id': '316', 'type': 'expression_statement', 'children': ['317']},{'id': '317', 'type': 'call', 'children': ['318', '325']},{'id': '318', 'type': 'attribute', 'children': ['319', '324']},{'id': '319', 'type': 'subscript', 'children': ['320', '323']},{'id': '320', 'type': 'subscript', 'children': ['321', '322']},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'dataframe_dicts'},{'id': '322', 'type': 'string', 'children': [], 'value': '"any_alt_fraction"'},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '325', 'type': 'argument_list', 'children': ['326']},{'id': '326', 'type': 'binary_operator', 'children': ['327', '333'], 'value': '/'},{'id': '327', 'type': 'call', 'children': ['328', '329']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '329', 'type': 'argument_list', 'children': ['330']},{'id': '330', 'type': 'binary_operator', 'children': ['331', '332'], 'value': '+'},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'alt'},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '333', 'type': 'call', 'children': ['334', '335']},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '335', 'type': 'argument_list', 'children': ['336', '337']},{'id': '336', 'type': 'integer', 'children': [], 'value': '1'},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'total'},{'id': '338', 'type': 'expression_statement', 'children': ['339']},{'id': '339', 'type': 'assignment', 'children': ['340', '341']},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'dataframes'},{'id': '341', 'type': 'call', 'children': ['342', '343']},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '343', 'type': 'generator_expression', 'children': ['344', '355']},{'id': '344', 'type': 'tuple', 'children': ['345', '346']},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '346', 'type': 'call', 'children': ['347', '350']},{'id': '347', 'type': 'attribute', 'children': ['348', '349']},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'pandas'},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'DataFrame'},{'id': '350', 'type': 'argument_list', 'children': ['351', '352']},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '352', 'type': 'keyword_argument', 'children': ['353', '354']},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'variants'},{'id': '355', 'type': 'for_in_clause', 'children': ['356', '359']},{'id': '356', 'type': 'tuple_pattern', 'children': ['357', '358']},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '359', 'type': 'call', 'children': ['360', '363']},{'id': '360', 'type': 'attribute', 'children': ['361', '362']},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'dataframe_dicts'},{'id': '362', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '363', 'type': 'argument_list', 'children': []},{'id': '364', 'type': 'return_statement', 'children': ['365']},{'id': '365', 'type': 'call', 'children': ['366', '369']},{'id': '366', 'type': 'attribute', 'children': ['367', '368']},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'pandas'},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'Panel'},{'id': '369', 'type': 'argument_list', 'children': ['370']},{'id': '370', 'type': 'identifier', 'children': [], 'value': '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)) 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"] 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)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '21', '25']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_wavReadData'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '9', '13', '17']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'fid'},{'id': '5', 'type': 'typed_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '7', 'type': 'type', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '9', 'type': 'typed_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'channels'},{'id': '11', 'type': 'type', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '13', 'type': 'typed_parameter', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '15', 'type': 'type', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '17', 'type': 'typed_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'bigendian'},{'id': '19', 'type': 'type', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'bool'},{'id': '21', 'type': 'type', 'children': ['22']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'ndarray'},{'id': '25', 'type': 'block', 'children': ['26', '37', '254']},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'bits'},{'id': '29', 'type': 'call', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'subscript', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '34', 'type': 'slice', 'children': ['35', '36']},{'id': '35', 'type': 'integer', 'children': [], 'value': '3'},{'id': '36', 'type': 'colon', 'children': []},{'id': '37', 'type': 'if_statement', 'children': ['38', '41', '75']},{'id': '38', 'type': 'comparison_operator', 'children': ['39', '40'], 'value': '=='},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'bits'},{'id': '40', 'type': 'integer', 'children': [], 'value': '8'},{'id': '41', 'type': 'block', 'children': ['42', '59']},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '45', 'type': 'call', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'fromfile'},{'id': '49', 'type': 'argument_list', 'children': ['50', '51', '56']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'fid'},{'id': '51', 'type': 'keyword_argument', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'ubyte'},{'id': '56', 'type': 'keyword_argument', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '59', 'type': 'if_statement', 'children': ['60', '63']},{'id': '60', 'type': 'comparison_operator', 'children': ['61', '62'], 'value': '>'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'channels'},{'id': '62', 'type': 'integer', 'children': [], 'value': '1'},{'id': '63', 'type': 'block', 'children': ['64']},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '67', 'type': 'call', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'reshape'},{'id': '71', 'type': 'argument_list', 'children': ['72', '74']},{'id': '72', 'type': 'unary_operator', 'children': ['73'], 'value': '-'},{'id': '73', 'type': 'integer', 'children': [], 'value': '1'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'channels'},{'id': '75', 'type': 'else_clause', 'children': ['76']},{'id': '76', 'type': 'block', 'children': ['77', '83']},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'bytes'},{'id': '80', 'type': 'binary_operator', 'children': ['81', '82'], 'value': '//'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'bits'},{'id': '82', 'type': 'integer', 'children': [], 'value': '8'},{'id': '83', 'type': 'if_statement', 'children': ['84', '90', '141', '210']},{'id': '84', 'type': 'comparison_operator', 'children': ['85', '86'], 'value': 'in'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '86', 'type': 'tuple', 'children': ['87', '88', '89']},{'id': '87', 'type': 'string', 'children': [], 'value': "'pcm16'"},{'id': '88', 'type': 'string', 'children': [], 'value': "'pcm32'"},{'id': '89', 'type': 'string', 'children': [], 'value': "'pcm64'"},{'id': '90', 'type': 'block', 'children': ['91', '108', '125']},{'id': '91', 'type': 'if_statement', 'children': ['92', '93', '100']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'bigendian'},{'id': '93', 'type': 'block', 'children': ['94']},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'assignment', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '97', 'type': 'binary_operator', 'children': ['98', '99'], 'value': '%'},{'id': '98', 'type': 'string', 'children': [], 'value': "'>i%d'"},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'bytes'},{'id': '100', 'type': 'else_clause', 'children': ['101']},{'id': '101', 'type': 'block', 'children': ['102']},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'assignment', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '105', 'type': 'binary_operator', 'children': ['106', '107'], 'value': '%'},{'id': '106', 'type': 'string', 'children': [], 'value': "'<i%d'"},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'bytes'},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'assignment', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '111', 'type': 'call', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'fromfile'},{'id': '115', 'type': 'argument_list', 'children': ['116', '117', '120']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'fid'},{'id': '117', 'type': 'keyword_argument', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '120', 'type': 'keyword_argument', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '122', 'type': 'binary_operator', 'children': ['123', '124'], 'value': '//'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'bytes'},{'id': '125', 'type': 'if_statement', 'children': ['126', '129']},{'id': '126', 'type': 'comparison_operator', 'children': ['127', '128'], 'value': '>'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'channels'},{'id': '128', 'type': 'integer', 'children': [], 'value': '1'},{'id': '129', 'type': 'block', 'children': ['130']},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'assignment', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '133', 'type': 'call', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'reshape'},{'id': '137', 'type': 'argument_list', 'children': ['138', '140']},{'id': '138', 'type': 'unary_operator', 'children': ['139'], 'value': '-'},{'id': '139', 'type': 'integer', 'children': [], 'value': '1'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'channels'},{'id': '141', 'type': 'elif_clause', 'children': ['142', '149']},{'id': '142', 'type': 'comparison_operator', 'children': ['143', '148'], 'value': '=='},{'id': '143', 'type': 'subscript', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '145', 'type': 'slice', 'children': ['146', '147']},{'id': '146', 'type': 'colon', 'children': []},{'id': '147', 'type': 'integer', 'children': [], 'value': '3'},{'id': '148', 'type': 'string', 'children': [], 'value': "'flt'"},{'id': '149', 'type': 'block', 'children': ['150', '155', '177', '194']},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'call', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '153', 'type': 'argument_list', 'children': ['154']},{'id': '154', 'type': 'string', 'children': [], 'value': '"flt32!"'},{'id': '155', 'type': 'if_statement', 'children': ['156', '159', '173']},{'id': '156', 'type': 'comparison_operator', 'children': ['157', '158'], 'value': '=='},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'bits'},{'id': '158', 'type': 'integer', 'children': [], 'value': '32'},{'id': '159', 'type': 'block', 'children': ['160']},{'id': '160', 'type': 'if_statement', 'children': ['161', '162', '167']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'bigendian'},{'id': '162', 'type': 'block', 'children': ['163']},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'assignment', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '166', 'type': 'string', 'children': [], 'value': "'>f4'"},{'id': '167', 'type': 'else_clause', 'children': ['168']},{'id': '168', 'type': 'block', 'children': ['169']},{'id': '169', 'type': 'expression_statement', 'children': ['170']},{'id': '170', 'type': 'assignment', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '172', 'type': 'string', 'children': [], 'value': "'<f4'"},{'id': '173', 'type': 'else_clause', 'children': ['174']},{'id': '174', 'type': 'block', 'children': ['175']},{'id': '175', 'type': 'raise_statement', 'children': ['176']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'NotImplementedError'},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'assignment', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '180', 'type': 'call', 'children': ['181', '184']},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'fromfile'},{'id': '184', 'type': 'argument_list', 'children': ['185', '186', '189']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'fid'},{'id': '186', 'type': 'keyword_argument', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '189', 'type': 'keyword_argument', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '191', 'type': 'binary_operator', 'children': ['192', '193'], 'value': '//'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'bytes'},{'id': '194', 'type': 'if_statement', 'children': ['195', '198']},{'id': '195', 'type': 'comparison_operator', 'children': ['196', '197'], 'value': '>'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'channels'},{'id': '197', 'type': 'integer', 'children': [], 'value': '1'},{'id': '198', 'type': 'block', 'children': ['199']},{'id': '199', 'type': 'expression_statement', 'children': ['200']},{'id': '200', 'type': 'assignment', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '202', 'type': 'call', 'children': ['203', '206']},{'id': '203', 'type': 'attribute', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'reshape'},{'id': '206', 'type': 'argument_list', 'children': ['207', '209']},{'id': '207', 'type': 'unary_operator', 'children': ['208'], 'value': '-'},{'id': '208', 'type': 'integer', 'children': [], 'value': '1'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'channels'},{'id': '210', 'type': 'elif_clause', 'children': ['211', '214']},{'id': '211', 'type': 'comparison_operator', 'children': ['212', '213'], 'value': '=='},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '213', 'type': 'string', 'children': [], 'value': "'pcm24'"},{'id': '214', 'type': 'block', 'children': ['215', '238']},{'id': '215', 'type': 'expression_statement', 'children': ['216']},{'id': '216', 'type': 'assignment', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '218', 'type': 'call', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': '_numpy24to32bit'},{'id': '220', 'type': 'argument_list', 'children': ['221', '235']},{'id': '221', 'type': 'call', 'children': ['222', '225']},{'id': '222', 'type': 'attribute', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'fromfile'},{'id': '225', 'type': 'argument_list', 'children': ['226', '227', '232']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'fid'},{'id': '227', 'type': 'keyword_argument', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '229', 'type': 'attribute', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'ubyte'},{'id': '232', 'type': 'keyword_argument', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '235', 'type': 'keyword_argument', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'bigendian'},{'id': '237', 'type': 'False', 'children': []},{'id': '238', 'type': 'if_statement', 'children': ['239', '242']},{'id': '239', 'type': 'comparison_operator', 'children': ['240', '241'], 'value': '>'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'channels'},{'id': '241', 'type': 'integer', 'children': [], 'value': '1'},{'id': '242', 'type': 'block', 'children': ['243']},{'id': '243', 'type': 'expression_statement', 'children': ['244']},{'id': '244', 'type': 'assignment', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '246', 'type': 'call', 'children': ['247', '250']},{'id': '247', 'type': 'attribute', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'reshape'},{'id': '250', 'type': 'argument_list', 'children': ['251', '253']},{'id': '251', 'type': 'unary_operator', 'children': ['252'], 'value': '-'},{'id': '252', 'type': 'integer', 'children': [], 'value': '1'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'channels'},{'id': '254', 'type': 'return_statement', 'children': ['255']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'data'}
def _wavReadData(fid, size:int, channels:int, encoding:str, bigendian:bool) -> np.ndarray: 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': data = _numpy24to32bit(np.fromfile(fid, dtype=np.ubyte, count=size), bigendian=False) if channels > 1: data = data.reshape(-1, channels) return data
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'refreshButton'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '14', '20', '25', '33', '60', '64', '195', '262']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'collapsed'},{'id': '9', 'type': 'call', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'isCollapsed'},{'id': '13', 'type': 'argument_list', 'children': []},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'btn'},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '19', 'type': 'identifier', 'children': [], 'value': '_collapseButton'},{'id': '20', 'type': 'if_statement', 'children': ['21', '23']},{'id': '21', 'type': 'not_operator', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'btn'},{'id': '23', 'type': 'block', 'children': ['24']},{'id': '24', 'type': 'return_statement', 'children': []},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'btn'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'setMaximumSize'},{'id': '30', 'type': 'argument_list', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'MAX_SIZE'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'MAX_SIZE'},{'id': '33', 'type': 'if_statement', 'children': ['34', '43', '51']},{'id': '34', 'type': 'comparison_operator', 'children': ['35', '40'], 'value': '=='},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'orientation'},{'id': '39', 'type': 'argument_list', 'children': []},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'Qt'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'Vertical'},{'id': '43', 'type': 'block', 'children': ['44']},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'call', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'btn'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'setMaximumHeight'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'integer', 'children': [], 'value': '12'},{'id': '51', 'type': 'else_clause', 'children': ['52']},{'id': '52', 'type': 'block', 'children': ['53']},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'btn'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'setMaximumWidth'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'integer', 'children': [], 'value': '12'},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'icon'},{'id': '63', 'type': 'string', 'children': [], 'value': "''"},{'id': '64', 'type': 'if_statement', 'children': ['65', '74', '134']},{'id': '65', 'type': 'comparison_operator', 'children': ['66', '71'], 'value': '=='},{'id': '66', 'type': 'call', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'orientation'},{'id': '70', 'type': 'argument_list', 'children': []},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'Qt'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'Vertical'},{'id': '74', 'type': 'block', 'children': ['75']},{'id': '75', 'type': 'if_statement', 'children': ['76', '77', '103']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'collapsed'},{'id': '77', 'type': 'block', 'children': ['78', '87', '94']},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'call', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'setFixedWidth'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '86', 'type': 'identifier', 'children': [], 'value': '_collapsedSize'},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'call', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'btn'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'setMaximumHeight'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'MAX_SIZE'},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'call', 'children': ['96', '99']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'btn'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'setArrowType'},{'id': '99', 'type': 'argument_list', 'children': ['100']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'Qt'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'RightArrow'},{'id': '103', 'type': 'else_clause', 'children': ['104']},{'id': '104', 'type': 'block', 'children': ['105', '112', '118', '125']},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'call', 'children': ['107', '110']},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'setMaximumWidth'},{'id': '110', 'type': 'argument_list', 'children': ['111']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'MAX_SIZE'},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'assignment', 'children': ['114', '117']},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '116', 'type': 'identifier', 'children': [], 'value': '_precollapseSize'},{'id': '117', 'type': 'None', 'children': []},{'id': '118', 'type': 'expression_statement', 'children': ['119']},{'id': '119', 'type': 'call', 'children': ['120', '123']},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'btn'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'setMaximumHeight'},{'id': '123', 'type': 'argument_list', 'children': ['124']},{'id': '124', 'type': 'integer', 'children': [], 'value': '12'},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'call', 'children': ['127', '130']},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'btn'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'setArrowType'},{'id': '130', 'type': 'argument_list', 'children': ['131']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'Qt'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'LeftArrow'},{'id': '134', 'type': 'else_clause', 'children': ['135']},{'id': '135', 'type': 'block', 'children': ['136']},{'id': '136', 'type': 'if_statement', 'children': ['137', '138', '164']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'collapsed'},{'id': '138', 'type': 'block', 'children': ['139', '148', '155']},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'id': '140', 'type': 'call', 'children': ['141', '144']},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'setFixedHeight'},{'id': '144', 'type': 'argument_list', 'children': ['145']},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '147', 'type': 'identifier', 'children': [], 'value': '_collapsedSize'},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'call', 'children': ['150', '153']},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'btn'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'setMaximumWidth'},{'id': '153', 'type': 'argument_list', 'children': ['154']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'MAX_SIZE'},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'call', 'children': ['157', '160']},{'id': '157', 'type': 'attribute', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'btn'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'setArrowType'},{'id': '160', 'type': 'argument_list', 'children': ['161']},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'Qt'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'DownArrow'},{'id': '164', 'type': 'else_clause', 'children': ['165']},{'id': '165', 'type': 'block', 'children': ['166', '173', '179', '186']},{'id': '166', 'type': 'expression_statement', 'children': ['167']},{'id': '167', 'type': 'call', 'children': ['168', '171']},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'setMaximumHeight'},{'id': '171', 'type': 'argument_list', 'children': ['172']},{'id': '172', 'type': 'integer', 'children': [], 'value': '1000'},{'id': '173', 'type': 'expression_statement', 'children': ['174']},{'id': '174', 'type': 'assignment', 'children': ['175', '178']},{'id': '175', 'type': 'attribute', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '177', 'type': 'identifier', 'children': [], 'value': '_precollapseSize'},{'id': '178', 'type': 'None', 'children': []},{'id': '179', 'type': 'expression_statement', 'children': ['180']},{'id': '180', 'type': 'call', 'children': ['181', '184']},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'btn'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'setMaximumWidth'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'integer', 'children': [], 'value': '12'},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'call', 'children': ['188', '191']},{'id': '188', 'type': 'attribute', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'btn'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'setArrowType'},{'id': '191', 'type': 'argument_list', 'children': ['192']},{'id': '192', 'type': 'attribute', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'Qt'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'UpArrow'},{'id': '195', 'type': 'for_statement', 'children': ['196', '197', '210']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '197', 'type': 'call', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '199', 'type': 'argument_list', 'children': ['200', '201']},{'id': '200', 'type': 'integer', 'children': [], 'value': '1'},{'id': '201', 'type': 'call', 'children': ['202', '209']},{'id': '202', 'type': 'attribute', 'children': ['203', '208']},{'id': '203', 'type': 'call', 'children': ['204', '207']},{'id': '204', 'type': 'attribute', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'layout'},{'id': '207', 'type': 'argument_list', 'children': []},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '209', 'type': 'argument_list', 'children': []},{'id': '210', 'type': 'block', 'children': ['211', '224', '233']},{'id': '211', 'type': 'expression_statement', 'children': ['212']},{'id': '212', 'type': 'assignment', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '214', 'type': 'call', 'children': ['215', '222']},{'id': '215', 'type': 'attribute', 'children': ['216', '221']},{'id': '216', 'type': 'call', 'children': ['217', '220']},{'id': '217', 'type': 'attribute', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'layout'},{'id': '220', 'type': 'argument_list', 'children': []},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'itemAt'},{'id': '222', 'type': 'argument_list', 'children': ['223']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '224', 'type': 'if_statement', 'children': ['225', '231']},{'id': '225', 'type': 'not_operator', 'children': ['226']},{'id': '226', 'type': 'call', 'children': ['227', '230']},{'id': '227', 'type': 'attribute', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'widget'},{'id': '230', 'type': 'argument_list', 'children': []},{'id': '231', 'type': 'block', 'children': ['232']},{'id': '232', 'type': 'continue_statement', 'children': []},{'id': '233', 'type': 'if_statement', 'children': ['234', '235', '248']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'collapsed'},{'id': '235', 'type': 'block', 'children': ['236']},{'id': '236', 'type': 'expression_statement', 'children': ['237']},{'id': '237', 'type': 'call', 'children': ['238', '245']},{'id': '238', 'type': 'attribute', 'children': ['239', '244']},{'id': '239', 'type': 'call', 'children': ['240', '243']},{'id': '240', 'type': 'attribute', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'widget'},{'id': '243', 'type': 'argument_list', 'children': []},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'setMaximumSize'},{'id': '245', 'type': 'argument_list', 'children': ['246', '247']},{'id': '246', 'type': 'integer', 'children': [], 'value': '0'},{'id': '247', 'type': 'integer', 'children': [], 'value': '0'},{'id': '248', 'type': 'else_clause', 'children': ['249']},{'id': '249', 'type': 'block', 'children': ['250']},{'id': '250', 'type': 'expression_statement', 'children': ['251']},{'id': '251', 'type': 'call', 'children': ['252', '259']},{'id': '252', 'type': 'attribute', 'children': ['253', '258']},{'id': '253', 'type': 'call', 'children': ['254', '257']},{'id': '254', 'type': 'attribute', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'widget'},{'id': '257', 'type': 'argument_list', 'children': []},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'setMaximumSize'},{'id': '259', 'type': 'argument_list', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'MAX_SIZE'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'MAX_SIZE'},{'id': '262', 'type': 'if_statement', 'children': ['263', '269', '276']},{'id': '263', 'type': 'not_operator', 'children': ['264']},{'id': '264', 'type': 'call', 'children': ['265', '268']},{'id': '265', 'type': 'attribute', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'isCollapsable'},{'id': '268', 'type': 'argument_list', 'children': []},{'id': '269', 'type': 'block', 'children': ['270']},{'id': '270', 'type': 'expression_statement', 'children': ['271']},{'id': '271', 'type': 'call', 'children': ['272', '275']},{'id': '272', 'type': 'attribute', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'btn'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'hide'},{'id': '275', 'type': 'argument_list', 'children': []},{'id': '276', 'type': 'else_clause', 'children': ['277']},{'id': '277', 'type': 'block', 'children': ['278']},{'id': '278', 'type': 'expression_statement', 'children': ['279']},{'id': '279', 'type': 'call', 'children': ['280', '283']},{'id': '280', 'type': 'attribute', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'btn'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'show'},{'id': '283', 'type': 'argument_list', 'children': []}
def refreshButton(self): collapsed = self.isCollapsed() btn = self._collapseButton if not btn: return btn.setMaximumSize(MAX_SIZE, MAX_SIZE) if self.orientation() == Qt.Vertical: btn.setMaximumHeight(12) else: btn.setMaximumWidth(12) icon = '' 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()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'applyCommand'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '14', '23', '42', '50', '62', '72', '447', '454']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '9', 'type': 'call', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'textCursor'},{'id': '13', 'type': 'argument_list', 'children': []},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'call', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'movePosition'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'EndOfLine'},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '26', 'type': 'call', 'children': ['27', '32']},{'id': '27', 'type': 'attribute', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'projex'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'nativestring'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'call', 'children': ['34', '41']},{'id': '34', 'type': 'attribute', 'children': ['35', '40']},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'block'},{'id': '39', 'type': 'argument_list', 'children': []},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '41', 'type': 'argument_list', 'children': []},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'at_end'},{'id': '45', 'type': 'call', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'atEnd'},{'id': '49', 'type': 'argument_list', 'children': []},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'modifiers'},{'id': '53', 'type': 'call', 'children': ['54', '61']},{'id': '54', 'type': 'attribute', 'children': ['55', '60']},{'id': '55', 'type': 'call', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'QApplication'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '59', 'type': 'argument_list', 'children': []},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'keyboardModifiers'},{'id': '61', 'type': 'argument_list', 'children': []},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'mod_mode'},{'id': '65', 'type': 'boolean_operator', 'children': ['66', '67'], 'value': 'or'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'at_end'},{'id': '67', 'type': 'comparison_operator', 'children': ['68', '69'], 'value': '=='},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'modifiers'},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'Qt'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'ShiftModifier'},{'id': '72', 'type': 'if_statement', 'children': ['73', '81', '144', '216', '437']},{'id': '73', 'type': 'boolean_operator', 'children': ['74', '75'], 'value': 'and'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'mod_mode'},{'id': '75', 'type': 'call', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'endswith'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'string', 'children': [], 'value': "':'"},{'id': '81', 'type': 'block', 'children': ['82', '91', '102', '113', '131', '142']},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'call', 'children': ['84', '87']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'movePosition'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'EndOfLine'},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '94', 'type': 'call', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'sub'},{'id': '98', 'type': 'argument_list', 'children': ['99', '100', '101']},{'id': '99', 'type': 'string', 'children': [], 'value': "'^>>> '"},{'id': '100', 'type': 'string', 'children': [], 'value': "''"},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'assignment', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '105', 'type': 'call', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'sub'},{'id': '109', 'type': 'argument_list', 'children': ['110', '111', '112']},{'id': '110', 'type': 'string', 'children': [], 'value': "'^\\.\\.\\. '"},{'id': '111', 'type': 'string', 'children': [], 'value': "''"},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'assignment', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '116', 'type': 'binary_operator', 'children': ['117', '130'], 'value': '+'},{'id': '117', 'type': 'binary_operator', 'children': ['118', '122'], 'value': '-'},{'id': '118', 'type': 'call', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '120', 'type': 'argument_list', 'children': ['121']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '122', 'type': 'call', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'call', 'children': ['126', '129']},{'id': '126', 'type': 'attribute', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'lstrip'},{'id': '129', 'type': 'argument_list', 'children': []},{'id': '130', 'type': 'integer', 'children': [], 'value': '4'},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'call', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'insertPlainText'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'binary_operator', 'children': ['138', '139'], 'value': '+'},{'id': '138', 'type': 'string', 'children': [], 'value': "'\\n... '"},{'id': '139', 'type': 'binary_operator', 'children': ['140', '141'], 'value': '*'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '141', 'type': 'string', 'children': [], 'value': "' '"},{'id': '142', 'type': 'return_statement', 'children': ['143']},{'id': '143', 'type': 'False', 'children': []},{'id': '144', 'type': 'elif_clause', 'children': ['145', '166']},{'id': '145', 'type': 'boolean_operator', 'children': ['146', '154', '155'], 'value': 'and'},{'id': '146', 'type': 'boolean_operator', 'children': ['147', '148'], 'value': 'and'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'mod_mode'},{'id': '148', 'type': 'call', 'children': ['149', '152']},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '152', 'type': 'argument_list', 'children': ['153']},{'id': '153', 'type': 'string', 'children': [], 'value': "'...'"},{'id': '154', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '155', 'type': '()', 'children': ['156']},{'id': '156', 'type': 'boolean_operator', 'children': ['157', '164'], 'value': 'or'},{'id': '157', 'type': 'comparison_operator', 'children': ['158', '163'], 'value': '!='},{'id': '158', 'type': 'call', 'children': ['159', '162']},{'id': '159', 'type': 'attribute', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '162', 'type': 'argument_list', 'children': []},{'id': '163', 'type': 'string', 'children': [], 'value': "'...'"},{'id': '164', 'type': 'not_operator', 'children': ['165']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'at_end'},{'id': '166', 'type': 'block', 'children': ['167', '176', '187', '203', '214']},{'id': '167', 'type': 'expression_statement', 'children': ['168']},{'id': '168', 'type': 'call', 'children': ['169', '172']},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'movePosition'},{'id': '172', 'type': 'argument_list', 'children': ['173']},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'EndOfLine'},{'id': '176', 'type': 'expression_statement', 'children': ['177']},{'id': '177', 'type': 'assignment', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '179', 'type': 'call', 'children': ['180', '183']},{'id': '180', 'type': 'attribute', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'sub'},{'id': '183', 'type': 'argument_list', 'children': ['184', '185', '186']},{'id': '184', 'type': 'string', 'children': [], 'value': "'^\\.\\.\\. '"},{'id': '185', 'type': 'string', 'children': [], 'value': "''"},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '187', 'type': 'expression_statement', 'children': ['188']},{'id': '188', 'type': 'assignment', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '190', 'type': 'binary_operator', 'children': ['191', '195'], 'value': '-'},{'id': '191', 'type': 'call', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '193', 'type': 'argument_list', 'children': ['194']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '195', 'type': 'call', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '197', 'type': 'argument_list', 'children': ['198']},{'id': '198', 'type': 'call', 'children': ['199', '202']},{'id': '199', 'type': 'attribute', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'lstrip'},{'id': '202', 'type': 'argument_list', 'children': []},{'id': '203', 'type': 'expression_statement', 'children': ['204']},{'id': '204', 'type': 'call', 'children': ['205', '208']},{'id': '205', 'type': 'attribute', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'insertPlainText'},{'id': '208', 'type': 'argument_list', 'children': ['209']},{'id': '209', 'type': 'binary_operator', 'children': ['210', '211'], 'value': '+'},{'id': '210', 'type': 'string', 'children': [], 'value': "'\\n... '"},{'id': '211', 'type': 'binary_operator', 'children': ['212', '213'], 'value': '*'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '213', 'type': 'string', 'children': [], 'value': "' '"},{'id': '214', 'type': 'return_statement', 'children': ['215']},{'id': '215', 'type': 'False', 'children': []},{'id': '216', 'type': 'elif_clause', 'children': ['217', '230']},{'id': '217', 'type': 'boolean_operator', 'children': ['218', '224'], 'value': 'or'},{'id': '218', 'type': 'call', 'children': ['219', '222']},{'id': '219', 'type': 'attribute', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '222', 'type': 'argument_list', 'children': ['223']},{'id': '223', 'type': 'string', 'children': [], 'value': "'>>>'"},{'id': '224', 'type': 'call', 'children': ['225', '228']},{'id': '225', 'type': 'attribute', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '228', 'type': 'argument_list', 'children': ['229']},{'id': '229', 'type': 'string', 'children': [], 'value': "'...'"},{'id': '230', 'type': 'block', 'children': ['231', '250', '286', '295', '314', '318', '322', '391', '400']},{'id': '231', 'type': 'expression_statement', 'children': ['232']},{'id': '232', 'type': 'assignment', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '234', 'type': 'call', 'children': ['235', '240']},{'id': '235', 'type': 'attribute', 'children': ['236', '239']},{'id': '236', 'type': 'attribute', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'projex'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'nativestring'},{'id': '240', 'type': 'argument_list', 'children': ['241']},{'id': '241', 'type': 'call', 'children': ['242', '249']},{'id': '242', 'type': 'attribute', 'children': ['243', '248']},{'id': '243', 'type': 'call', 'children': ['244', '247']},{'id': '244', 'type': 'attribute', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'block'},{'id': '247', 'type': 'argument_list', 'children': []},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '249', 'type': 'argument_list', 'children': []},{'id': '250', 'type': 'while_statement', 'children': ['251', '257']},{'id': '251', 'type': 'call', 'children': ['252', '255']},{'id': '252', 'type': 'attribute', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '255', 'type': 'argument_list', 'children': ['256']},{'id': '256', 'type': 'string', 'children': [], 'value': "'...'"},{'id': '257', 'type': 'block', 'children': ['258', '267']},{'id': '258', 'type': 'expression_statement', 'children': ['259']},{'id': '259', 'type': 'call', 'children': ['260', '263']},{'id': '260', 'type': 'attribute', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'movePosition'},{'id': '263', 'type': 'argument_list', 'children': ['264']},{'id': '264', 'type': 'attribute', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'PreviousBlock'},{'id': '267', 'type': 'expression_statement', 'children': ['268']},{'id': '268', 'type': 'assignment', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '270', 'type': 'call', 'children': ['271', '276']},{'id': '271', 'type': 'attribute', 'children': ['272', '275']},{'id': '272', 'type': 'attribute', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'projex'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'nativestring'},{'id': '276', 'type': 'argument_list', 'children': ['277']},{'id': '277', 'type': 'call', 'children': ['278', '285']},{'id': '278', 'type': 'attribute', 'children': ['279', '284']},{'id': '279', 'type': 'call', 'children': ['280', '283']},{'id': '280', 'type': 'attribute', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'block'},{'id': '283', 'type': 'argument_list', 'children': []},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '285', 'type': 'argument_list', 'children': []},{'id': '286', 'type': 'expression_statement', 'children': ['287']},{'id': '287', 'type': 'call', 'children': ['288', '291']},{'id': '288', 'type': 'attribute', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'movePosition'},{'id': '291', 'type': 'argument_list', 'children': ['292']},{'id': '292', 'type': 'attribute', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'EndOfLine'},{'id': '295', 'type': 'expression_statement', 'children': ['296']},{'id': '296', 'type': 'assignment', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '298', 'type': 'call', 'children': ['299', '304']},{'id': '299', 'type': 'attribute', 'children': ['300', '303']},{'id': '300', 'type': 'attribute', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'projex'},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'nativestring'},{'id': '304', 'type': 'argument_list', 'children': ['305']},{'id': '305', 'type': 'call', 'children': ['306', '313']},{'id': '306', 'type': 'attribute', 'children': ['307', '312']},{'id': '307', 'type': 'call', 'children': ['308', '311']},{'id': '308', 'type': 'attribute', 'children': ['309', '310']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'block'},{'id': '311', 'type': 'argument_list', 'children': []},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '313', 'type': 'argument_list', 'children': []},{'id': '314', 'type': 'expression_statement', 'children': ['315']},{'id': '315', 'type': 'assignment', 'children': ['316', '317']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'ended'},{'id': '317', 'type': 'False', 'children': []},{'id': '318', 'type': 'expression_statement', 'children': ['319']},{'id': '319', 'type': 'assignment', 'children': ['320', '321']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '321', 'type': 'list', 'children': [], 'value': '[]'},{'id': '322', 'type': 'while_statement', 'children': ['323', '324']},{'id': '323', 'type': 'True', 'children': []},{'id': '324', 'type': 'block', 'children': ['325', '332', '344', '353', '362', '381']},{'id': '325', 'type': 'expression_statement', 'children': ['326']},{'id': '326', 'type': 'call', 'children': ['327', '330']},{'id': '327', 'type': 'attribute', 'children': ['328', '329']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '330', 'type': 'argument_list', 'children': ['331']},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '332', 'type': 'if_statement', 'children': ['333', '338']},{'id': '333', 'type': 'call', 'children': ['334', '337']},{'id': '334', 'type': 'attribute', 'children': ['335', '336']},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'atEnd'},{'id': '337', 'type': 'argument_list', 'children': []},{'id': '338', 'type': 'block', 'children': ['339', '343']},{'id': '339', 'type': 'expression_statement', 'children': ['340']},{'id': '340', 'type': 'assignment', 'children': ['341', '342']},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'ended'},{'id': '342', 'type': 'True', 'children': []},{'id': '343', 'type': 'break_statement', 'children': []},{'id': '344', 'type': 'expression_statement', 'children': ['345']},{'id': '345', 'type': 'call', 'children': ['346', '349']},{'id': '346', 'type': 'attribute', 'children': ['347', '348']},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'movePosition'},{'id': '349', 'type': 'argument_list', 'children': ['350']},{'id': '350', 'type': 'attribute', 'children': ['351', '352']},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'NextBlock'},{'id': '353', 'type': 'expression_statement', 'children': ['354']},{'id': '354', 'type': 'call', 'children': ['355', '358']},{'id': '355', 'type': 'attribute', 'children': ['356', '357']},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'movePosition'},{'id': '358', 'type': 'argument_list', 'children': ['359']},{'id': '359', 'type': 'attribute', 'children': ['360', '361']},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'EndOfLine'},{'id': '362', 'type': 'expression_statement', 'children': ['363']},{'id': '363', 'type': 'assignment', 'children': ['364', '365']},{'id': '364', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '365', 'type': 'call', 'children': ['366', '371']},{'id': '366', 'type': 'attribute', 'children': ['367', '370']},{'id': '367', 'type': 'attribute', 'children': ['368', '369']},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'projex'},{'id': '369', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '370', 'type': 'identifier', 'children': [], 'value': 'nativestring'},{'id': '371', 'type': 'argument_list', 'children': ['372']},{'id': '372', 'type': 'call', 'children': ['373', '380']},{'id': '373', 'type': 'attribute', 'children': ['374', '379']},{'id': '374', 'type': 'call', 'children': ['375', '378']},{'id': '375', 'type': 'attribute', 'children': ['376', '377']},{'id': '376', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '377', 'type': 'identifier', 'children': [], 'value': 'block'},{'id': '378', 'type': 'argument_list', 'children': []},{'id': '379', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '380', 'type': 'argument_list', 'children': []},{'id': '381', 'type': 'if_statement', 'children': ['382', '389']},{'id': '382', 'type': 'not_operator', 'children': ['383']},{'id': '383', 'type': 'call', 'children': ['384', '387']},{'id': '384', 'type': 'attribute', 'children': ['385', '386']},{'id': '385', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '386', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '387', 'type': 'argument_list', 'children': ['388']},{'id': '388', 'type': 'string', 'children': [], 'value': "'...'"},{'id': '389', 'type': 'block', 'children': ['390']},{'id': '390', 'type': 'break_statement', 'children': []},{'id': '391', 'type': 'expression_statement', 'children': ['392']},{'id': '392', 'type': 'assignment', 'children': ['393', '394']},{'id': '393', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '394', 'type': 'call', 'children': ['395', '398']},{'id': '395', 'type': 'attribute', 'children': ['396', '397']},{'id': '396', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '397', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '398', 'type': 'argument_list', 'children': ['399']},{'id': '399', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '400', 'type': 'if_statement', 'children': ['401', '406']},{'id': '401', 'type': 'not_operator', 'children': ['402']},{'id': '402', 'type': '()', 'children': ['403']},{'id': '403', 'type': 'boolean_operator', 'children': ['404', '405'], 'value': 'and'},{'id': '404', 'type': 'identifier', 'children': [], 'value': 'ended'},{'id': '405', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '406', 'type': 'block', 'children': ['407', '413', '426', '435']},{'id': '407', 'type': 'expression_statement', 'children': ['408']},{'id': '408', 'type': 'call', 'children': ['409', '412']},{'id': '409', 'type': 'attribute', 'children': ['410', '411']},{'id': '410', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '411', 'type': 'identifier', 'children': [], 'value': 'waitForInput'},{'id': '412', 'type': 'argument_list', 'children': []},{'id': '413', 'type': 'expression_statement', 'children': ['414']},{'id': '414', 'type': 'call', 'children': ['415', '418']},{'id': '415', 'type': 'attribute', 'children': ['416', '417']},{'id': '416', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '417', 'type': 'identifier', 'children': [], 'value': 'insertPlainText'},{'id': '418', 'type': 'argument_list', 'children': ['419']},{'id': '419', 'type': 'call', 'children': ['420', '423']},{'id': '420', 'type': 'attribute', 'children': ['421', '422']},{'id': '421', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '422', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '423', 'type': 'argument_list', 'children': ['424', '425']},{'id': '424', 'type': 'string', 'children': [], 'value': "'>>> '"},{'id': '425', 'type': 'string', 'children': [], 'value': "''"},{'id': '426', 'type': 'expression_statement', 'children': ['427']},{'id': '427', 'type': 'call', 'children': ['428', '431']},{'id': '428', 'type': 'attribute', 'children': ['429', '430']},{'id': '429', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '430', 'type': 'identifier', 'children': [], 'value': 'movePosition'},{'id': '431', 'type': 'argument_list', 'children': ['432']},{'id': '432', 'type': 'attribute', 'children': ['433', '434']},{'id': '433', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '434', 'type': 'identifier', 'children': [], 'value': 'End'},{'id': '435', 'type': 'return_statement', 'children': ['436']},{'id': '436', 'type': 'False', 'children': []},{'id': '437', 'type': 'else_clause', 'children': ['438']},{'id': '438', 'type': 'block', 'children': ['439', '445']},{'id': '439', 'type': 'expression_statement', 'children': ['440']},{'id': '440', 'type': 'call', 'children': ['441', '444']},{'id': '441', 'type': 'attribute', 'children': ['442', '443']},{'id': '442', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '443', 'type': 'identifier', 'children': [], 'value': 'waitForInput'},{'id': '444', 'type': 'argument_list', 'children': []},{'id': '445', 'type': 'return_statement', 'children': ['446']},{'id': '446', 'type': 'False', 'children': []},{'id': '447', 'type': 'expression_statement', 'children': ['448']},{'id': '448', 'type': 'call', 'children': ['449', '452']},{'id': '449', 'type': 'attribute', 'children': ['450', '451']},{'id': '450', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '451', 'type': 'identifier', 'children': [], 'value': 'executeCommand'},{'id': '452', 'type': 'argument_list', 'children': ['453']},{'id': '453', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '454', 'type': 'return_statement', 'children': ['455']},{'id': '455', 'type': 'True', 'children': []}
def applyCommand(self): 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 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 elif line.startswith('>>>') or line.startswith('...'): line = projex.text.nativestring(cursor.block().text()) while line.startswith('...'): cursor.movePosition(cursor.PreviousBlock) line = projex.text.nativestring(cursor.block().text()) cursor.movePosition(cursor.EndOfLine) line = projex.text.nativestring(cursor.block().text()) ended = False lines = [] while True: lines.append(line) if cursor.atEnd(): ended = True break cursor.movePosition(cursor.NextBlock) cursor.movePosition(cursor.EndOfLine) line = projex.text.nativestring(cursor.block().text()) if not line.startswith('...'): break command = '\n'.join(lines) 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
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'pager'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '6', 'type': 'block', 'children': ['7']},{'id': '7', 'type': 'try_statement', 'children': ['8', '244']},{'id': '8', 'type': 'block', 'children': ['9', '13', '35', '50', '54', '231']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'line_count'},{'id': '12', 'type': 'integer', 'children': [], 'value': '0'},{'id': '13', 'type': 'if_statement', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '16', 'type': 'identifier', 'children': [], 'value': '_output_filename'},{'id': '17', 'type': 'block', 'children': ['18', '23']},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'string', 'children': [], 'value': 'f"Output is also going to \'{self.output_file}\'"'},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '27', 'type': 'identifier', 'children': [], 'value': '_output_file'},{'id': '28', 'type': 'call', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '30', 'type': 'argument_list', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '33', 'type': 'identifier', 'children': [], 'value': '_output_filename'},{'id': '34', 'type': 'string', 'children': [], 'value': '"a+"'},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '40']},{'id': '37', 'type': 'pattern_list', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'terminal_columns'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'terminal_lines'},{'id': '40', 'type': 'call', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'shutil'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'get_terminal_size'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'keyword_argument', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'fallback'},{'id': '47', 'type': 'tuple', 'children': ['48', '49']},{'id': '48', 'type': 'integer', 'children': [], 'value': '80'},{'id': '49', 'type': 'integer', 'children': [], 'value': '24'},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'lines_left'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'terminal_lines'},{'id': '54', 'type': 'for_statement', 'children': ['55', '58', '63']},{'id': '55', 'type': 'pattern_list', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '58', 'type': 'call', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '60', 'type': 'argument_list', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '62', 'type': 'integer', 'children': [], 'value': '1'},{'id': '63', 'type': 'block', 'children': ['64', '68', '83', '95', '107', '126', '137', '142', '164']},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'line_residue'},{'id': '67', 'type': 'integer', 'children': [], 'value': '0'},{'id': '68', 'type': 'if_statement', 'children': ['69', '72', '77']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'line_numbers'},{'id': '72', 'type': 'block', 'children': ['73']},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'output_line'},{'id': '76', 'type': 'string', 'children': [], 'value': 'f"{i:<4} {l}"'},{'id': '77', 'type': 'else_clause', 'children': ['78']},{'id': '78', 'type': 'block', 'children': ['79']},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'output_line'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'line_overflow'},{'id': '86', 'type': 'call', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'binary_operator', 'children': ['90', '94'], 'value': '/'},{'id': '90', 'type': 'call', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'output_line'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'terminal_columns'},{'id': '95', 'type': 'if_statement', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'line_overflow'},{'id': '97', 'type': 'block', 'children': ['98']},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'line_residue'},{'id': '101', 'type': 'binary_operator', 'children': ['102', '106'], 'value': '%'},{'id': '102', 'type': 'call', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '104', 'type': 'argument_list', 'children': ['105']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'output_line'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'terminal_columns'},{'id': '107', 'type': 'if_statement', 'children': ['108', '111', '118']},{'id': '108', 'type': 'comparison_operator', 'children': ['109', '110'], 'value': '>='},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'line_overflow'},{'id': '110', 'type': 'integer', 'children': [], 'value': '1'},{'id': '111', 'type': 'block', 'children': ['112']},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'assignment', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'lines_left'},{'id': '115', 'type': 'binary_operator', 'children': ['116', '117'], 'value': '-'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'lines_left'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'line_overflow'},{'id': '118', 'type': 'else_clause', 'children': ['119']},{'id': '119', 'type': 'block', 'children': ['120']},{'id': '120', 'type': 'expression_statement', 'children': ['121']},{'id': '121', 'type': 'assignment', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'lines_left'},{'id': '123', 'type': 'binary_operator', 'children': ['124', '125'], 'value': '-'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'lines_left'},{'id': '125', 'type': 'integer', 'children': [], 'value': '1'},{'id': '126', 'type': 'if_statement', 'children': ['127', '130']},{'id': '127', 'type': 'comparison_operator', 'children': ['128', '129'], 'value': '>'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'line_residue'},{'id': '129', 'type': 'integer', 'children': [], 'value': '1'},{'id': '130', 'type': 'block', 'children': ['131']},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'assignment', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'lines_left'},{'id': '134', 'type': 'binary_operator', 'children': ['135', '136'], 'value': '-'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'lines_left'},{'id': '136', 'type': 'integer', 'children': [], 'value': '1'},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'call', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'output_line'},{'id': '142', 'type': 'if_statement', 'children': ['143', '146']},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '145', 'type': 'identifier', 'children': [], 'value': '_output_file'},{'id': '146', 'type': 'block', 'children': ['147', '156']},{'id': '147', 'type': 'expression_statement', 'children': ['148']},{'id': '148', 'type': 'call', 'children': ['149', '154']},{'id': '149', 'type': 'attribute', 'children': ['150', '153']},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '152', 'type': 'identifier', 'children': [], 'value': '_output_file'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '154', 'type': 'argument_list', 'children': ['155']},{'id': '155', 'type': 'string', 'children': [], 'value': 'f"{l}\\n"'},{'id': '156', 'type': 'expression_statement', 'children': ['157']},{'id': '157', 'type': 'call', 'children': ['158', '163']},{'id': '158', 'type': 'attribute', 'children': ['159', '162']},{'id': '159', 'type': 'attribute', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '161', 'type': 'identifier', 'children': [], 'value': '_output_file'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'flush'},{'id': '163', 'type': 'argument_list', 'children': []},{'id': '164', 'type': 'if_statement', 'children': ['165', '175']},{'id': '165', 'type': 'comparison_operator', 'children': ['166', '174'], 'value': '<='},{'id': '166', 'type': '()', 'children': ['167']},{'id': '167', 'type': 'binary_operator', 'children': ['168', '173'], 'value': '-'},{'id': '168', 'type': 'binary_operator', 'children': ['169', '170'], 'value': '-'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'lines_left'},{'id': '170', 'type': 'attribute', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'overlap'},{'id': '173', 'type': 'integer', 'children': [], 'value': '1'},{'id': '174', 'type': 'integer', 'children': [], 'value': '0'},{'id': '175', 'type': 'block', 'children': ['176']},{'id': '176', 'type': 'if_statement', 'children': ['177', '180']},{'id': '177', 'type': 'attribute', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'paginate'},{'id': '180', 'type': 'block', 'children': ['181', '189', '195', '212', '227']},{'id': '181', 'type': 'expression_statement', 'children': ['182']},{'id': '182', 'type': 'call', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '184', 'type': 'argument_list', 'children': ['185', '186']},{'id': '185', 'type': 'string', 'children': [], 'value': '"Hit Return to continue (q or quit to exit)"'},{'id': '186', 'type': 'keyword_argument', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '188', 'type': 'string', 'children': [], 'value': '""'},{'id': '189', 'type': 'expression_statement', 'children': ['190']},{'id': '190', 'type': 'assignment', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'user_input'},{'id': '192', 'type': 'call', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'input'},{'id': '194', 'type': 'argument_list', 'children': []},{'id': '195', 'type': 'if_statement', 'children': ['196', '210']},{'id': '196', 'type': 'comparison_operator', 'children': ['197', '206'], 'value': 'in'},{'id': '197', 'type': 'call', 'children': ['198', '205']},{'id': '198', 'type': 'attribute', 'children': ['199', '204']},{'id': '199', 'type': 'call', 'children': ['200', '203']},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'user_input'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '203', 'type': 'argument_list', 'children': []},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '205', 'type': 'argument_list', 'children': []},{'id': '206', 'type': 'list', 'children': ['207', '208', '209'], 'value': '["q", "quit", "exit"]'},{'id': '207', 'type': 'string', 'children': [], 'value': '"q"'},{'id': '208', 'type': 'string', 'children': [], 'value': '"quit"'},{'id': '209', 'type': 'string', 'children': [], 'value': '"exit"'},{'id': '210', 'type': 'block', 'children': ['211']},{'id': '211', 'type': 'break_statement', 'children': []},{'id': '212', 'type': 'expression_statement', 'children': ['213']},{'id': '213', 'type': 'assignment', 'children': ['214', '217']},{'id': '214', 'type': 'pattern_list', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'terminal_columns'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'terminal_lines'},{'id': '217', 'type': 'call', 'children': ['218', '221']},{'id': '218', 'type': 'attribute', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'shutil'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'get_terminal_size'},{'id': '221', 'type': 'argument_list', 'children': ['222']},{'id': '222', 'type': 'keyword_argument', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'fallback'},{'id': '224', 'type': 'tuple', 'children': ['225', '226']},{'id': '225', 'type': 'integer', 'children': [], 'value': '80'},{'id': '226', 'type': 'integer', 'children': [], 'value': '24'},{'id': '227', 'type': 'expression_statement', 'children': ['228']},{'id': '228', 'type': 'assignment', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'lines_left'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'terminal_lines'},{'id': '231', 'type': 'if_statement', 'children': ['232', '235']},{'id': '232', 'type': 'attribute', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '234', 'type': 'identifier', 'children': [], 'value': '_output_file'},{'id': '235', 'type': 'block', 'children': ['236']},{'id': '236', 'type': 'expression_statement', 'children': ['237']},{'id': '237', 'type': 'call', 'children': ['238', '243']},{'id': '238', 'type': 'attribute', 'children': ['239', '242']},{'id': '239', 'type': 'attribute', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '241', 'type': 'identifier', 'children': [], 'value': '_output_file'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '243', 'type': 'argument_list', 'children': []},{'id': '244', 'type': 'except_clause', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'KeyboardInterrupt'},{'id': '246', 'type': 'block', 'children': ['247', '252']},{'id': '247', 'type': 'expression_statement', 'children': ['248']},{'id': '248', 'type': 'call', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '250', 'type': 'argument_list', 'children': ['251']},{'id': '251', 'type': 'string', 'children': [], 'value': '"ctrl-C..."'},{'id': '252', 'type': 'if_statement', 'children': ['253', '256']},{'id': '253', 'type': 'attribute', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '255', 'type': 'identifier', 'children': [], 'value': '_output_file'},{'id': '256', 'type': 'block', 'children': ['257']},{'id': '257', 'type': 'expression_statement', 'children': ['258']},{'id': '258', 'type': 'call', 'children': ['259', '264']},{'id': '259', 'type': 'attribute', 'children': ['260', '263']},{'id': '260', 'type': 'attribute', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '262', 'type': 'identifier', 'children': [], 'value': '_output_file'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '264', 'type': 'argument_list', 'children': []}
def pager(self, lines): 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 print(output_line) if self._output_file: self._output_file.write(f"{l}\n") self._output_file.flush() if (lines_left - self.overlap - 1) <= 0: 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 if self._output_file: self._output_file.close() except KeyboardInterrupt: print("ctrl-C...") if self._output_file: self._output_file.close()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'merge'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'constraints'},{'id': '5', 'type': 'block', 'children': ['6', '13', '30', '53', '76', '98', '120', '124', '201', '205', '282', '365', '379', '393']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'operators'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'defaultdict'},{'id': '11', 'type': 'argument_list', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '13', 'type': 'for_statement', 'children': ['14', '15', '16']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'constraint'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'constraints'},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'call', 'children': ['19', '26']},{'id': '19', 'type': 'attribute', 'children': ['20', '25']},{'id': '20', 'type': 'subscript', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'operators'},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'constraint'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'operator'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'constraint'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '30', 'type': 'if_statement', 'children': ['31', '34', '47']},{'id': '31', 'type': 'comparison_operator', 'children': ['32', '33'], 'value': 'in'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'gt'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'operators'},{'id': '34', 'type': 'block', 'children': ['35']},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'gt_ver'},{'id': '38', 'type': 'subscript', 'children': ['39', '45']},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'subscript', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'operators'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'gt'},{'id': '45', 'type': 'unary_operator', 'children': ['46'], 'value': '-'},{'id': '46', 'type': 'integer', 'children': [], 'value': '1'},{'id': '47', 'type': 'else_clause', 'children': ['48']},{'id': '48', 'type': 'block', 'children': ['49']},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'gt_ver'},{'id': '52', 'type': 'None', 'children': []},{'id': '53', 'type': 'if_statement', 'children': ['54', '57', '70']},{'id': '54', 'type': 'comparison_operator', 'children': ['55', '56'], 'value': 'in'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'ge'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'operators'},{'id': '57', 'type': 'block', 'children': ['58']},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'ge_ver'},{'id': '61', 'type': 'subscript', 'children': ['62', '68']},{'id': '62', 'type': 'call', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'subscript', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'operators'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'ge'},{'id': '68', 'type': 'unary_operator', 'children': ['69'], 'value': '-'},{'id': '69', 'type': 'integer', 'children': [], 'value': '1'},{'id': '70', 'type': 'else_clause', 'children': ['71']},{'id': '71', 'type': 'block', 'children': ['72']},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'ge_ver'},{'id': '75', 'type': 'None', 'children': []},{'id': '76', 'type': 'if_statement', 'children': ['77', '80', '92']},{'id': '77', 'type': 'comparison_operator', 'children': ['78', '79'], 'value': 'in'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'lt'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'operators'},{'id': '80', 'type': 'block', 'children': ['81']},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'lt_ver'},{'id': '84', 'type': 'subscript', 'children': ['85', '91']},{'id': '85', 'type': 'call', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'subscript', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'operators'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'lt'},{'id': '91', 'type': 'integer', 'children': [], 'value': '0'},{'id': '92', 'type': 'else_clause', 'children': ['93']},{'id': '93', 'type': 'block', 'children': ['94']},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'assignment', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'lt_ver'},{'id': '97', 'type': 'None', 'children': []},{'id': '98', 'type': 'if_statement', 'children': ['99', '102', '114']},{'id': '99', 'type': 'comparison_operator', 'children': ['100', '101'], 'value': 'in'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'le'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'operators'},{'id': '102', 'type': 'block', 'children': ['103']},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'le_ver'},{'id': '106', 'type': 'subscript', 'children': ['107', '113']},{'id': '107', 'type': 'call', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'subscript', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'operators'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'le'},{'id': '113', 'type': 'integer', 'children': [], 'value': '0'},{'id': '114', 'type': 'else_clause', 'children': ['115']},{'id': '115', 'type': 'block', 'children': ['116']},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'assignment', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'le_ver'},{'id': '119', 'type': 'None', 'children': []},{'id': '120', 'type': 'expression_statement', 'children': ['121']},{'id': '121', 'type': 'assignment', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'l_constraint'},{'id': '123', 'type': 'None', 'children': []},{'id': '124', 'type': 'if_statement', 'children': ['125', '126', '190']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'le_ver'},{'id': '126', 'type': 'block', 'children': ['127']},{'id': '127', 'type': 'if_statement', 'children': ['128', '129', '180']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'lt_ver'},{'id': '129', 'type': 'block', 'children': ['130', '138', '146', '169']},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'assignment', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'le_constraint'},{'id': '133', 'type': 'call', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'Constraint'},{'id': '135', 'type': 'argument_list', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'le'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'le_ver'},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'assignment', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'lt_constraint'},{'id': '141', 'type': 'call', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'Constraint'},{'id': '143', 'type': 'argument_list', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'lt'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'lt_ver'},{'id': '146', 'type': 'if_statement', 'children': ['147', '150', '159']},{'id': '147', 'type': 'comparison_operator', 'children': ['148', '149'], 'value': '<'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'le_ver'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'lt_ver'},{'id': '150', 'type': 'block', 'children': ['151', '155']},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'assignment', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'l_constraint'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'le_constraint'},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'assignment', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'l_less_restrictive_c'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'lt_constraint'},{'id': '159', 'type': 'else_clause', 'children': ['160']},{'id': '160', 'type': 'block', 'children': ['161', '165']},{'id': '161', 'type': 'expression_statement', 'children': ['162']},{'id': '162', 'type': 'assignment', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'l_constraint'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'lt_constraint'},{'id': '165', 'type': 'expression_statement', 'children': ['166']},{'id': '166', 'type': 'assignment', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'l_less_restrictive_c'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'le_constraint'},{'id': '169', 'type': 'expression_statement', 'children': ['170']},{'id': '170', 'type': 'call', 'children': ['171', '174']},{'id': '171', 'type': 'attribute', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'LOGGER'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '174', 'type': 'argument_list', 'children': ['175', '178', '179']},{'id': '175', 'type': 'concatenated_string', 'children': ['176', '177']},{'id': '176', 'type': 'string', 'children': [], 'value': "'Removed constraint %s because it is less '"},{'id': '177', 'type': 'string', 'children': [], 'value': "'restrictive than %s'"},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'l_less_restrictive_c'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'l_constraint'},{'id': '180', 'type': 'else_clause', 'children': ['181']},{'id': '181', 'type': 'block', 'children': ['182']},{'id': '182', 'type': 'expression_statement', 'children': ['183']},{'id': '183', 'type': 'assignment', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'l_constraint'},{'id': '185', 'type': 'call', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'Constraint'},{'id': '187', 'type': 'argument_list', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'le'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'le_ver'},{'id': '190', 'type': 'elif_clause', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'lt_ver'},{'id': '192', 'type': 'block', 'children': ['193']},{'id': '193', 'type': 'expression_statement', 'children': ['194']},{'id': '194', 'type': 'assignment', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'l_constraint'},{'id': '196', 'type': 'call', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'Constraint'},{'id': '198', 'type': 'argument_list', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'lt'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'lt_ver'},{'id': '201', 'type': 'expression_statement', 'children': ['202']},{'id': '202', 'type': 'assignment', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'g_constraint'},{'id': '204', 'type': 'None', 'children': []},{'id': '205', 'type': 'if_statement', 'children': ['206', '207', '271']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'ge_ver'},{'id': '207', 'type': 'block', 'children': ['208']},{'id': '208', 'type': 'if_statement', 'children': ['209', '210', '261']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'gt_ver'},{'id': '210', 'type': 'block', 'children': ['211', '219', '227', '250']},{'id': '211', 'type': 'expression_statement', 'children': ['212']},{'id': '212', 'type': 'assignment', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'gt_constraint'},{'id': '214', 'type': 'call', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'Constraint'},{'id': '216', 'type': 'argument_list', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'gt'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'gt_ver'},{'id': '219', 'type': 'expression_statement', 'children': ['220']},{'id': '220', 'type': 'assignment', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'ge_constraint'},{'id': '222', 'type': 'call', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'Constraint'},{'id': '224', 'type': 'argument_list', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'ge'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'ge_ver'},{'id': '227', 'type': 'if_statement', 'children': ['228', '231', '240']},{'id': '228', 'type': 'comparison_operator', 'children': ['229', '230'], 'value': '<='},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'ge_ver'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'gt_ver'},{'id': '231', 'type': 'block', 'children': ['232', '236']},{'id': '232', 'type': 'expression_statement', 'children': ['233']},{'id': '233', 'type': 'assignment', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'g_constraint'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'gt_constraint'},{'id': '236', 'type': 'expression_statement', 'children': ['237']},{'id': '237', 'type': 'assignment', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'g_less_restrictive_c'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'ge_constraint'},{'id': '240', 'type': 'else_clause', 'children': ['241']},{'id': '241', 'type': 'block', 'children': ['242', '246']},{'id': '242', 'type': 'expression_statement', 'children': ['243']},{'id': '243', 'type': 'assignment', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'g_constraint'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'ge_constraint'},{'id': '246', 'type': 'expression_statement', 'children': ['247']},{'id': '247', 'type': 'assignment', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'g_less_restrictive_c'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'gt_constraint'},{'id': '250', 'type': 'expression_statement', 'children': ['251']},{'id': '251', 'type': 'call', 'children': ['252', '255']},{'id': '252', 'type': 'attribute', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'LOGGER'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '255', 'type': 'argument_list', 'children': ['256', '259', '260']},{'id': '256', 'type': 'concatenated_string', 'children': ['257', '258']},{'id': '257', 'type': 'string', 'children': [], 'value': "'Removed constraint %s because it is less '"},{'id': '258', 'type': 'string', 'children': [], 'value': "'restrictive than %s'"},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'g_less_restrictive_c'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'g_constraint'},{'id': '261', 'type': 'else_clause', 'children': ['262']},{'id': '262', 'type': 'block', 'children': ['263']},{'id': '263', 'type': 'expression_statement', 'children': ['264']},{'id': '264', 'type': 'assignment', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'g_constraint'},{'id': '266', 'type': 'call', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'Constraint'},{'id': '268', 'type': 'argument_list', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'ge'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'ge_ver'},{'id': '271', 'type': 'elif_clause', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'gt_ver'},{'id': '273', 'type': 'block', 'children': ['274']},{'id': '274', 'type': 'expression_statement', 'children': ['275']},{'id': '275', 'type': 'assignment', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'g_constraint'},{'id': '277', 'type': 'call', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'Constraint'},{'id': '279', 'type': 'argument_list', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'gt'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'gt_ver'},{'id': '282', 'type': 'if_statement', 'children': ['283', '286']},{'id': '283', 'type': 'boolean_operator', 'children': ['284', '285'], 'value': 'and'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'g_constraint'},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'l_constraint'},{'id': '286', 'type': 'block', 'children': ['287']},{'id': '287', 'type': 'if_statement', 'children': ['288', '295', '349']},{'id': '288', 'type': 'comparison_operator', 'children': ['289', '292'], 'value': '=='},{'id': '289', 'type': 'attribute', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'g_constraint'},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '292', 'type': 'attribute', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'l_constraint'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '295', 'type': 'block', 'children': ['296']},{'id': '296', 'type': 'if_statement', 'children': ['297', '308', '340']},{'id': '297', 'type': 'boolean_operator', 'children': ['298', '303'], 'value': 'and'},{'id': '298', 'type': 'comparison_operator', 'children': ['299', '302'], 'value': '=='},{'id': '299', 'type': 'attribute', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'g_constraint'},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'operator'},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'ge'},{'id': '303', 'type': 'comparison_operator', 'children': ['304', '307'], 'value': '=='},{'id': '304', 'type': 'attribute', 'children': ['305', '306']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'l_constraint'},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'operator'},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'le'},{'id': '308', 'type': 'block', 'children': ['309', '320', '332']},{'id': '309', 'type': 'expression_statement', 'children': ['310']},{'id': '310', 'type': 'call', 'children': ['311', '316']},{'id': '311', 'type': 'attribute', 'children': ['312', '315']},{'id': '312', 'type': 'subscript', 'children': ['313', '314']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'operators'},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'eq'},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '316', 'type': 'argument_list', 'children': ['317']},{'id': '317', 'type': 'attribute', 'children': ['318', '319']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'g_constraint'},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '320', 'type': 'expression_statement', 'children': ['321']},{'id': '321', 'type': 'call', 'children': ['322', '325']},{'id': '322', 'type': 'attribute', 'children': ['323', '324']},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'LOGGER'},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '325', 'type': 'argument_list', 'children': ['326', '327', '328', '329']},{'id': '326', 'type': 'string', 'children': [], 'value': "'Merged constraints: %s and %s into ==%s'"},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'l_constraint'},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'g_constraint'},{'id': '329', 'type': 'attribute', 'children': ['330', '331']},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'g_constraint'},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '332', 'type': 'expression_statement', 'children': ['333']},{'id': '333', 'type': 'assignment', 'children': ['334', '337']},{'id': '334', 'type': 'pattern_list', 'children': ['335', '336']},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'l_constraint'},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'g_constraint'},{'id': '337', 'type': 'expression_list', 'children': ['338', '339']},{'id': '338', 'type': 'None', 'children': []},{'id': '339', 'type': 'None', 'children': []},{'id': '340', 'type': 'else_clause', 'children': ['341']},{'id': '341', 'type': 'block', 'children': ['342']},{'id': '342', 'type': 'raise_statement', 'children': ['343']},{'id': '343', 'type': 'call', 'children': ['344', '345']},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'ExclusiveConstraints'},{'id': '345', 'type': 'argument_list', 'children': ['346', '347']},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'g_constraint'},{'id': '347', 'type': 'list', 'children': ['348'], 'value': '[l_constraint]'},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'l_constraint'},{'id': '349', 'type': 'elif_clause', 'children': ['350', '357']},{'id': '350', 'type': 'comparison_operator', 'children': ['351', '354'], 'value': '>'},{'id': '351', 'type': 'attribute', 'children': ['352', '353']},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'g_constraint'},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '354', 'type': 'attribute', 'children': ['355', '356']},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'l_constraint'},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '357', 'type': 'block', 'children': ['358']},{'id': '358', 'type': 'raise_statement', 'children': ['359']},{'id': '359', 'type': 'call', 'children': ['360', '361']},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'ExclusiveConstraints'},{'id': '361', 'type': 'argument_list', 'children': ['362', '363']},{'id': '362', 'type': 'identifier', 'children': [], 'value': 'g_constraint'},{'id': '363', 'type': 'list', 'children': ['364'], 'value': '[l_constraint]'},{'id': '364', 'type': 'identifier', 'children': [], 'value': 'l_constraint'},{'id': '365', 'type': 'expression_statement', 'children': ['366']},{'id': '366', 'type': 'assignment', 'children': ['367', '368']},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'ne_constraints'},{'id': '368', 'type': 'list_comprehension', 'children': ['369', '374']},{'id': '369', 'type': 'call', 'children': ['370', '371']},{'id': '370', 'type': 'identifier', 'children': [], 'value': 'Constraint'},{'id': '371', 'type': 'argument_list', 'children': ['372', '373']},{'id': '372', 'type': 'identifier', 'children': [], 'value': 'ne'},{'id': '373', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '374', 'type': 'for_in_clause', 'children': ['375', '376']},{'id': '375', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '376', 'type': 'subscript', 'children': ['377', '378']},{'id': '377', 'type': 'identifier', 'children': [], 'value': 'operators'},{'id': '378', 'type': 'identifier', 'children': [], 'value': 'ne'},{'id': '379', 'type': 'expression_statement', 'children': ['380']},{'id': '380', 'type': 'assignment', 'children': ['381', '382']},{'id': '381', 'type': 'identifier', 'children': [], 'value': 'eq_constraints'},{'id': '382', 'type': 'list_comprehension', 'children': ['383', '388']},{'id': '383', 'type': 'call', 'children': ['384', '385']},{'id': '384', 'type': 'identifier', 'children': [], 'value': 'Constraint'},{'id': '385', 'type': 'argument_list', 'children': ['386', '387']},{'id': '386', 'type': 'identifier', 'children': [], 'value': 'eq'},{'id': '387', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '388', 'type': 'for_in_clause', 'children': ['389', '390']},{'id': '389', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '390', 'type': 'subscript', 'children': ['391', '392']},{'id': '391', 'type': 'identifier', 'children': [], 'value': 'operators'},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'eq'},{'id': '393', 'type': 'if_statement', 'children': ['394', '395', '448']},{'id': '394', 'type': 'identifier', 'children': [], 'value': 'eq_constraints'},{'id': '395', 'type': 'block', 'children': ['396', '404', '445']},{'id': '396', 'type': 'expression_statement', 'children': ['397']},{'id': '397', 'type': 'assignment', 'children': ['398', '399']},{'id': '398', 'type': 'identifier', 'children': [], 'value': 'eq_constraint'},{'id': '399', 'type': 'call', 'children': ['400', '403']},{'id': '400', 'type': 'attribute', 'children': ['401', '402']},{'id': '401', 'type': 'identifier', 'children': [], 'value': 'eq_constraints'},{'id': '402', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '403', 'type': 'argument_list', 'children': []},{'id': '404', 'type': 'if_statement', 'children': ['405', '412']},{'id': '405', 'type': 'boolean_operator', 'children': ['406', '411'], 'value': 'or'},{'id': '406', 'type': 'boolean_operator', 'children': ['407', '410'], 'value': 'or'},{'id': '407', 'type': 'boolean_operator', 'children': ['408', '409'], 'value': 'or'},{'id': '408', 'type': 'identifier', 'children': [], 'value': 'g_constraint'},{'id': '409', 'type': 'identifier', 'children': [], 'value': 'l_constraint'},{'id': '410', 'type': 'identifier', 'children': [], 'value': 'ne_constraints'},{'id': '411', 'type': 'identifier', 'children': [], 'value': 'eq_constraints'},{'id': '412', 'type': 'block', 'children': ['413', '425', '432', '439']},{'id': '413', 'type': 'expression_statement', 'children': ['414']},{'id': '414', 'type': 'assignment', 'children': ['415', '416']},{'id': '415', 'type': 'identifier', 'children': [], 'value': 'conflict_list'},{'id': '416', 'type': 'list_comprehension', 'children': ['417', '418', '423']},{'id': '417', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '418', 'type': 'for_in_clause', 'children': ['419', '420']},{'id': '419', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '420', 'type': 'tuple', 'children': ['421', '422']},{'id': '421', 'type': 'identifier', 'children': [], 'value': 'g_constraint'},{'id': '422', 'type': 'identifier', 'children': [], 'value': 'l_constraint'},{'id': '423', 'type': 'if_clause', 'children': ['424']},{'id': '424', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '425', 'type': 'expression_statement', 'children': ['426']},{'id': '426', 'type': 'call', 'children': ['427', '430']},{'id': '427', 'type': 'attribute', 'children': ['428', '429']},{'id': '428', 'type': 'identifier', 'children': [], 'value': 'conflict_list'},{'id': '429', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '430', 'type': 'argument_list', 'children': ['431']},{'id': '431', 'type': 'identifier', 'children': [], 'value': 'ne_constraints'},{'id': '432', 'type': 'expression_statement', 'children': ['433']},{'id': '433', 'type': 'call', 'children': ['434', '437']},{'id': '434', 'type': 'attribute', 'children': ['435', '436']},{'id': '435', 'type': 'identifier', 'children': [], 'value': 'conflict_list'},{'id': '436', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '437', 'type': 'argument_list', 'children': ['438']},{'id': '438', 'type': 'identifier', 'children': [], 'value': 'eq_constraints'},{'id': '439', 'type': 'raise_statement', 'children': ['440']},{'id': '440', 'type': 'call', 'children': ['441', '442']},{'id': '441', 'type': 'identifier', 'children': [], 'value': 'ExclusiveConstraints'},{'id': '442', 'type': 'argument_list', 'children': ['443', '444']},{'id': '443', 'type': 'identifier', 'children': [], 'value': 'eq_constraint'},{'id': '444', 'type': 'identifier', 'children': [], 'value': 'conflict_list'},{'id': '445', 'type': 'return_statement', 'children': ['446']},{'id': '446', 'type': 'list', 'children': ['447'], 'value': '[eq_constraint]'},{'id': '447', 'type': 'identifier', 'children': [], 'value': 'eq_constraint'},{'id': '448', 'type': 'else_clause', 'children': ['449']},{'id': '449', 'type': 'block', 'children': ['450', '458']},{'id': '450', 'type': 'expression_statement', 'children': ['451']},{'id': '451', 'type': 'assignment', 'children': ['452', '453']},{'id': '452', 'type': 'identifier', 'children': [], 'value': 'constraints'},{'id': '453', 'type': 'binary_operator', 'children': ['454', '455'], 'value': '+'},{'id': '454', 'type': 'identifier', 'children': [], 'value': 'ne_constraints'},{'id': '455', 'type': 'list', 'children': ['456', '457'], 'value': '[g_constraint, l_constraint]'},{'id': '456', 'type': 'identifier', 'children': [], 'value': 'g_constraint'},{'id': '457', 'type': 'identifier', 'children': [], 'value': 'l_constraint'},{'id': '458', 'type': 'return_statement', 'children': ['459']},{'id': '459', 'type': 'list_comprehension', 'children': ['460', '461', '464']},{'id': '460', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '461', 'type': 'for_in_clause', 'children': ['462', '463']},{'id': '462', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '463', 'type': 'identifier', 'children': [], 'value': 'constraints'},{'id': '464', 'type': 'if_clause', 'children': ['465']},{'id': '465', 'type': 'identifier', 'children': [], 'value': 'c'}
def merge(constraints): operators = defaultdict(set) for constraint in constraints: operators[constraint.operator].add(constraint.version) if gt in operators: gt_ver = sorted(operators[gt])[-1] else: gt_ver = None if ge in operators: ge_ver = sorted(operators[ge])[-1] else: ge_ver = None if lt in operators: lt_ver = sorted(operators[lt])[0] else: lt_ver = None if le in operators: le_ver = sorted(operators[le])[0] else: le_ver = None 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: l_constraint = le_constraint l_less_restrictive_c = lt_constraint else: 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) 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: g_constraint = gt_constraint g_less_restrictive_c = ge_constraint else: 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) if g_constraint and l_constraint: if g_constraint.version == l_constraint.version: if g_constraint.operator == ge and l_constraint.operator == le: 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() 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]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse_baxter'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'reading'},{'id': '5', 'type': 'block', 'children': ['6', '10', '14', '18', '22', '26', '30', '34', '38', '42', '49', '139', '162', '175', '192']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'initial'},{'id': '9', 'type': 'string', 'children': [], 'value': "''"},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'medial'},{'id': '13', 'type': 'string', 'children': [], 'value': "''"},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'final'},{'id': '17', 'type': 'string', 'children': [], 'value': "''"},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'tone'},{'id': '21', 'type': 'string', 'children': [], 'value': "''"},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'inienv'},{'id': '25', 'type': 'True', 'children': []},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'medienv'},{'id': '29', 'type': 'False', 'children': []},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'finenv'},{'id': '33', 'type': 'False', 'children': []},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'tonenv'},{'id': '37', 'type': 'False', 'children': []},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'inichars'},{'id': '41', 'type': 'string', 'children': [], 'value': '"pbmrtdnkgnsyhzl\'x"'},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'chars'},{'id': '45', 'type': 'call', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'reading'},{'id': '49', 'type': 'for_statement', 'children': ['50', '51', '52']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'char'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'chars'},{'id': '52', 'type': 'block', 'children': ['53', '111', '118', '125', '132']},{'id': '53', 'type': 'if_statement', 'children': ['54', '60', '73']},{'id': '54', 'type': 'boolean_operator', 'children': ['55', '58'], 'value': 'and'},{'id': '55', 'type': 'comparison_operator', 'children': ['56', '57'], 'value': 'in'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'char'},{'id': '57', 'type': 'string', 'children': [], 'value': "'jw'"},{'id': '58', 'type': 'not_operator', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'finenv'},{'id': '60', 'type': 'block', 'children': ['61']},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '68']},{'id': '63', 'type': 'pattern_list', 'children': ['64', '65', '66', '67']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'inienv'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'medienv'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'finenv'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'tonenv'},{'id': '68', 'type': 'expression_list', 'children': ['69', '70', '71', '72']},{'id': '69', 'type': 'False', 'children': []},{'id': '70', 'type': 'True', 'children': []},{'id': '71', 'type': 'False', 'children': []},{'id': '72', 'type': 'False', 'children': []},{'id': '73', 'type': 'elif_clause', 'children': ['74', '79']},{'id': '74', 'type': 'boolean_operator', 'children': ['75', '78'], 'value': 'or'},{'id': '75', 'type': 'comparison_operator', 'children': ['76', '77'], 'value': 'not'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'char'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'inichars'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'finenv'},{'id': '79', 'type': 'block', 'children': ['80']},{'id': '80', 'type': 'if_statement', 'children': ['81', '84', '97']},{'id': '81', 'type': 'comparison_operator', 'children': ['82', '83'], 'value': 'in'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'char'},{'id': '83', 'type': 'string', 'children': [], 'value': "'XH'"},{'id': '84', 'type': 'block', 'children': ['85']},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'assignment', 'children': ['87', '92']},{'id': '87', 'type': 'pattern_list', 'children': ['88', '89', '90', '91']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'inienv'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'medienv'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'finenv'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'tonenv'},{'id': '92', 'type': 'expression_list', 'children': ['93', '94', '95', '96']},{'id': '93', 'type': 'False', 'children': []},{'id': '94', 'type': 'False', 'children': []},{'id': '95', 'type': 'False', 'children': []},{'id': '96', 'type': 'True', 'children': []},{'id': '97', 'type': 'else_clause', 'children': ['98']},{'id': '98', 'type': 'block', 'children': ['99']},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'assignment', 'children': ['101', '106']},{'id': '101', 'type': 'pattern_list', 'children': ['102', '103', '104', '105']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'inienv'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'medienv'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'finenv'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'tonenv'},{'id': '106', 'type': 'expression_list', 'children': ['107', '108', '109', '110']},{'id': '107', 'type': 'False', 'children': []},{'id': '108', 'type': 'False', 'children': []},{'id': '109', 'type': 'True', 'children': []},{'id': '110', 'type': 'False', 'children': []},{'id': '111', 'type': 'if_statement', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'inienv'},{'id': '113', 'type': 'block', 'children': ['114']},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'augmented_assignment', 'children': ['116', '117'], 'value': '+='},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'initial'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'char'},{'id': '118', 'type': 'if_statement', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'medienv'},{'id': '120', 'type': 'block', 'children': ['121']},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'augmented_assignment', 'children': ['123', '124'], 'value': '+='},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'medial'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'char'},{'id': '125', 'type': 'if_statement', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'finenv'},{'id': '127', 'type': 'block', 'children': ['128']},{'id': '128', 'type': 'expression_statement', 'children': ['129']},{'id': '129', 'type': 'augmented_assignment', 'children': ['130', '131'], 'value': '+='},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'final'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'char'},{'id': '132', 'type': 'if_statement', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'tonenv'},{'id': '134', 'type': 'block', 'children': ['135']},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'augmented_assignment', 'children': ['137', '138'], 'value': '+='},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'tone'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'char'},{'id': '139', 'type': 'if_statement', 'children': ['140', '149', '154']},{'id': '140', 'type': 'boolean_operator', 'children': ['141', '143'], 'value': 'and'},{'id': '141', 'type': 'not_operator', 'children': ['142']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'tone'},{'id': '143', 'type': 'comparison_operator', 'children': ['144', '148'], 'value': 'in'},{'id': '144', 'type': 'subscript', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'final'},{'id': '146', 'type': 'unary_operator', 'children': ['147'], 'value': '-'},{'id': '147', 'type': 'integer', 'children': [], 'value': '1'},{'id': '148', 'type': 'string', 'children': [], 'value': "'ptk'"},{'id': '149', 'type': 'block', 'children': ['150']},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'assignment', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'tone'},{'id': '153', 'type': 'string', 'children': [], 'value': "'R'"},{'id': '154', 'type': 'elif_clause', 'children': ['155', '157']},{'id': '155', 'type': 'not_operator', 'children': ['156']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'tone'},{'id': '157', 'type': 'block', 'children': ['158']},{'id': '158', 'type': 'expression_statement', 'children': ['159']},{'id': '159', 'type': 'assignment', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'tone'},{'id': '161', 'type': 'string', 'children': [], 'value': "'P'"},{'id': '162', 'type': 'if_statement', 'children': ['163', '170']},{'id': '163', 'type': 'boolean_operator', 'children': ['164', '167'], 'value': 'and'},{'id': '164', 'type': 'comparison_operator', 'children': ['165', '166'], 'value': 'not'},{'id': '165', 'type': 'string', 'children': [], 'value': "'j'"},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'medial'},{'id': '167', 'type': 'comparison_operator', 'children': ['168', '169'], 'value': 'in'},{'id': '168', 'type': 'string', 'children': [], 'value': "'y'"},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'initial'},{'id': '170', 'type': 'block', 'children': ['171']},{'id': '171', 'type': 'expression_statement', 'children': ['172']},{'id': '172', 'type': 'augmented_assignment', 'children': ['173', '174'], 'value': '+='},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'medial'},{'id': '174', 'type': 'string', 'children': [], 'value': "'j'"},{'id': '175', 'type': 'if_statement', 'children': ['176', '185']},{'id': '176', 'type': 'boolean_operator', 'children': ['177', '182'], 'value': 'and'},{'id': '177', 'type': 'comparison_operator', 'children': ['178', '181'], 'value': 'in'},{'id': '178', 'type': 'subscript', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'final'},{'id': '180', 'type': 'integer', 'children': [], 'value': '0'},{'id': '181', 'type': 'string', 'children': [], 'value': "'u'"},{'id': '182', 'type': 'comparison_operator', 'children': ['183', '184'], 'value': 'not'},{'id': '183', 'type': 'string', 'children': [], 'value': "'w'"},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'medial'},{'id': '185', 'type': 'block', 'children': ['186']},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'assignment', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'medial'},{'id': '189', 'type': 'binary_operator', 'children': ['190', '191'], 'value': '+'},{'id': '190', 'type': 'string', 'children': [], 'value': "'w'"},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'medial'},{'id': '192', 'type': 'return_statement', 'children': ['193']},{'id': '193', 'type': 'expression_list', 'children': ['194', '195', '196', '197']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'initial'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'medial'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'final'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'tone'}
def parse_baxter(reading): initial = '' medial = '' final = '' tone = '' inienv = True medienv = False finenv = False tonenv = False inichars = "pbmrtdnkgnsyhzl'x" chars = list(reading) for char in chars: 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 if inienv: initial += char if medienv: medial += char if finenv: final += char if tonenv: tone += char if not tone and final[-1] in 'ptk': tone = 'R' elif not tone: tone = 'P' if 'j' not in medial and 'y' in initial: medial += 'j' if final[0] in 'u' and 'w' not in medial: medial = 'w' + medial return initial,medial,final,tone
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'create'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '6', 'type': 'keyword_separator', 'children': []},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'dc'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'block', 'children': ['11', '31', '52']},{'id': '11', 'type': 'if_statement', 'children': ['12', '15']},{'id': '12', 'type': 'comparison_operator', 'children': ['13', '14'], 'value': 'in'},{'id': '13', 'type': 'string', 'children': [], 'value': '"Token"'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '15', 'type': 'block', 'children': ['16']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '21']},{'id': '18', 'type': 'subscript', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '20', 'type': 'string', 'children': [], 'value': '"Token"'},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'extract_attr'},{'id': '23', 'type': 'argument_list', 'children': ['24', '27']},{'id': '24', 'type': 'subscript', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '26', 'type': 'string', 'children': [], 'value': '"Token"'},{'id': '27', 'type': 'keyword_argument', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '29', 'type': 'list', 'children': ['30'], 'value': '["ID"]'},{'id': '30', 'type': 'string', 'children': [], 'value': '"ID"'},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '34', 'type': 'await', 'children': ['35']},{'id': '35', 'type': 'call', 'children': ['36', '41']},{'id': '36', 'type': 'attribute', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '39', 'type': 'identifier', 'children': [], 'value': '_api'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'post'},{'id': '41', 'type': 'argument_list', 'children': ['42', '43', '49']},{'id': '42', 'type': 'string', 'children': [], 'value': '"/v1/query"'},{'id': '43', 'type': 'keyword_argument', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '45', 'type': 'dictionary', 'children': ['46']},{'id': '46', 'type': 'pair', 'children': ['47', '48']},{'id': '47', 'type': 'string', 'children': [], 'value': '"dc"'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'dc'},{'id': '49', 'type': 'keyword_argument', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '52', 'type': 'return_statement', 'children': ['53']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'body'}
async def create(self, query, *, dc=None): if "Token" in query: query["Token"] = extract_attr(query["Token"], keys=["ID"]) response = await self._api.post("/v1/query", params={"dc": dc}, data=query) return response.body
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '19']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'execute'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13', '16']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '6', 'type': 'keyword_separator', 'children': []},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'dc'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'near'},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'default_parameter', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '15', 'type': 'None', 'children': []},{'id': '16', 'type': 'default_parameter', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'consistency'},{'id': '18', 'type': 'None', 'children': []},{'id': '19', 'type': 'block', 'children': ['20', '31', '60']},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'query_id'},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'extract_attr'},{'id': '25', 'type': 'argument_list', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '27', 'type': 'keyword_argument', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '29', 'type': 'list', 'children': ['30'], 'value': '["ID"]'},{'id': '30', 'type': 'string', 'children': [], 'value': '"ID"'},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '34', 'type': 'await', 'children': ['35']},{'id': '35', 'type': 'call', 'children': ['36', '41']},{'id': '36', 'type': 'attribute', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '39', 'type': 'identifier', 'children': [], 'value': '_api'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '41', 'type': 'argument_list', 'children': ['42', '45', '57']},{'id': '42', 'type': 'binary_operator', 'children': ['43', '44'], 'value': '%'},{'id': '43', 'type': 'string', 'children': [], 'value': '"/v1/query/%s/execute"'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'query_id'},{'id': '45', 'type': 'keyword_argument', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '47', 'type': 'dictionary', 'children': ['48', '51', '54']},{'id': '48', 'type': 'pair', 'children': ['49', '50']},{'id': '49', 'type': 'string', 'children': [], 'value': '"dc"'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'dc'},{'id': '51', 'type': 'pair', 'children': ['52', '53']},{'id': '52', 'type': 'string', 'children': [], 'value': '"near"'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'near'},{'id': '54', 'type': 'pair', 'children': ['55', '56']},{'id': '55', 'type': 'string', 'children': [], 'value': '"limit"'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '57', 'type': 'keyword_argument', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'consistency'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'consistency'},{'id': '60', 'type': 'return_statement', 'children': ['61']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'body'}
async def execute(self, query, *, dc=None, near=None, limit=None, consistency=None): 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
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'zip_process'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'dictionary_splat_pattern', 'children': ['5']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '6', 'type': 'block', 'children': ['7', '11', '15', '19', '23', '69', '94', '253']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'str_localPath'},{'id': '10', 'type': 'string', 'children': [], 'value': '""'},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'str_zipFileName'},{'id': '14', 'type': 'string', 'children': [], 'value': '""'},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'str_action'},{'id': '18', 'type': 'string', 'children': [], 'value': '"zip"'},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'str_arcroot'},{'id': '22', 'type': 'string', 'children': [], 'value': '""'},{'id': '23', 'type': 'for_statement', 'children': ['24', '27', '32']},{'id': '24', 'type': 'pattern_list', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '31', 'type': 'argument_list', 'children': []},{'id': '32', 'type': 'block', 'children': ['33', '42', '51', '60']},{'id': '33', 'type': 'if_statement', 'children': ['34', '37']},{'id': '34', 'type': 'comparison_operator', 'children': ['35', '36'], 'value': '=='},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '36', 'type': 'string', 'children': [], 'value': "'path'"},{'id': '37', 'type': 'block', 'children': ['38']},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'str_localPath'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '42', 'type': 'if_statement', 'children': ['43', '46']},{'id': '43', 'type': 'comparison_operator', 'children': ['44', '45'], 'value': '=='},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '45', 'type': 'string', 'children': [], 'value': "'action'"},{'id': '46', 'type': 'block', 'children': ['47']},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'str_action'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '51', 'type': 'if_statement', 'children': ['52', '55']},{'id': '52', 'type': 'comparison_operator', 'children': ['53', '54'], 'value': '=='},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '54', 'type': 'string', 'children': [], 'value': "'payloadFile'"},{'id': '55', 'type': 'block', 'children': ['56']},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'str_zipFileName'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '60', 'type': 'if_statement', 'children': ['61', '64']},{'id': '61', 'type': 'comparison_operator', 'children': ['62', '63'], 'value': '=='},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '63', 'type': 'string', 'children': [], 'value': "'arcroot'"},{'id': '64', 'type': 'block', 'children': ['65']},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'str_arcroot'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '69', 'type': 'if_statement', 'children': ['70', '73', '88']},{'id': '70', 'type': 'comparison_operator', 'children': ['71', '72'], 'value': '=='},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'str_action'},{'id': '72', 'type': 'string', 'children': [], 'value': "'zip'"},{'id': '73', 'type': 'block', 'children': ['74', '78']},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'str_mode'},{'id': '77', 'type': 'string', 'children': [], 'value': "'w'"},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'str_zipFileName'},{'id': '81', 'type': 'binary_operator', 'children': ['82', '83'], 'value': '%'},{'id': '82', 'type': 'string', 'children': [], 'value': "'%s.zip'"},{'id': '83', 'type': 'call', 'children': ['84', '87']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'uuid4'},{'id': '87', 'type': 'argument_list', 'children': []},{'id': '88', 'type': 'else_clause', 'children': ['89']},{'id': '89', 'type': 'block', 'children': ['90']},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'str_mode'},{'id': '93', 'type': 'string', 'children': [], 'value': "'r'"},{'id': '94', 'type': 'try_statement', 'children': ['95', '241']},{'id': '95', 'type': 'block', 'children': ['96', '109', '213', '225', '231', '237']},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'assignment', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'ziphandler'},{'id': '99', 'type': 'call', 'children': ['100', '103']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'zipfile'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'ZipFile'},{'id': '103', 'type': 'argument_list', 'children': ['104', '105', '106']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'str_zipFileName'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'str_mode'},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'zipfile'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'ZIP_DEFLATED'},{'id': '109', 'type': 'if_statement', 'children': ['110', '113']},{'id': '110', 'type': 'comparison_operator', 'children': ['111', '112'], 'value': '=='},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'str_mode'},{'id': '112', 'type': 'string', 'children': [], 'value': "'w'"},{'id': '113', 'type': 'block', 'children': ['114']},{'id': '114', 'type': 'if_statement', 'children': ['115', '123', '133']},{'id': '115', 'type': 'call', 'children': ['116', '121']},{'id': '116', 'type': 'attribute', 'children': ['117', '120']},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'isdir'},{'id': '121', 'type': 'argument_list', 'children': ['122']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'str_localPath'},{'id': '123', 'type': 'block', 'children': ['124']},{'id': '124', 'type': 'expression_statement', 'children': ['125']},{'id': '125', 'type': 'call', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'zipdir'},{'id': '127', 'type': 'argument_list', 'children': ['128', '129', '130']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'str_localPath'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'ziphandler'},{'id': '130', 'type': 'keyword_argument', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'arcroot'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'str_arcroot'},{'id': '133', 'type': 'else_clause', 'children': ['134']},{'id': '134', 'type': 'block', 'children': ['135', '168']},{'id': '135', 'type': 'if_statement', 'children': ['136', '140', '162']},{'id': '136', 'type': 'call', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'str_arcroot'},{'id': '140', 'type': 'block', 'children': ['141']},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'assignment', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'str_arcname'},{'id': '144', 'type': 'binary_operator', 'children': ['145', '154'], 'value': '+'},{'id': '145', 'type': 'subscript', 'children': ['146', '152']},{'id': '146', 'type': 'call', 'children': ['147', '150']},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'str_arcroot'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '150', 'type': 'argument_list', 'children': ['151']},{'id': '151', 'type': 'string', 'children': [], 'value': "'/'"},{'id': '152', 'type': 'unary_operator', 'children': ['153'], 'value': '-'},{'id': '153', 'type': 'integer', 'children': [], 'value': '1'},{'id': '154', 'type': 'subscript', 'children': ['155', '161']},{'id': '155', 'type': 'call', 'children': ['156', '159']},{'id': '156', 'type': 'attribute', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'str_localPath'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '159', 'type': 'argument_list', 'children': ['160']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'str_arcroot'},{'id': '161', 'type': 'integer', 'children': [], 'value': '1'},{'id': '162', 'type': 'else_clause', 'children': ['163']},{'id': '163', 'type': 'block', 'children': ['164']},{'id': '164', 'type': 'expression_statement', 'children': ['165']},{'id': '165', 'type': 'assignment', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'str_arcname'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'str_localPath'},{'id': '168', 'type': 'try_statement', 'children': ['169', '180']},{'id': '169', 'type': 'block', 'children': ['170']},{'id': '170', 'type': 'expression_statement', 'children': ['171']},{'id': '171', 'type': 'call', 'children': ['172', '175']},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'ziphandler'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '175', 'type': 'argument_list', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'str_localPath'},{'id': '177', 'type': 'keyword_argument', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'arcname'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'str_arcname'},{'id': '180', 'type': 'except_clause', 'children': ['181']},{'id': '181', 'type': 'block', 'children': ['182', '188', '195']},{'id': '182', 'type': 'expression_statement', 'children': ['183']},{'id': '183', 'type': 'call', 'children': ['184', '187']},{'id': '184', 'type': 'attribute', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'ziphandler'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '187', 'type': 'argument_list', 'children': []},{'id': '188', 'type': 'expression_statement', 'children': ['189']},{'id': '189', 'type': 'call', 'children': ['190', '193']},{'id': '190', 'type': 'attribute', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'remove'},{'id': '193', 'type': 'argument_list', 'children': ['194']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'str_zipFileName'},{'id': '195', 'type': 'return_statement', 'children': ['196']},{'id': '196', 'type': 'dictionary', 'children': ['197', '210']},{'id': '197', 'type': 'pair', 'children': ['198', '199']},{'id': '198', 'type': 'string', 'children': [], 'value': "'msg'"},{'id': '199', 'type': 'call', 'children': ['200', '203']},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'dumps'},{'id': '203', 'type': 'argument_list', 'children': ['204']},{'id': '204', 'type': 'dictionary', 'children': ['205']},{'id': '205', 'type': 'pair', 'children': ['206', '207']},{'id': '206', 'type': 'string', 'children': [], 'value': '"msg"'},{'id': '207', 'type': 'binary_operator', 'children': ['208', '209'], 'value': '%'},{'id': '208', 'type': 'string', 'children': [], 'value': '"No file or directory found for \'%s\'"'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'str_localPath'},{'id': '210', 'type': 'pair', 'children': ['211', '212']},{'id': '211', 'type': 'string', 'children': [], 'value': "'status'"},{'id': '212', 'type': 'False', 'children': []},{'id': '213', 'type': 'if_statement', 'children': ['214', '217']},{'id': '214', 'type': 'comparison_operator', 'children': ['215', '216'], 'value': '=='},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'str_mode'},{'id': '216', 'type': 'string', 'children': [], 'value': "'r'"},{'id': '217', 'type': 'block', 'children': ['218']},{'id': '218', 'type': 'expression_statement', 'children': ['219']},{'id': '219', 'type': 'call', 'children': ['220', '223']},{'id': '220', 'type': 'attribute', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'ziphandler'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'extractall'},{'id': '223', 'type': 'argument_list', 'children': ['224']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'str_localPath'},{'id': '225', 'type': 'expression_statement', 'children': ['226']},{'id': '226', 'type': 'call', 'children': ['227', '230']},{'id': '227', 'type': 'attribute', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'ziphandler'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '230', 'type': 'argument_list', 'children': []},{'id': '231', 'type': 'expression_statement', 'children': ['232']},{'id': '232', 'type': 'assignment', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'str_msg'},{'id': '234', 'type': 'binary_operator', 'children': ['235', '236'], 'value': '%'},{'id': '235', 'type': 'string', 'children': [], 'value': "'%s operation successful'"},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'str_action'},{'id': '237', 'type': 'expression_statement', 'children': ['238']},{'id': '238', 'type': 'assignment', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'b_status'},{'id': '240', 'type': 'True', 'children': []},{'id': '241', 'type': 'except_clause', 'children': ['242']},{'id': '242', 'type': 'block', 'children': ['243', '249']},{'id': '243', 'type': 'expression_statement', 'children': ['244']},{'id': '244', 'type': 'assignment', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'str_msg'},{'id': '246', 'type': 'binary_operator', 'children': ['247', '248'], 'value': '%'},{'id': '247', 'type': 'string', 'children': [], 'value': "'%s operation failed'"},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'str_action'},{'id': '249', 'type': 'expression_statement', 'children': ['250']},{'id': '250', 'type': 'assignment', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'b_status'},{'id': '252', 'type': 'False', 'children': []},{'id': '253', 'type': 'return_statement', 'children': ['254']},{'id': '254', 'type': 'dictionary', 'children': ['255', '258', '261', '264', '267', '270', '285']},{'id': '255', 'type': 'pair', 'children': ['256', '257']},{'id': '256', 'type': 'string', 'children': [], 'value': "'msg'"},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'str_msg'},{'id': '258', 'type': 'pair', 'children': ['259', '260']},{'id': '259', 'type': 'string', 'children': [], 'value': "'fileProcessed'"},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'str_zipFileName'},{'id': '261', 'type': 'pair', 'children': ['262', '263']},{'id': '262', 'type': 'string', 'children': [], 'value': "'status'"},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'b_status'},{'id': '264', 'type': 'pair', 'children': ['265', '266']},{'id': '265', 'type': 'string', 'children': [], 'value': "'path'"},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'str_localPath'},{'id': '267', 'type': 'pair', 'children': ['268', '269']},{'id': '268', 'type': 'string', 'children': [], 'value': "'zipmode'"},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'str_mode'},{'id': '270', 'type': 'pair', 'children': ['271', '272']},{'id': '271', 'type': 'string', 'children': [], 'value': "'filesize'"},{'id': '272', 'type': 'call', 'children': ['273', '276']},{'id': '273', 'type': 'attribute', 'children': ['274', '275']},{'id': '274', 'type': 'string', 'children': [], 'value': '"{:,}"'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '276', 'type': 'argument_list', 'children': ['277']},{'id': '277', 'type': 'attribute', 'children': ['278', '284']},{'id': '278', 'type': 'call', 'children': ['279', '282']},{'id': '279', 'type': 'attribute', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'stat'},{'id': '282', 'type': 'argument_list', 'children': ['283']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'str_zipFileName'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'st_size'},{'id': '285', 'type': 'pair', 'children': ['286', '287']},{'id': '286', 'type': 'string', 'children': [], 'value': "'timestamp'"},{'id': '287', 'type': 'binary_operator', 'children': ['288', '289'], 'value': '%'},{'id': '288', 'type': 'string', 'children': [], 'value': "'%s'"},{'id': '289', 'type': 'call', 'children': ['290', '295']},{'id': '290', 'type': 'attribute', 'children': ['291', '294']},{'id': '291', 'type': 'attribute', 'children': ['292', '293']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '295', 'type': 'argument_list', 'children': []}
def zip_process(**kwargs): 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() }
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'base64_process'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'dictionary_splat_pattern', 'children': ['5']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '6', 'type': 'block', 'children': ['7', '11', '15', '19', '23', '69', '151']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'str_fileToSave'},{'id': '10', 'type': 'string', 'children': [], 'value': '""'},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'str_fileToRead'},{'id': '14', 'type': 'string', 'children': [], 'value': '""'},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'str_action'},{'id': '18', 'type': 'string', 'children': [], 'value': '"encode"'},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '22', 'type': 'None', 'children': []},{'id': '23', 'type': 'for_statement', 'children': ['24', '27', '32']},{'id': '24', 'type': 'pattern_list', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '31', 'type': 'argument_list', 'children': []},{'id': '32', 'type': 'block', 'children': ['33', '42', '51', '60']},{'id': '33', 'type': 'if_statement', 'children': ['34', '37']},{'id': '34', 'type': 'comparison_operator', 'children': ['35', '36'], 'value': '=='},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '36', 'type': 'string', 'children': [], 'value': "'action'"},{'id': '37', 'type': 'block', 'children': ['38']},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'str_action'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '42', 'type': 'if_statement', 'children': ['43', '46']},{'id': '43', 'type': 'comparison_operator', 'children': ['44', '45'], 'value': '=='},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '45', 'type': 'string', 'children': [], 'value': "'payloadBytes'"},{'id': '46', 'type': 'block', 'children': ['47']},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '51', 'type': 'if_statement', 'children': ['52', '55']},{'id': '52', 'type': 'comparison_operator', 'children': ['53', '54'], 'value': '=='},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '54', 'type': 'string', 'children': [], 'value': "'payloadFile'"},{'id': '55', 'type': 'block', 'children': ['56']},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'str_fileToRead'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '60', 'type': 'if_statement', 'children': ['61', '64']},{'id': '61', 'type': 'comparison_operator', 'children': ['62', '63'], 'value': '=='},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '63', 'type': 'string', 'children': [], 'value': "'saveToFile'"},{'id': '64', 'type': 'block', 'children': ['65']},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'str_fileToSave'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '69', 'type': 'if_statement', 'children': ['70', '73']},{'id': '70', 'type': 'comparison_operator', 'children': ['71', '72'], 'value': '=='},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'str_action'},{'id': '72', 'type': 'string', 'children': [], 'value': '"encode"'},{'id': '73', 'type': 'block', 'children': ['74', '106', '115', '140']},{'id': '74', 'type': 'if_statement', 'children': ['75', '79']},{'id': '75', 'type': 'call', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'str_fileToRead'},{'id': '79', 'type': 'block', 'children': ['80']},{'id': '80', 'type': 'with_statement', 'children': ['81', '91']},{'id': '81', 'type': 'with_clause', 'children': ['82']},{'id': '82', 'type': 'with_item', 'children': ['83']},{'id': '83', 'type': 'as_pattern', 'children': ['84', '89']},{'id': '84', 'type': 'call', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '86', 'type': 'argument_list', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'str_fileToRead'},{'id': '88', 'type': 'string', 'children': [], 'value': "'rb'"},{'id': '89', 'type': 'as_pattern_target', 'children': ['90']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '91', 'type': 'block', 'children': ['92', '100']},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'assignment', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '95', 'type': 'call', 'children': ['96', '99']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '99', 'type': 'argument_list', 'children': []},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'call', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '105', 'type': 'argument_list', 'children': []},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'assignment', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'data_b64'},{'id': '109', 'type': 'call', 'children': ['110', '113']},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'base64'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'b64encode'},{'id': '113', 'type': 'argument_list', 'children': ['114']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '115', 'type': 'with_statement', 'children': ['116', '126']},{'id': '116', 'type': 'with_clause', 'children': ['117']},{'id': '117', 'type': 'with_item', 'children': ['118']},{'id': '118', 'type': 'as_pattern', 'children': ['119', '124']},{'id': '119', 'type': 'call', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '121', 'type': 'argument_list', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'str_fileToSave'},{'id': '123', 'type': 'string', 'children': [], 'value': "'wb'"},{'id': '124', 'type': 'as_pattern_target', 'children': ['125']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '126', 'type': 'block', 'children': ['127', '134']},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'call', 'children': ['129', '132']},{'id': '129', 'type': 'attribute', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'data_b64'},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'call', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '139', 'type': 'argument_list', 'children': []},{'id': '140', 'type': 'return_statement', 'children': ['141']},{'id': '141', 'type': 'dictionary', 'children': ['142', '145', '148']},{'id': '142', 'type': 'pair', 'children': ['143', '144']},{'id': '143', 'type': 'string', 'children': [], 'value': "'msg'"},{'id': '144', 'type': 'string', 'children': [], 'value': "'Encode successful'"},{'id': '145', 'type': 'pair', 'children': ['146', '147']},{'id': '146', 'type': 'string', 'children': [], 'value': "'fileProcessed'"},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'str_fileToSave'},{'id': '148', 'type': 'pair', 'children': ['149', '150']},{'id': '149', 'type': 'string', 'children': [], 'value': "'status'"},{'id': '150', 'type': 'True', 'children': []},{'id': '151', 'type': 'if_statement', 'children': ['152', '155']},{'id': '152', 'type': 'comparison_operator', 'children': ['153', '154'], 'value': '=='},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'str_action'},{'id': '154', 'type': 'string', 'children': [], 'value': '"decode"'},{'id': '155', 'type': 'block', 'children': ['156', '167', '192']},{'id': '156', 'type': 'expression_statement', 'children': ['157']},{'id': '157', 'type': 'assignment', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'bytes_decoded'},{'id': '159', 'type': 'call', 'children': ['160', '163']},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'base64'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'b64decode'},{'id': '163', 'type': 'argument_list', 'children': ['164']},{'id': '164', 'type': 'binary_operator', 'children': ['165', '166'], 'value': '+'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '166', 'type': 'string', 'children': [], 'value': '"==="'},{'id': '167', 'type': 'with_statement', 'children': ['168', '178']},{'id': '168', 'type': 'with_clause', 'children': ['169']},{'id': '169', 'type': 'with_item', 'children': ['170']},{'id': '170', 'type': 'as_pattern', 'children': ['171', '176']},{'id': '171', 'type': 'call', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '173', 'type': 'argument_list', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'str_fileToSave'},{'id': '175', 'type': 'string', 'children': [], 'value': "'wb'"},{'id': '176', 'type': 'as_pattern_target', 'children': ['177']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '178', 'type': 'block', 'children': ['179', '186']},{'id': '179', 'type': 'expression_statement', 'children': ['180']},{'id': '180', 'type': 'call', 'children': ['181', '184']},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'bytes_decoded'},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'call', 'children': ['188', '191']},{'id': '188', 'type': 'attribute', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '191', 'type': 'argument_list', 'children': []},{'id': '192', 'type': 'return_statement', 'children': ['193']},{'id': '193', 'type': 'dictionary', 'children': ['194', '197', '200']},{'id': '194', 'type': 'pair', 'children': ['195', '196']},{'id': '195', 'type': 'string', 'children': [], 'value': "'msg'"},{'id': '196', 'type': 'string', 'children': [], 'value': "'Decode successful'"},{'id': '197', 'type': 'pair', 'children': ['198', '199']},{'id': '198', 'type': 'string', 'children': [], 'value': "'fileProcessed'"},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'str_fileToSave'},{'id': '200', 'type': 'pair', 'children': ['201', '202']},{'id': '201', 'type': 'string', 'children': [], 'value': "'status'"},{'id': '202', 'type': 'True', 'children': []}
def base64_process(**kwargs): 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 str_action == "encode": 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 } if str_action == "decode": 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 }
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'path_localLocationCheck'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'd_msg'},{'id': '6', 'type': 'dictionary_splat_pattern', 'children': ['7']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '8', 'type': 'block', 'children': ['9', '13', '19', '35', '46', '57', '63', '76', '80', '84', '95', '106', '117', '272', '296']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'b_pull'},{'id': '12', 'type': 'False', 'children': []},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'd_meta'},{'id': '16', 'type': 'subscript', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'd_msg'},{'id': '18', 'type': 'string', 'children': [], 'value': "'meta'"},{'id': '19', 'type': 'if_statement', 'children': ['20', '23']},{'id': '20', 'type': 'comparison_operator', 'children': ['21', '22'], 'value': 'in'},{'id': '21', 'type': 'string', 'children': [], 'value': "'do'"},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'd_meta'},{'id': '23', 'type': 'block', 'children': ['24']},{'id': '24', 'type': 'if_statement', 'children': ['25', '30']},{'id': '25', 'type': 'comparison_operator', 'children': ['26', '29'], 'value': '=='},{'id': '26', 'type': 'subscript', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'd_meta'},{'id': '28', 'type': 'string', 'children': [], 'value': "'do'"},{'id': '29', 'type': 'string', 'children': [], 'value': "'pull'"},{'id': '30', 'type': 'block', 'children': ['31']},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'b_pull'},{'id': '34', 'type': 'True', 'children': []},{'id': '35', 'type': 'if_statement', 'children': ['36', '39']},{'id': '36', 'type': 'comparison_operator', 'children': ['37', '38'], 'value': 'in'},{'id': '37', 'type': 'string', 'children': [], 'value': "'local'"},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'd_meta'},{'id': '39', 'type': 'block', 'children': ['40']},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'd_local'},{'id': '43', 'type': 'subscript', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'd_meta'},{'id': '45', 'type': 'string', 'children': [], 'value': "'local'"},{'id': '46', 'type': 'if_statement', 'children': ['47', '50']},{'id': '47', 'type': 'comparison_operator', 'children': ['48', '49'], 'value': 'in'},{'id': '48', 'type': 'string', 'children': [], 'value': "'to'"},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'd_meta'},{'id': '50', 'type': 'block', 'children': ['51']},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'd_local'},{'id': '54', 'type': 'subscript', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'd_meta'},{'id': '56', 'type': 'string', 'children': [], 'value': "'to'"},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'str_localPathFull'},{'id': '60', 'type': 'subscript', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'd_local'},{'id': '62', 'type': 'string', 'children': [], 'value': "'path'"},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '68']},{'id': '65', 'type': 'pattern_list', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'str_localPath'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'str_unpack'},{'id': '68', 'type': 'call', 'children': ['69', '74']},{'id': '69', 'type': 'attribute', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'str_localPathFull'},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'assignment', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'str_msg'},{'id': '79', 'type': 'string', 'children': [], 'value': "''"},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'str_checkedDir'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'str_localPathFull'},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'b_isFile'},{'id': '87', 'type': 'call', 'children': ['88', '93']},{'id': '88', 'type': 'attribute', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'isfile'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'str_localPathFull'},{'id': '95', 'type': 'expression_statement', 'children': ['96']},{'id': '96', 'type': 'assignment', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'b_isDir'},{'id': '98', 'type': 'call', 'children': ['99', '104']},{'id': '99', 'type': 'attribute', 'children': ['100', '103']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'isdir'},{'id': '104', 'type': 'argument_list', 'children': ['105']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'str_localPathFull'},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'assignment', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'b_exists'},{'id': '109', 'type': 'call', 'children': ['110', '115']},{'id': '110', 'type': 'attribute', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '115', 'type': 'argument_list', 'children': ['116']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'str_localPathFull'},{'id': '117', 'type': 'if_statement', 'children': ['118', '125']},{'id': '118', 'type': 'boolean_operator', 'children': ['119', '124'], 'value': 'or'},{'id': '119', 'type': 'comparison_operator', 'children': ['120', '121'], 'value': 'in'},{'id': '120', 'type': 'string', 'children': [], 'value': "'pull'"},{'id': '121', 'type': 'subscript', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'd_msg'},{'id': '123', 'type': 'string', 'children': [], 'value': "'action'"},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'b_pull'},{'id': '125', 'type': 'block', 'children': ['126', '130', '141', '152', '163']},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'assignment', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'str_checkedDir'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'str_localPath'},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'assignment', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'b_isFile'},{'id': '133', 'type': 'call', 'children': ['134', '139']},{'id': '134', 'type': 'attribute', 'children': ['135', '138']},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'isfile'},{'id': '139', 'type': 'argument_list', 'children': ['140']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'str_localPath'},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'assignment', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'b_isDir'},{'id': '144', 'type': 'call', 'children': ['145', '150']},{'id': '145', 'type': 'attribute', 'children': ['146', '149']},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'isdir'},{'id': '150', 'type': 'argument_list', 'children': ['151']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'str_localPath'},{'id': '152', 'type': 'expression_statement', 'children': ['153']},{'id': '153', 'type': 'assignment', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'b_exists'},{'id': '155', 'type': 'call', 'children': ['156', '161']},{'id': '156', 'type': 'attribute', 'children': ['157', '160']},{'id': '157', 'type': 'attribute', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '161', 'type': 'argument_list', 'children': ['162']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'str_localPath'},{'id': '163', 'type': 'if_statement', 'children': ['164', '171', '235']},{'id': '164', 'type': 'comparison_operator', 'children': ['165', '166'], 'value': 'in'},{'id': '165', 'type': 'string', 'children': [], 'value': "'createDir'"},{'id': '166', 'type': 'call', 'children': ['167', '170']},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'd_local'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '170', 'type': 'argument_list', 'children': []},{'id': '171', 'type': 'block', 'children': ['172']},{'id': '172', 'type': 'if_statement', 'children': ['173', '176']},{'id': '173', 'type': 'subscript', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'd_local'},{'id': '175', 'type': 'string', 'children': [], 'value': "'createDir'"},{'id': '176', 'type': 'block', 'children': ['177', '209', '220', '227', '231']},{'id': '177', 'type': 'if_statement', 'children': ['178', '186']},{'id': '178', 'type': 'call', 'children': ['179', '184']},{'id': '179', 'type': 'attribute', 'children': ['180', '183']},{'id': '180', 'type': 'attribute', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'isdir'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'str_localPathFull'},{'id': '186', 'type': 'block', 'children': ['187', '198', '205']},{'id': '187', 'type': 'expression_statement', 'children': ['188']},{'id': '188', 'type': 'call', 'children': ['189', '194']},{'id': '189', 'type': 'attribute', 'children': ['190', '193']},{'id': '190', 'type': 'attribute', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'dp'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'qprint'},{'id': '194', 'type': 'argument_list', 'children': ['195']},{'id': '195', 'type': 'binary_operator', 'children': ['196', '197'], 'value': '%'},{'id': '196', 'type': 'string', 'children': [], 'value': "'Removing local path %s...'"},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'str_localPathFull'},{'id': '198', 'type': 'expression_statement', 'children': ['199']},{'id': '199', 'type': 'call', 'children': ['200', '203']},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'shutil'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'rmtree'},{'id': '203', 'type': 'argument_list', 'children': ['204']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'str_localPathFull'},{'id': '205', 'type': 'expression_statement', 'children': ['206']},{'id': '206', 'type': 'assignment', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'str_msg'},{'id': '208', 'type': 'string', 'children': [], 'value': "'Removed existing local path... '"},{'id': '209', 'type': 'expression_statement', 'children': ['210']},{'id': '210', 'type': 'call', 'children': ['211', '216']},{'id': '211', 'type': 'attribute', 'children': ['212', '215']},{'id': '212', 'type': 'attribute', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'dp'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'qprint'},{'id': '216', 'type': 'argument_list', 'children': ['217']},{'id': '217', 'type': 'binary_operator', 'children': ['218', '219'], 'value': '%'},{'id': '218', 'type': 'string', 'children': [], 'value': "'Creating empty local path %s...'"},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'str_localPathFull'},{'id': '220', 'type': 'expression_statement', 'children': ['221']},{'id': '221', 'type': 'call', 'children': ['222', '225']},{'id': '222', 'type': 'attribute', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'makedirs'},{'id': '225', 'type': 'argument_list', 'children': ['226']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'str_localPathFull'},{'id': '227', 'type': 'expression_statement', 'children': ['228']},{'id': '228', 'type': 'assignment', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'b_exists'},{'id': '230', 'type': 'True', 'children': []},{'id': '231', 'type': 'expression_statement', 'children': ['232']},{'id': '232', 'type': 'augmented_assignment', 'children': ['233', '234'], 'value': '+='},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'str_msg'},{'id': '234', 'type': 'string', 'children': [], 'value': "'Created new local path'"},{'id': '235', 'type': 'else_clause', 'children': ['236']},{'id': '236', 'type': 'block', 'children': ['237', '241']},{'id': '237', 'type': 'expression_statement', 'children': ['238']},{'id': '238', 'type': 'assignment', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'str_msg'},{'id': '240', 'type': 'string', 'children': [], 'value': "'local path already exists!'"},{'id': '241', 'type': 'if_statement', 'children': ['242', '249', '263']},{'id': '242', 'type': 'comparison_operator', 'children': ['243', '244'], 'value': 'in'},{'id': '243', 'type': 'string', 'children': [], 'value': "'writeInExisting'"},{'id': '244', 'type': 'call', 'children': ['245', '248']},{'id': '245', 'type': 'attribute', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'd_local'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '248', 'type': 'argument_list', 'children': []},{'id': '249', 'type': 'block', 'children': ['250']},{'id': '250', 'type': 'if_statement', 'children': ['251', '255']},{'id': '251', 'type': 'not_operator', 'children': ['252']},{'id': '252', 'type': 'subscript', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'd_local'},{'id': '254', 'type': 'string', 'children': [], 'value': "'writeInExisting'"},{'id': '255', 'type': 'block', 'children': ['256']},{'id': '256', 'type': 'if_statement', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'b_isDir'},{'id': '258', 'type': 'block', 'children': ['259']},{'id': '259', 'type': 'expression_statement', 'children': ['260']},{'id': '260', 'type': 'assignment', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'b_exists'},{'id': '262', 'type': 'False', 'children': []},{'id': '263', 'type': 'else_clause', 'children': ['264']},{'id': '264', 'type': 'block', 'children': ['265']},{'id': '265', 'type': 'if_statement', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'b_isDir'},{'id': '267', 'type': 'block', 'children': ['268']},{'id': '268', 'type': 'expression_statement', 'children': ['269']},{'id': '269', 'type': 'assignment', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'b_exists'},{'id': '271', 'type': 'False', 'children': []},{'id': '272', 'type': 'expression_statement', 'children': ['273']},{'id': '273', 'type': 'assignment', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'd_ret'},{'id': '275', 'type': 'dictionary', 'children': ['276', '281', '284', '287', '290', '293']},{'id': '276', 'type': 'pair', 'children': ['277', '278']},{'id': '277', 'type': 'string', 'children': [], 'value': "'action'"},{'id': '278', 'type': 'subscript', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'd_msg'},{'id': '280', 'type': 'string', 'children': [], 'value': "'action'"},{'id': '281', 'type': 'pair', 'children': ['282', '283']},{'id': '282', 'type': 'string', 'children': [], 'value': "'dir'"},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'str_checkedDir'},{'id': '284', 'type': 'pair', 'children': ['285', '286']},{'id': '285', 'type': 'string', 'children': [], 'value': "'status'"},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'b_exists'},{'id': '287', 'type': 'pair', 'children': ['288', '289']},{'id': '288', 'type': 'string', 'children': [], 'value': "'isfile'"},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'b_isFile'},{'id': '290', 'type': 'pair', 'children': ['291', '292']},{'id': '291', 'type': 'string', 'children': [], 'value': "'isdir'"},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'b_isDir'},{'id': '293', 'type': 'pair', 'children': ['294', '295']},{'id': '294', 'type': 'string', 'children': [], 'value': "'msg'"},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'str_msg'},{'id': '296', 'type': 'return_statement', 'children': ['297']},{'id': '297', 'type': 'dictionary', 'children': ['298', '301', '306']},{'id': '298', 'type': 'pair', 'children': ['299', '300']},{'id': '299', 'type': 'string', 'children': [], 'value': "'check'"},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'd_ret'},{'id': '301', 'type': 'pair', 'children': ['302', '303']},{'id': '302', 'type': 'string', 'children': [], 'value': "'status'"},{'id': '303', 'type': 'subscript', 'children': ['304', '305']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'd_ret'},{'id': '305', 'type': 'string', 'children': [], 'value': "'status'"},{'id': '306', 'type': 'pair', 'children': ['307', '308']},{'id': '307', 'type': 'string', 'children': [], 'value': "'timestamp'"},{'id': '308', 'type': 'binary_operator', 'children': ['309', '310'], 'value': '%'},{'id': '309', 'type': 'string', 'children': [], 'value': "'%s'"},{'id': '310', 'type': 'call', 'children': ['311', '316']},{'id': '311', 'type': 'attribute', 'children': ['312', '315']},{'id': '312', 'type': 'attribute', 'children': ['313', '314']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '316', 'type': 'argument_list', 'children': []}
def path_localLocationCheck(self, d_msg, **kwargs): 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: 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()}
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'rebuild'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '14', '25', '87', '115', '122', '130', '138', '156', '162', '342', '349']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '9', 'type': 'call', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'tableType'},{'id': '13', 'type': 'argument_list', 'children': []},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'form'},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'nativestring'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'filterFormat'},{'id': '24', 'type': 'argument_list', 'children': []},{'id': '25', 'type': 'if_statement', 'children': ['26', '30', '82']},{'id': '26', 'type': 'boolean_operator', 'children': ['27', '29'], 'value': 'and'},{'id': '27', 'type': 'not_operator', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'form'},{'id': '30', 'type': 'block', 'children': ['31', '81']},{'id': '31', 'type': 'if_statement', 'children': ['32', '43', '59']},{'id': '32', 'type': 'comparison_operator', 'children': ['33', '42'], 'value': '=='},{'id': '33', 'type': 'call', 'children': ['34', '41']},{'id': '34', 'type': 'attribute', 'children': ['35', '40']},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'layout'},{'id': '39', 'type': 'argument_list', 'children': []},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '41', 'type': 'argument_list', 'children': []},{'id': '42', 'type': 'integer', 'children': [], 'value': '0'},{'id': '43', 'type': 'block', 'children': ['44']},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'call', 'children': ['46', '53']},{'id': '46', 'type': 'attribute', 'children': ['47', '52']},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'layout'},{'id': '51', 'type': 'argument_list', 'children': []},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'addWidget'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'QLabel'},{'id': '56', 'type': 'argument_list', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'form'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '59', 'type': 'else_clause', 'children': ['60']},{'id': '60', 'type': 'block', 'children': ['61']},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'call', 'children': ['63', '79']},{'id': '63', 'type': 'attribute', 'children': ['64', '78']},{'id': '64', 'type': 'call', 'children': ['65', '77']},{'id': '65', 'type': 'attribute', 'children': ['66', '76']},{'id': '66', 'type': 'call', 'children': ['67', '74']},{'id': '67', 'type': 'attribute', 'children': ['68', '73']},{'id': '68', 'type': 'call', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'layout'},{'id': '72', 'type': 'argument_list', 'children': []},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'itemAt'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'integer', 'children': [], 'value': '0'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'widget'},{'id': '77', 'type': 'argument_list', 'children': []},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'setText'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'form'},{'id': '81', 'type': 'return_statement', 'children': []},{'id': '82', 'type': 'elif_clause', 'children': ['83', '85']},{'id': '83', 'type': 'not_operator', 'children': ['84']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'form'},{'id': '85', 'type': 'block', 'children': ['86']},{'id': '86', 'type': 'return_statement', 'children': []},{'id': '87', 'type': 'for_statement', 'children': ['88', '89', '95']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '89', 'type': 'call', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'findChildren'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'QWidget'},{'id': '95', 'type': 'block', 'children': ['96', '102', '109']},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'call', 'children': ['98', '101']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '101', 'type': 'argument_list', 'children': []},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'call', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'setParent'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'None', 'children': []},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'call', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'deleteLater'},{'id': '114', 'type': 'argument_list', 'children': []},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'call', 'children': ['117', '120']},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'setUpdatesEnabled'},{'id': '120', 'type': 'argument_list', 'children': ['121']},{'id': '121', 'type': 'False', 'children': []},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'assignment', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '125', 'type': 'call', 'children': ['126', '129']},{'id': '126', 'type': 'attribute', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '129', 'type': 'argument_list', 'children': []},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'assignment', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'vlayout'},{'id': '133', 'type': 'call', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'layout'},{'id': '137', 'type': 'argument_list', 'children': []},{'id': '138', 'type': 'for_statement', 'children': ['139', '140', '148']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '140', 'type': 'call', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '142', 'type': 'argument_list', 'children': ['143']},{'id': '143', 'type': 'call', 'children': ['144', '147']},{'id': '144', 'type': 'attribute', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'vlayout'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '147', 'type': 'argument_list', 'children': []},{'id': '148', 'type': 'block', 'children': ['149']},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'call', 'children': ['151', '154']},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'vlayout'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'takeAt'},{'id': '154', 'type': 'argument_list', 'children': ['155']},{'id': '155', 'type': 'integer', 'children': [], 'value': '0'},{'id': '156', 'type': 'expression_statement', 'children': ['157']},{'id': '157', 'type': 'assignment', 'children': ['158', '161']},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '160', 'type': 'identifier', 'children': [], 'value': '_plugins'},{'id': '161', 'type': 'list', 'children': [], 'value': '[]'},{'id': '162', 'type': 'for_statement', 'children': ['163', '164', '170']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '164', 'type': 'call', 'children': ['165', '168']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'form'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '168', 'type': 'argument_list', 'children': ['169']},{'id': '169', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '170', 'type': 'block', 'children': ['171', '177', '187', '194', '328', '335']},{'id': '171', 'type': 'expression_statement', 'children': ['172']},{'id': '172', 'type': 'assignment', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '174', 'type': 'call', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'QHBoxLayout'},{'id': '176', 'type': 'argument_list', 'children': []},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'call', 'children': ['179', '182']},{'id': '179', 'type': 'attribute', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'setContentsMargins'},{'id': '182', 'type': 'argument_list', 'children': ['183', '184', '185', '186']},{'id': '183', 'type': 'integer', 'children': [], 'value': '0'},{'id': '184', 'type': 'integer', 'children': [], 'value': '0'},{'id': '185', 'type': 'integer', 'children': [], 'value': '0'},{'id': '186', 'type': 'integer', 'children': [], 'value': '0'},{'id': '187', 'type': 'expression_statement', 'children': ['188']},{'id': '188', 'type': 'call', 'children': ['189', '192']},{'id': '189', 'type': 'attribute', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'setSpacing'},{'id': '192', 'type': 'argument_list', 'children': ['193']},{'id': '193', 'type': 'integer', 'children': [], 'value': '0'},{'id': '194', 'type': 'for_statement', 'children': ['195', '198', '204']},{'id': '195', 'type': 'pattern_list', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'lookup'},{'id': '198', 'type': 'call', 'children': ['199', '202']},{'id': '199', 'type': 'attribute', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'FORMAT_SPLITTER'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'findall'},{'id': '202', 'type': 'argument_list', 'children': ['203']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '204', 'type': 'block', 'children': ['205', '213', '220', '229', '244', '255', '260', '273', '278', '292']},{'id': '205', 'type': 'expression_statement', 'children': ['206']},{'id': '206', 'type': 'assignment', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'lbl'},{'id': '208', 'type': 'call', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'QLabel'},{'id': '210', 'type': 'argument_list', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '213', 'type': 'expression_statement', 'children': ['214']},{'id': '214', 'type': 'call', 'children': ['215', '218']},{'id': '215', 'type': 'attribute', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'addWidget'},{'id': '218', 'type': 'argument_list', 'children': ['219']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'lbl'},{'id': '220', 'type': 'expression_statement', 'children': ['221']},{'id': '221', 'type': 'assignment', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'opts'},{'id': '223', 'type': 'call', 'children': ['224', '227']},{'id': '224', 'type': 'attribute', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'lookup'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '227', 'type': 'argument_list', 'children': ['228']},{'id': '228', 'type': 'string', 'children': [], 'value': "':'"},{'id': '229', 'type': 'if_statement', 'children': ['230', '236']},{'id': '230', 'type': 'comparison_operator', 'children': ['231', '235'], 'value': '=='},{'id': '231', 'type': 'call', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '233', 'type': 'argument_list', 'children': ['234']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'opts'},{'id': '235', 'type': 'integer', 'children': [], 'value': '1'},{'id': '236', 'type': 'block', 'children': ['237']},{'id': '237', 'type': 'expression_statement', 'children': ['238']},{'id': '238', 'type': 'call', 'children': ['239', '242']},{'id': '239', 'type': 'attribute', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'opts'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '242', 'type': 'argument_list', 'children': ['243']},{'id': '243', 'type': 'string', 'children': [], 'value': "'is'"},{'id': '244', 'type': 'expression_statement', 'children': ['245']},{'id': '245', 'type': 'assignment', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '247', 'type': 'call', 'children': ['248', '251']},{'id': '248', 'type': 'attribute', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '251', 'type': 'argument_list', 'children': ['252']},{'id': '252', 'type': 'subscript', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'opts'},{'id': '254', 'type': 'integer', 'children': [], 'value': '0'},{'id': '255', 'type': 'if_statement', 'children': ['256', '258']},{'id': '256', 'type': 'not_operator', 'children': ['257']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '258', 'type': 'block', 'children': ['259']},{'id': '259', 'type': 'continue_statement', 'children': []},{'id': '260', 'type': 'expression_statement', 'children': ['261']},{'id': '261', 'type': 'assignment', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'plugin'},{'id': '263', 'type': 'call', 'children': ['264', '271']},{'id': '264', 'type': 'attribute', 'children': ['265', '270']},{'id': '265', 'type': 'call', 'children': ['266', '269']},{'id': '266', 'type': 'attribute', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'pluginFactory'},{'id': '269', 'type': 'argument_list', 'children': []},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'plugin'},{'id': '271', 'type': 'argument_list', 'children': ['272']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '273', 'type': 'if_statement', 'children': ['274', '276']},{'id': '274', 'type': 'not_operator', 'children': ['275']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'plugin'},{'id': '276', 'type': 'block', 'children': ['277']},{'id': '277', 'type': 'continue_statement', 'children': []},{'id': '278', 'type': 'expression_statement', 'children': ['279']},{'id': '279', 'type': 'assignment', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'editor'},{'id': '281', 'type': 'call', 'children': ['282', '285']},{'id': '282', 'type': 'attribute', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'plugin'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'createEditor'},{'id': '285', 'type': 'argument_list', 'children': ['286', '287', '288', '291']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '288', 'type': 'subscript', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'opts'},{'id': '290', 'type': 'integer', 'children': [], 'value': '1'},{'id': '291', 'type': 'None', 'children': []},{'id': '292', 'type': 'if_statement', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'editor'},{'id': '294', 'type': 'block', 'children': ['295', '304', '311']},{'id': '295', 'type': 'expression_statement', 'children': ['296']},{'id': '296', 'type': 'call', 'children': ['297', '300']},{'id': '297', 'type': 'attribute', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'editor'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'setObjectName'},{'id': '300', 'type': 'argument_list', 'children': ['301']},{'id': '301', 'type': 'subscript', 'children': ['302', '303']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'opts'},{'id': '303', 'type': 'integer', 'children': [], 'value': '0'},{'id': '304', 'type': 'expression_statement', 'children': ['305']},{'id': '305', 'type': 'call', 'children': ['306', '309']},{'id': '306', 'type': 'attribute', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'addWidget'},{'id': '309', 'type': 'argument_list', 'children': ['310']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'editor'},{'id': '311', 'type': 'expression_statement', 'children': ['312']},{'id': '312', 'type': 'call', 'children': ['313', '318']},{'id': '313', 'type': 'attribute', 'children': ['314', '317']},{'id': '314', 'type': 'attribute', 'children': ['315', '316']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '316', 'type': 'identifier', 'children': [], 'value': '_plugins'},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '318', 'type': 'argument_list', 'children': ['319']},{'id': '319', 'type': 'tuple', 'children': ['320', '323', '326', '327']},{'id': '320', 'type': 'subscript', 'children': ['321', '322']},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'opts'},{'id': '322', 'type': 'integer', 'children': [], 'value': '0'},{'id': '323', 'type': 'subscript', 'children': ['324', '325']},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'opts'},{'id': '325', 'type': 'integer', 'children': [], 'value': '1'},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'plugin'},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'editor'},{'id': '328', 'type': 'expression_statement', 'children': ['329']},{'id': '329', 'type': 'call', 'children': ['330', '333']},{'id': '330', 'type': 'attribute', 'children': ['331', '332']},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'addStretch'},{'id': '333', 'type': 'argument_list', 'children': ['334']},{'id': '334', 'type': 'integer', 'children': [], 'value': '1'},{'id': '335', 'type': 'expression_statement', 'children': ['336']},{'id': '336', 'type': 'call', 'children': ['337', '340']},{'id': '337', 'type': 'attribute', 'children': ['338', '339']},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'vlayout'},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'addLayout'},{'id': '340', 'type': 'argument_list', 'children': ['341']},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '342', 'type': 'expression_statement', 'children': ['343']},{'id': '343', 'type': 'call', 'children': ['344', '347']},{'id': '344', 'type': 'attribute', 'children': ['345', '346']},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'setUpdatesEnabled'},{'id': '347', 'type': 'argument_list', 'children': ['348']},{'id': '348', 'type': 'True', 'children': []},{'id': '349', 'type': 'expression_statement', 'children': ['350']},{'id': '350', 'type': 'call', 'children': ['351', '354']},{'id': '351', 'type': 'attribute', 'children': ['352', '353']},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'adjustSize'},{'id': '354', 'type': 'argument_list', 'children': []}
def rebuild(self): 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): lbl = QLabel(label, self) row.addWidget(lbl) 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()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'filters'},{'id': '3', 'type': 'parameters', 'children': ['4', '7', '10', '13']},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'filter_directory'},{'id': '6', 'type': 'None', 'children': []},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '9', 'type': 'False', 'children': []},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'fmt'},{'id': '12', 'type': 'string', 'children': [], 'value': "'table'"},{'id': '13', 'type': 'dictionary_splat_pattern', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '15', 'type': 'block', 'children': ['16', '29', '41', '45', '68', '272', '276', '307']},{'id': '16', 'type': 'if_statement', 'children': ['17', '20']},{'id': '17', 'type': 'comparison_operator', 'children': ['18', '19'], 'value': 'is'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'filter_directory'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'block', 'children': ['21']},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'filter_directory'},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'resource_filename'},{'id': '26', 'type': 'argument_list', 'children': ['27', '28']},{'id': '27', 'type': 'string', 'children': [], 'value': "'svo_filters'"},{'id': '28', 'type': 'string', 'children': [], 'value': "'data/filters/'"},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'p_path'},{'id': '32', 'type': 'call', 'children': ['33', '38']},{'id': '33', 'type': 'attribute', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '38', 'type': 'argument_list', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'filter_directory'},{'id': '40', 'type': 'string', 'children': [], 'value': "'filter_list.p'"},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'updated'},{'id': '44', 'type': 'False', 'children': []},{'id': '45', 'type': 'if_statement', 'children': ['46', '55']},{'id': '46', 'type': 'not_operator', 'children': ['47']},{'id': '47', 'type': 'call', 'children': ['48', '53']},{'id': '48', 'type': 'attribute', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'isfile'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'p_path'},{'id': '55', 'type': 'block', 'children': ['56']},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'call', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'system'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'call', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'string', 'children': [], 'value': "'touch {}'"},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'p_path'},{'id': '68', 'type': 'if_statement', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '70', 'type': 'block', 'children': ['71', '76', '85', '101', '116', '120', '247']},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'call', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'string', 'children': [], 'value': "'Loading filters into table...'"},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'assignment', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '79', 'type': 'call', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'glob'},{'id': '81', 'type': 'argument_list', 'children': ['82']},{'id': '82', 'type': 'binary_operator', 'children': ['83', '84'], 'value': '+'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'filter_directory'},{'id': '84', 'type': 'string', 'children': [], 'value': "'*'"},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'assignment', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '88', 'type': 'list_comprehension', 'children': ['89', '90', '93']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '90', 'type': 'for_in_clause', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '93', 'type': 'if_clause', 'children': ['94']},{'id': '94', 'type': 'not_operator', 'children': ['95']},{'id': '95', 'type': 'call', 'children': ['96', '99']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'endswith'},{'id': '99', 'type': 'argument_list', 'children': ['100']},{'id': '100', 'type': 'string', 'children': [], 'value': "'.p'"},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'assignment', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'bands'},{'id': '104', 'type': 'list_comprehension', 'children': ['105', '113']},{'id': '105', 'type': 'call', 'children': ['106', '111']},{'id': '106', 'type': 'attribute', 'children': ['107', '110']},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '111', 'type': 'argument_list', 'children': ['112']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '113', 'type': 'for_in_clause', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'assignment', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'tables'},{'id': '119', 'type': 'list', 'children': [], 'value': '[]'},{'id': '120', 'type': 'for_statement', 'children': ['121', '122', '123']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'band'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'bands'},{'id': '123', 'type': 'block', 'children': ['124', '134', '143', '149', '158', '196', '212', '235', '242']},{'id': '124', 'type': 'expression_statement', 'children': ['125']},{'id': '125', 'type': 'assignment', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'band'},{'id': '127', 'type': 'call', 'children': ['128', '131']},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'band'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '131', 'type': 'argument_list', 'children': ['132', '133']},{'id': '132', 'type': 'string', 'children': [], 'value': "'.txt'"},{'id': '133', 'type': 'string', 'children': [], 'value': "''"},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'assignment', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'filt'},{'id': '137', 'type': 'call', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'Filter'},{'id': '139', 'type': 'argument_list', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'band'},{'id': '141', 'type': 'dictionary_splat', 'children': ['142']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'assignment', 'children': ['145', '148']},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'filt'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'Band'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'band'},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'assignment', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '152', 'type': 'call', 'children': ['153', '156']},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'filt'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '156', 'type': 'argument_list', 'children': ['157']},{'id': '157', 'type': 'True', 'children': []},{'id': '158', 'type': 'expression_statement', 'children': ['159']},{'id': '159', 'type': 'assignment', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'vals'},{'id': '161', 'type': 'list_comprehension', 'children': ['162', '191']},{'id': '162', 'type': 'conditional_expression', 'children': ['163', '167', '190'], 'value': 'if'},{'id': '163', 'type': 'call', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '165', 'type': 'argument_list', 'children': ['166']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '167', 'type': 'call', 'children': ['168', '189']},{'id': '168', 'type': 'attribute', 'children': ['169', '188']},{'id': '169', 'type': 'call', 'children': ['170', '185']},{'id': '170', 'type': 'attribute', 'children': ['171', '184']},{'id': '171', 'type': 'call', 'children': ['172', '181']},{'id': '172', 'type': 'attribute', 'children': ['173', '180']},{'id': '173', 'type': 'call', 'children': ['174', '177']},{'id': '174', 'type': 'attribute', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '177', 'type': 'argument_list', 'children': ['178', '179']},{'id': '178', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '179', 'type': 'string', 'children': [], 'value': "''"},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '181', 'type': 'argument_list', 'children': ['182', '183']},{'id': '182', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '183', 'type': 'string', 'children': [], 'value': "''"},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '185', 'type': 'argument_list', 'children': ['186', '187']},{'id': '186', 'type': 'string', 'children': [], 'value': "'+'"},{'id': '187', 'type': 'string', 'children': [], 'value': "''"},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'isnumeric'},{'id': '189', 'type': 'argument_list', 'children': []},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '191', 'type': 'for_in_clause', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '193', 'type': 'subscript', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '195', 'type': 'string', 'children': [], 'value': "'Values'"},{'id': '196', 'type': 'expression_statement', 'children': ['197']},{'id': '197', 'type': 'assignment', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'dtypes'},{'id': '199', 'type': 'call', 'children': ['200', '203']},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '203', 'type': 'argument_list', 'children': ['204']},{'id': '204', 'type': 'list_comprehension', 'children': ['205', '209']},{'id': '205', 'type': 'call', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '207', 'type': 'argument_list', 'children': ['208']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '209', 'type': 'for_in_clause', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'vals'},{'id': '212', 'type': 'expression_statement', 'children': ['213']},{'id': '213', 'type': 'assignment', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '215', 'type': 'call', 'children': ['216', '219']},{'id': '216', 'type': 'attribute', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'at'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'Table'},{'id': '219', 'type': 'argument_list', 'children': ['220', '227', '232']},{'id': '220', 'type': 'call', 'children': ['221', '224']},{'id': '221', 'type': 'attribute', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '224', 'type': 'argument_list', 'children': ['225']},{'id': '225', 'type': 'list', 'children': ['226'], 'value': '[vals]'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'vals'},{'id': '227', 'type': 'keyword_argument', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '229', 'type': 'subscript', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '231', 'type': 'string', 'children': [], 'value': "'Attributes'"},{'id': '232', 'type': 'keyword_argument', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'dtypes'},{'id': '235', 'type': 'expression_statement', 'children': ['236']},{'id': '236', 'type': 'call', 'children': ['237', '240']},{'id': '237', 'type': 'attribute', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'tables'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '240', 'type': 'argument_list', 'children': ['241']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '242', 'type': 'delete_statement', 'children': ['243']},{'id': '243', 'type': 'expression_list', 'children': ['244', '245', '246']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'filt'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '247', 'type': 'with_statement', 'children': ['248', '258']},{'id': '248', 'type': 'with_clause', 'children': ['249']},{'id': '249', 'type': 'with_item', 'children': ['250']},{'id': '250', 'type': 'as_pattern', 'children': ['251', '256']},{'id': '251', 'type': 'call', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '253', 'type': 'argument_list', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'p_path'},{'id': '255', 'type': 'string', 'children': [], 'value': "'wb'"},{'id': '256', 'type': 'as_pattern_target', 'children': ['257']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '258', 'type': 'block', 'children': ['259']},{'id': '259', 'type': 'expression_statement', 'children': ['260']},{'id': '260', 'type': 'call', 'children': ['261', '264']},{'id': '261', 'type': 'attribute', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'pickle'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'dump'},{'id': '264', 'type': 'argument_list', 'children': ['265', '271']},{'id': '265', 'type': 'call', 'children': ['266', '269']},{'id': '266', 'type': 'attribute', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'at'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'vstack'},{'id': '269', 'type': 'argument_list', 'children': ['270']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'tables'},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '272', 'type': 'expression_statement', 'children': ['273']},{'id': '273', 'type': 'assignment', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '275', 'type': 'dictionary', 'children': []},{'id': '276', 'type': 'if_statement', 'children': ['277', '285']},{'id': '277', 'type': 'call', 'children': ['278', '283']},{'id': '278', 'type': 'attribute', 'children': ['279', '282']},{'id': '279', 'type': 'attribute', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'isfile'},{'id': '283', 'type': 'argument_list', 'children': ['284']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'p_path'},{'id': '285', 'type': 'block', 'children': ['286']},{'id': '286', 'type': 'with_statement', 'children': ['287', '297']},{'id': '287', 'type': 'with_clause', 'children': ['288']},{'id': '288', 'type': 'with_item', 'children': ['289']},{'id': '289', 'type': 'as_pattern', 'children': ['290', '295']},{'id': '290', 'type': 'call', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '292', 'type': 'argument_list', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'p_path'},{'id': '294', 'type': 'string', 'children': [], 'value': "'rb'"},{'id': '295', 'type': 'as_pattern_target', 'children': ['296']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '297', 'type': 'block', 'children': ['298']},{'id': '298', 'type': 'expression_statement', 'children': ['299']},{'id': '299', 'type': 'assignment', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '301', 'type': 'call', 'children': ['302', '305']},{'id': '302', 'type': 'attribute', 'children': ['303', '304']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'pickle'},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'load'},{'id': '305', 'type': 'argument_list', 'children': ['306']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '307', 'type': 'if_statement', 'children': ['308', '309', '367']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '309', 'type': 'block', 'children': ['310', '365']},{'id': '310', 'type': 'if_statement', 'children': ['311', '314', '356']},{'id': '311', 'type': 'comparison_operator', 'children': ['312', '313'], 'value': '=='},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'fmt'},{'id': '313', 'type': 'string', 'children': [], 'value': "'dict'"},{'id': '314', 'type': 'block', 'children': ['315']},{'id': '315', 'type': 'expression_statement', 'children': ['316']},{'id': '316', 'type': 'assignment', 'children': ['317', '318']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '318', 'type': 'dictionary_comprehension', 'children': ['319', '353']},{'id': '319', 'type': 'pair', 'children': ['320', '323']},{'id': '320', 'type': 'subscript', 'children': ['321', '322']},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '322', 'type': 'integer', 'children': [], 'value': '0'},{'id': '323', 'type': 'dictionary_comprehension', 'children': ['324', '342']},{'id': '324', 'type': 'pair', 'children': ['325', '326']},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '326', 'type': 'conditional_expression', 'children': ['327', '332', '339'], 'value': 'if'},{'id': '327', 'type': 'attribute', 'children': ['328', '331']},{'id': '328', 'type': 'subscript', 'children': ['329', '330']},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '332', 'type': 'call', 'children': ['333', '334']},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '334', 'type': 'argument_list', 'children': ['335', '338']},{'id': '335', 'type': 'subscript', 'children': ['336', '337']},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '338', 'type': 'string', 'children': [], 'value': "'unit'"},{'id': '339', 'type': 'subscript', 'children': ['340', '341']},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '342', 'type': 'for_in_clause', 'children': ['343', '344']},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '344', 'type': 'subscript', 'children': ['345', '350']},{'id': '345', 'type': 'call', 'children': ['346', '349']},{'id': '346', 'type': 'attribute', 'children': ['347', '348']},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '349', 'type': 'argument_list', 'children': []},{'id': '350', 'type': 'slice', 'children': ['351', '352']},{'id': '351', 'type': 'integer', 'children': [], 'value': '1'},{'id': '352', 'type': 'colon', 'children': []},{'id': '353', 'type': 'for_in_clause', 'children': ['354', '355']},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '356', 'type': 'else_clause', 'children': ['357']},{'id': '357', 'type': 'block', 'children': ['358']},{'id': '358', 'type': 'expression_statement', 'children': ['359']},{'id': '359', 'type': 'call', 'children': ['360', '363']},{'id': '360', 'type': 'attribute', 'children': ['361', '362']},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '362', 'type': 'identifier', 'children': [], 'value': 'add_index'},{'id': '363', 'type': 'argument_list', 'children': ['364']},{'id': '364', 'type': 'string', 'children': [], 'value': "'Band'"},{'id': '365', 'type': 'return_statement', 'children': ['366']},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '367', 'type': 'else_clause', 'children': ['368']},{'id': '368', 'type': 'block', 'children': ['369']},{'id': '369', 'type': 'if_statement', 'children': ['370', '372', '384']},{'id': '370', 'type': 'not_operator', 'children': ['371']},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'updated'},{'id': '372', 'type': 'block', 'children': ['373', '377']},{'id': '373', 'type': 'expression_statement', 'children': ['374']},{'id': '374', 'type': 'assignment', 'children': ['375', '376']},{'id': '375', 'type': 'identifier', 'children': [], 'value': 'updated'},{'id': '376', 'type': 'True', 'children': []},{'id': '377', 'type': 'expression_statement', 'children': ['378']},{'id': '378', 'type': 'call', 'children': ['379', '380']},{'id': '379', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '380', 'type': 'argument_list', 'children': ['381']},{'id': '381', 'type': 'keyword_argument', 'children': ['382', '383']},{'id': '382', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '383', 'type': 'True', 'children': []},{'id': '384', 'type': 'else_clause', 'children': ['385']},{'id': '385', 'type': 'block', 'children': ['386']},{'id': '386', 'type': 'expression_statement', 'children': ['387']},{'id': '387', 'type': 'call', 'children': ['388', '389']},{'id': '388', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '389', 'type': 'argument_list', 'children': ['390', '391']},{'id': '390', 'type': 'string', 'children': [], 'value': "'No filters found in'"},{'id': '391', 'type': 'identifier', 'children': [], 'value': 'filter_directory'}
def filters(filter_directory=None, update=False, fmt='table', **kwargs): if filter_directory is None: filter_directory = resource_filename('svo_filters', 'data/filters/') 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...') 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: band = band.replace('.txt', '') filt = Filter(band, **kwargs) filt.Band = band 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 with open(p_path, 'wb') as file: pickle.dump(at.vstack(tables), file) data = {} if os.path.isfile(p_path): with open(p_path, 'rb') as file: data = pickle.load(file) 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: data.add_index('Band') return data else: if not updated: updated = True filters(update=True) else: print('No filters found in', filter_directory)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse_unit'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'dictionary'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'dt'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '12', '35', '51', '78', '123', '134']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'string', 'children': [], 'value': "'''Do a fuzzy match for `prop` in the dictionary, taking into account unit suffix.'''"},{'id': '12', 'type': 'try_statement', 'children': ['13', '28']},{'id': '13', 'type': 'block', 'children': ['14']},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'dt'},{'id': '17', 'type': 'call', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'timezone'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'parse_datetime'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'call', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'dictionary'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'string', 'children': [], 'value': "'date_time'"},{'id': '28', 'type': 'except_clause', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '30', 'type': 'block', 'children': ['31']},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'dt'},{'id': '34', 'type': 'None', 'children': []},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'matches'},{'id': '38', 'type': 'list_comprehension', 'children': ['39', '40', '47']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '40', 'type': 'for_in_clause', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '42', 'type': 'call', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'dictionary'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '46', 'type': 'argument_list', 'children': []},{'id': '47', 'type': 'if_clause', 'children': ['48']},{'id': '48', 'type': 'comparison_operator', 'children': ['49', '50'], 'value': 'in'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '51', 'type': 'try_statement', 'children': ['52', '73']},{'id': '52', 'type': 'block', 'children': ['53', '61']},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '56', 'type': 'subscript', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'dictionary'},{'id': '58', 'type': 'subscript', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'matches'},{'id': '60', 'type': 'integer', 'children': [], 'value': '0'},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'unit'},{'id': '64', 'type': 'call', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '68', 'type': 'argument_list', 'children': ['69', '70']},{'id': '69', 'type': 'string', 'children': [], 'value': "r' \\(([^)]+)\\)'"},{'id': '70', 'type': 'subscript', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'matches'},{'id': '72', 'type': 'integer', 'children': [], 'value': '0'},{'id': '73', 'type': 'except_clause', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'IndexError'},{'id': '75', 'type': 'block', 'children': ['76']},{'id': '76', 'type': 'return_statement', 'children': ['77']},{'id': '77', 'type': 'None', 'children': []},{'id': '78', 'type': 'if_statement', 'children': ['79', '82']},{'id': '79', 'type': 'comparison_operator', 'children': ['80', '81'], 'value': 'in'},{'id': '80', 'type': 'string', 'children': [], 'value': "';'"},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '82', 'type': 'block', 'children': ['83', '100']},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '86', 'type': 'list_comprehension', 'children': ['87', '88', '96']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '88', 'type': 'for_in_clause', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '90', 'type': 'call', 'children': ['91', '94']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'string', 'children': [], 'value': "';'"},{'id': '96', 'type': 'if_clause', 'children': ['97']},{'id': '97', 'type': 'comparison_operator', 'children': ['98', '99'], 'value': '!='},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '99', 'type': 'string', 'children': [], 'value': "''"},{'id': '100', 'type': 'if_statement', 'children': ['101', '102', '119']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'unit'},{'id': '102', 'type': 'block', 'children': ['103']},{'id': '103', 'type': 'return_statement', 'children': ['104']},{'id': '104', 'type': 'list_comprehension', 'children': ['105', '116']},{'id': '105', 'type': 'call', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'Observation'},{'id': '107', 'type': 'argument_list', 'children': ['108', '109', '115']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '109', 'type': 'call', 'children': ['110', '113']},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'unit'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '113', 'type': 'argument_list', 'children': ['114']},{'id': '114', 'type': 'integer', 'children': [], 'value': '1'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'dt'},{'id': '116', 'type': 'for_in_clause', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '119', 'type': 'else_clause', 'children': ['120']},{'id': '120', 'type': 'block', 'children': ['121']},{'id': '121', 'type': 'return_statement', 'children': ['122']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '123', 'type': 'if_statement', 'children': ['124', '129']},{'id': '124', 'type': 'boolean_operator', 'children': ['125', '127'], 'value': 'or'},{'id': '125', 'type': 'not_operator', 'children': ['126']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '127', 'type': 'not_operator', 'children': ['128']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'unit'},{'id': '129', 'type': 'block', 'children': ['130']},{'id': '130', 'type': 'return_statement', 'children': ['131']},{'id': '131', 'type': 'boolean_operator', 'children': ['132', '133'], 'value': 'or'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '133', 'type': 'None', 'children': []},{'id': '134', 'type': 'return_statement', 'children': ['135']},{'id': '135', 'type': 'call', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'Observation'},{'id': '137', 'type': 'argument_list', 'children': ['138', '139', '145']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '139', 'type': 'call', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'unit'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '143', 'type': 'argument_list', 'children': ['144']},{'id': '144', 'type': 'integer', 'children': [], 'value': '1'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'dt'}
def parse_unit(prop, dictionary, dt=None): '''Do a fuzzy match for `prop` in the dictionary, taking into account unit suffix.''' try: dt = timezone.parse_datetime(dictionary.get('date_time')) except TypeError: dt = None matches = [k for k in dictionary.keys() if prop in k] try: value = dictionary[matches[0]] unit = re.search(r' \(([^)]+)\)', matches[0]) except IndexError: return None if ';' in value: 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 if not value or not unit: return value or None return Observation(value, unit.group(1), dt)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'rebuild'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '13', '20', '42', '50', '313', '320']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'call', 'children': ['8', '11']},{'id': '8', 'type': 'attribute', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'setUpdatesEnabled'},{'id': '11', 'type': 'argument_list', 'children': ['12']},{'id': '12', 'type': 'False', 'children': []},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'call', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'blockSignals'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'True', 'children': []},{'id': '20', 'type': 'for_statement', 'children': ['21', '22', '28']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '22', 'type': 'call', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'findChildren'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'QObject'},{'id': '28', 'type': 'block', 'children': ['29', '36']},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'setParent'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'None', 'children': []},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'call', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'deleteLater'},{'id': '41', 'type': 'argument_list', 'children': []},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '45', 'type': 'call', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '49', 'type': 'argument_list', 'children': []},{'id': '50', 'type': 'if_statement', 'children': ['51', '53', '304']},{'id': '51', 'type': '()', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '53', 'type': 'block', 'children': ['54', '61', '69']},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'call', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'setEnabled'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'True', 'children': []},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'uifile'},{'id': '64', 'type': 'call', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'uiFile'},{'id': '68', 'type': 'argument_list', 'children': []},{'id': '69', 'type': 'if_statement', 'children': ['70', '72', '137']},{'id': '70', 'type': '()', 'children': ['71']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'uifile'},{'id': '72', 'type': 'block', 'children': ['73', '82']},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'call', 'children': ['75', '78']},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'projexui'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'loadUi'},{'id': '78', 'type': 'argument_list', 'children': ['79', '80', '81']},{'id': '79', 'type': 'string', 'children': [], 'value': "''"},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'uifile'},{'id': '82', 'type': 'for_statement', 'children': ['83', '84', '90']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'widget'},{'id': '84', 'type': 'call', 'children': ['85', '88']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'findChildren'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'XOrbColumnEdit'},{'id': '90', 'type': 'block', 'children': ['91', '99', '108']},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'columnName'},{'id': '94', 'type': 'call', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'widget'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'columnName'},{'id': '98', 'type': 'argument_list', 'children': []},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'assignment', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '102', 'type': 'call', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'columnName'},{'id': '108', 'type': 'if_statement', 'children': ['109', '111', '119']},{'id': '109', 'type': '()', 'children': ['110']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '111', 'type': 'block', 'children': ['112']},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'call', 'children': ['114', '117']},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'widget'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'setColumn'},{'id': '117', 'type': 'argument_list', 'children': ['118']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '119', 'type': 'else_clause', 'children': ['120']},{'id': '120', 'type': 'block', 'children': ['121']},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'call', 'children': ['123', '126']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '126', 'type': 'argument_list', 'children': ['127']},{'id': '127', 'type': 'binary_operator', 'children': ['128', '129', '130'], 'value': '%'},{'id': '128', 'type': 'string', 'children': [], 'value': "'%s is not a valid column of %s'"},{'id': '129', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '130', 'type': 'tuple', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'columnName'},{'id': '132', 'type': 'call', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '136', 'type': 'argument_list', 'children': []},{'id': '137', 'type': 'else_clause', 'children': ['138']},{'id': '138', 'type': 'block', 'children': ['139', '145', '155', '163', '179', '187', '278', '285', '291']},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'id': '140', 'type': 'assignment', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'layout'},{'id': '142', 'type': 'call', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'QFormLayout'},{'id': '144', 'type': 'argument_list', 'children': []},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'call', 'children': ['147', '150']},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'layout'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'setContentsMargins'},{'id': '150', 'type': 'argument_list', 'children': ['151', '152', '153', '154']},{'id': '151', 'type': 'integer', 'children': [], 'value': '0'},{'id': '152', 'type': 'integer', 'children': [], 'value': '0'},{'id': '153', 'type': 'integer', 'children': [], 'value': '0'},{'id': '154', 'type': 'integer', 'children': [], 'value': '0'},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'assignment', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '158', 'type': 'call', 'children': ['159', '162']},{'id': '159', 'type': 'attribute', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '162', 'type': 'argument_list', 'children': []},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'call', 'children': ['165', '168']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '168', 'type': 'argument_list', 'children': ['169']},{'id': '169', 'type': 'keyword_argument', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '171', 'type': 'lambda', 'children': ['172', '174']},{'id': '172', 'type': 'lambda_parameters', 'children': ['173']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '174', 'type': 'call', 'children': ['175', '178']},{'id': '175', 'type': 'attribute', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'displayName'},{'id': '178', 'type': 'argument_list', 'children': []},{'id': '179', 'type': 'expression_statement', 'children': ['180']},{'id': '180', 'type': 'assignment', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'record'},{'id': '182', 'type': 'call', 'children': ['183', '186']},{'id': '183', 'type': 'attribute', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'record'},{'id': '186', 'type': 'argument_list', 'children': []},{'id': '187', 'type': 'for_statement', 'children': ['188', '189', '190']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '190', 'type': 'block', 'children': ['191', '205', '213', '221', '229', '236', '245', '252', '259', '266']},{'id': '191', 'type': 'if_statement', 'children': ['192', '203']},{'id': '192', 'type': '()', 'children': ['193']},{'id': '193', 'type': 'call', 'children': ['194', '201']},{'id': '194', 'type': 'attribute', 'children': ['195', '200']},{'id': '195', 'type': 'call', 'children': ['196', '199']},{'id': '196', 'type': 'attribute', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '199', 'type': 'argument_list', 'children': []},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '201', 'type': 'argument_list', 'children': ['202']},{'id': '202', 'type': 'string', 'children': [], 'value': "'_'"},{'id': '203', 'type': 'block', 'children': ['204']},{'id': '204', 'type': 'continue_statement', 'children': []},{'id': '205', 'type': 'expression_statement', 'children': ['206']},{'id': '206', 'type': 'assignment', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '208', 'type': 'call', 'children': ['209', '212']},{'id': '209', 'type': 'attribute', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'displayName'},{'id': '212', 'type': 'argument_list', 'children': []},{'id': '213', 'type': 'expression_statement', 'children': ['214']},{'id': '214', 'type': 'assignment', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'coltype'},{'id': '216', 'type': 'call', 'children': ['217', '220']},{'id': '217', 'type': 'attribute', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'columnType'},{'id': '220', 'type': 'argument_list', 'children': []},{'id': '221', 'type': 'expression_statement', 'children': ['222']},{'id': '222', 'type': 'assignment', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '224', 'type': 'call', 'children': ['225', '228']},{'id': '225', 'type': 'attribute', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '228', 'type': 'argument_list', 'children': []},{'id': '229', 'type': 'expression_statement', 'children': ['230']},{'id': '230', 'type': 'assignment', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'widget'},{'id': '232', 'type': 'call', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'XOrbColumnEdit'},{'id': '234', 'type': 'argument_list', 'children': ['235']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '236', 'type': 'expression_statement', 'children': ['237']},{'id': '237', 'type': 'call', 'children': ['238', '241']},{'id': '238', 'type': 'attribute', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'widget'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'setObjectName'},{'id': '241', 'type': 'argument_list', 'children': ['242']},{'id': '242', 'type': 'binary_operator', 'children': ['243', '244'], 'value': '+'},{'id': '243', 'type': 'string', 'children': [], 'value': "'ui_'"},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '245', 'type': 'expression_statement', 'children': ['246']},{'id': '246', 'type': 'call', 'children': ['247', '250']},{'id': '247', 'type': 'attribute', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'widget'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'setColumnName'},{'id': '250', 'type': 'argument_list', 'children': ['251']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '252', 'type': 'expression_statement', 'children': ['253']},{'id': '253', 'type': 'call', 'children': ['254', '257']},{'id': '254', 'type': 'attribute', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'widget'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'setColumnType'},{'id': '257', 'type': 'argument_list', 'children': ['258']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'coltype'},{'id': '259', 'type': 'expression_statement', 'children': ['260']},{'id': '260', 'type': 'call', 'children': ['261', '264']},{'id': '261', 'type': 'attribute', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'widget'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'setColumn'},{'id': '264', 'type': 'argument_list', 'children': ['265']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '266', 'type': 'expression_statement', 'children': ['267']},{'id': '267', 'type': 'call', 'children': ['268', '271']},{'id': '268', 'type': 'attribute', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'layout'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'addRow'},{'id': '271', 'type': 'argument_list', 'children': ['272', '277']},{'id': '272', 'type': 'call', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'QLabel'},{'id': '274', 'type': 'argument_list', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'widget'},{'id': '278', 'type': 'expression_statement', 'children': ['279']},{'id': '279', 'type': 'call', 'children': ['280', '283']},{'id': '280', 'type': 'attribute', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'setLayout'},{'id': '283', 'type': 'argument_list', 'children': ['284']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'layout'},{'id': '285', 'type': 'expression_statement', 'children': ['286']},{'id': '286', 'type': 'call', 'children': ['287', '290']},{'id': '287', 'type': 'attribute', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'adjustSize'},{'id': '290', 'type': 'argument_list', 'children': []},{'id': '291', 'type': 'expression_statement', 'children': ['292']},{'id': '292', 'type': 'call', 'children': ['293', '296']},{'id': '293', 'type': 'attribute', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'setWindowTitle'},{'id': '296', 'type': 'argument_list', 'children': ['297']},{'id': '297', 'type': 'binary_operator', 'children': ['298', '299'], 'value': '%'},{'id': '298', 'type': 'string', 'children': [], 'value': "'Edit %s'"},{'id': '299', 'type': 'call', 'children': ['300', '303']},{'id': '300', 'type': 'attribute', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '303', 'type': 'argument_list', 'children': []},{'id': '304', 'type': 'else_clause', 'children': ['305']},{'id': '305', 'type': 'block', 'children': ['306']},{'id': '306', 'type': 'expression_statement', 'children': ['307']},{'id': '307', 'type': 'call', 'children': ['308', '311']},{'id': '308', 'type': 'attribute', 'children': ['309', '310']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'setEnabled'},{'id': '311', 'type': 'argument_list', 'children': ['312']},{'id': '312', 'type': 'False', 'children': []},{'id': '313', 'type': 'expression_statement', 'children': ['314']},{'id': '314', 'type': 'call', 'children': ['315', '318']},{'id': '315', 'type': 'attribute', 'children': ['316', '317']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'setUpdatesEnabled'},{'id': '318', 'type': 'argument_list', 'children': ['319']},{'id': '319', 'type': 'True', 'children': []},{'id': '320', 'type': 'expression_statement', 'children': ['321']},{'id': '321', 'type': 'call', 'children': ['322', '325']},{'id': '322', 'type': 'attribute', 'children': ['323', '324']},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'blockSignals'},{'id': '325', 'type': 'argument_list', 'children': ['326']},{'id': '326', 'type': 'False', 'children': []}
def rebuild( self ): self.setUpdatesEnabled(False) self.blockSignals(True) for child in self.findChildren(QObject): child.setParent(None) child.deleteLater() schema = self.schema() if ( schema ): self.setEnabled(True) uifile = self.uiFile() 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())) 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: if ( column.name().startswith('_') ): continue label = column.displayName() coltype = column.columnType() name = column.name() 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)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'save'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '14', '28', '36', '48', '52', '61', '249', '267', '273']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '9', 'type': 'call', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '13', 'type': 'argument_list', 'children': []},{'id': '14', 'type': 'if_statement', 'children': ['15', '18']},{'id': '15', 'type': '()', 'children': ['16']},{'id': '16', 'type': 'not_operator', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '18', 'type': 'block', 'children': ['19', '27']},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'call', 'children': ['21', '26']},{'id': '21', 'type': 'attribute', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'saved'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'emit'},{'id': '26', 'type': 'argument_list', 'children': []},{'id': '27', 'type': 'return_statement', 'children': []},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'record'},{'id': '31', 'type': 'call', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'record'},{'id': '35', 'type': 'argument_list', 'children': []},{'id': '36', 'type': 'if_statement', 'children': ['37', '39']},{'id': '37', 'type': 'not_operator', 'children': ['38']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'record'},{'id': '39', 'type': 'block', 'children': ['40']},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'record'},{'id': '43', 'type': 'call', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '46', 'type': 'identifier', 'children': [], 'value': '_model'},{'id': '47', 'type': 'argument_list', 'children': []},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'save_data'},{'id': '51', 'type': 'list', 'children': [], 'value': '[]'},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'column_edits'},{'id': '55', 'type': 'call', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'findChildren'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'XOrbColumnEdit'},{'id': '61', 'type': 'for_statement', 'children': ['62', '63', '64']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'widget'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'column_edits'},{'id': '64', 'type': 'block', 'children': ['65', '73', '82', '104', '112', '119', '240']},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'columnName'},{'id': '68', 'type': 'call', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'widget'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'columnName'},{'id': '72', 'type': 'argument_list', 'children': []},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '76', 'type': 'call', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'columnName'},{'id': '82', 'type': 'if_statement', 'children': ['83', '86']},{'id': '83', 'type': '()', 'children': ['84']},{'id': '84', 'type': 'not_operator', 'children': ['85']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '86', 'type': 'block', 'children': ['87', '103']},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'call', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'binary_operator', 'children': ['94', '95', '96'], 'value': '%'},{'id': '94', 'type': 'string', 'children': [], 'value': "'%s is not a valid column of %s.'"},{'id': '95', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '96', 'type': 'tuple', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'columnName'},{'id': '98', 'type': 'call', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '102', 'type': 'argument_list', 'children': []},{'id': '103', 'type': 'continue_statement', 'children': []},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'assignment', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '107', 'type': 'call', 'children': ['108', '111']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'widget'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '111', 'type': 'argument_list', 'children': []},{'id': '112', 'type': 'if_statement', 'children': ['113', '117']},{'id': '113', 'type': '()', 'children': ['114']},{'id': '114', 'type': 'comparison_operator', 'children': ['115', '116'], 'value': '=='},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'IGNORED'},{'id': '117', 'type': 'block', 'children': ['118']},{'id': '118', 'type': 'continue_statement', 'children': []},{'id': '119', 'type': 'if_statement', 'children': ['120', '129', '150']},{'id': '120', 'type': '()', 'children': ['121']},{'id': '121', 'type': 'boolean_operator', 'children': ['122', '127'], 'value': 'and'},{'id': '122', 'type': 'call', 'children': ['123', '126']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'required'},{'id': '126', 'type': 'argument_list', 'children': []},{'id': '127', 'type': 'not_operator', 'children': ['128']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '129', 'type': 'block', 'children': ['130', '138', '149']},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'assignment', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '133', 'type': 'call', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'displayName'},{'id': '137', 'type': 'argument_list', 'children': []},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'call', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'QMessageBox'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'information'},{'id': '143', 'type': 'argument_list', 'children': ['144', '145', '146']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '145', 'type': 'string', 'children': [], 'value': "'Missing Required Field'"},{'id': '146', 'type': 'binary_operator', 'children': ['147', '148'], 'value': '%'},{'id': '147', 'type': 'string', 'children': [], 'value': "'%s is a required field.'"},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '149', 'type': 'return_statement', 'children': []},{'id': '150', 'type': 'elif_clause', 'children': ['151', '157']},{'id': '151', 'type': '()', 'children': ['152']},{'id': '152', 'type': 'call', 'children': ['153', '156']},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'unique'},{'id': '156', 'type': 'argument_list', 'children': []},{'id': '157', 'type': 'block', 'children': ['158', '171', '190', '204', '220']},{'id': '158', 'type': 'expression_statement', 'children': ['159']},{'id': '159', 'type': 'assignment', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '161', 'type': 'comparison_operator', 'children': ['162', '170'], 'value': '=='},{'id': '162', 'type': 'call', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'Q'},{'id': '164', 'type': 'argument_list', 'children': ['165']},{'id': '165', 'type': 'call', 'children': ['166', '169']},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '169', 'type': 'argument_list', 'children': []},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '171', 'type': 'if_statement', 'children': ['172', '178']},{'id': '172', 'type': '()', 'children': ['173']},{'id': '173', 'type': 'call', 'children': ['174', '177']},{'id': '174', 'type': 'attribute', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'record'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'isRecord'},{'id': '177', 'type': 'argument_list', 'children': []},{'id': '178', 'type': 'block', 'children': ['179']},{'id': '179', 'type': 'expression_statement', 'children': ['180']},{'id': '180', 'type': 'augmented_assignment', 'children': ['181', '182'], 'value': '&='},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '182', 'type': 'comparison_operator', 'children': ['183', '189'], 'value': '!='},{'id': '183', 'type': 'call', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'Q'},{'id': '185', 'type': 'argument_list', 'children': ['186']},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '188', 'type': 'identifier', 'children': [], 'value': '_model'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'record'},{'id': '190', 'type': 'expression_statement', 'children': ['191']},{'id': '191', 'type': 'assignment', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '193', 'type': 'call', 'children': ['194', '203']},{'id': '194', 'type': 'attribute', 'children': ['195', '202']},{'id': '195', 'type': 'call', 'children': ['196', '201']},{'id': '196', 'type': 'attribute', 'children': ['197', '200']},{'id': '197', 'type': 'attribute', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '199', 'type': 'identifier', 'children': [], 'value': '_model'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '201', 'type': 'argument_list', 'children': []},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'primaryColumns'},{'id': '203', 'type': 'argument_list', 'children': []},{'id': '204', 'type': 'expression_statement', 'children': ['205']},{'id': '205', 'type': 'assignment', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '207', 'type': 'call', 'children': ['208', '213']},{'id': '208', 'type': 'attribute', 'children': ['209', '212']},{'id': '209', 'type': 'attribute', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '211', 'type': 'identifier', 'children': [], 'value': '_model'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'select'},{'id': '213', 'type': 'argument_list', 'children': ['214', '217']},{'id': '214', 'type': 'keyword_argument', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '217', 'type': 'keyword_argument', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'where'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '220', 'type': 'if_statement', 'children': ['221', '227']},{'id': '221', 'type': '()', 'children': ['222']},{'id': '222', 'type': 'call', 'children': ['223', '226']},{'id': '223', 'type': 'attribute', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'total'},{'id': '226', 'type': 'argument_list', 'children': []},{'id': '227', 'type': 'block', 'children': ['228', '239']},{'id': '228', 'type': 'expression_statement', 'children': ['229']},{'id': '229', 'type': 'call', 'children': ['230', '233']},{'id': '230', 'type': 'attribute', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'QMessageBox'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'information'},{'id': '233', 'type': 'argument_list', 'children': ['234', '235', '236']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '235', 'type': 'string', 'children': [], 'value': "'Duplicate Entry'"},{'id': '236', 'type': 'binary_operator', 'children': ['237', '238'], 'value': '%'},{'id': '237', 'type': 'string', 'children': [], 'value': "'%s already exists.'"},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '239', 'type': 'return_statement', 'children': []},{'id': '240', 'type': 'expression_statement', 'children': ['241']},{'id': '241', 'type': 'call', 'children': ['242', '245']},{'id': '242', 'type': 'attribute', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'save_data'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '245', 'type': 'argument_list', 'children': ['246']},{'id': '246', 'type': 'tuple', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '249', 'type': 'for_statement', 'children': ['250', '253', '254']},{'id': '250', 'type': 'pattern_list', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'save_data'},{'id': '254', 'type': 'block', 'children': ['255']},{'id': '255', 'type': 'expression_statement', 'children': ['256']},{'id': '256', 'type': 'call', 'children': ['257', '260']},{'id': '257', 'type': 'attribute', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'record'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'setRecordValue'},{'id': '260', 'type': 'argument_list', 'children': ['261', '266']},{'id': '261', 'type': 'call', 'children': ['262', '265']},{'id': '262', 'type': 'attribute', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '265', 'type': 'argument_list', 'children': []},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '267', 'type': 'expression_statement', 'children': ['268']},{'id': '268', 'type': 'assignment', 'children': ['269', '272']},{'id': '269', 'type': 'attribute', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '271', 'type': 'identifier', 'children': [], 'value': '_record'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'record'},{'id': '273', 'type': 'expression_statement', 'children': ['274']},{'id': '274', 'type': 'call', 'children': ['275', '280']},{'id': '275', 'type': 'attribute', 'children': ['276', '279']},{'id': '276', 'type': 'attribute', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'saved'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'emit'},{'id': '280', 'type': 'argument_list', 'children': []}
def save( self ): schema = self.schema() if ( not schema ): self.saved.emit() return record = self.record() if not record: record = self._model() 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 if ( column.required() and not value ): name = column.displayName() QMessageBox.information(self, 'Missing Required Field', '%s is a required field.' % name) return elif ( column.unique() ): 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)) for column, value in save_data: record.setRecordValue(column.name(), value) self._record = record self.saved.emit()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'register'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'service'},{'id': '6', 'type': 'block', 'children': ['7', '22']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '10', 'type': 'await', 'children': ['11']},{'id': '11', 'type': 'call', 'children': ['12', '17']},{'id': '12', 'type': 'attribute', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '15', 'type': 'identifier', 'children': [], 'value': '_api'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'put'},{'id': '17', 'type': 'argument_list', 'children': ['18', '19']},{'id': '18', 'type': 'string', 'children': [], 'value': '"/v1/agent/service/register"'},{'id': '19', 'type': 'keyword_argument', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'service'},{'id': '22', 'type': 'return_statement', 'children': ['23']},{'id': '23', 'type': 'comparison_operator', 'children': ['24', '27'], 'value': '=='},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '27', 'type': 'integer', 'children': [], 'value': '200'}
async def register(self, service): response = await self._api.put("/v1/agent/service/register", data=service) return response.status == 200
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'save'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '14', '29', '54', '62', '70', '110', '214', '225', '241', '249', '259', '274', '306', '346']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'record'},{'id': '9', 'type': 'call', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'record'},{'id': '13', 'type': 'argument_list', 'children': []},{'id': '14', 'type': 'if_statement', 'children': ['15', '17']},{'id': '15', 'type': 'not_operator', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'record'},{'id': '17', 'type': 'block', 'children': ['18', '27']},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'call', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'binary_operator', 'children': ['25', '26'], 'value': '%'},{'id': '25', 'type': 'string', 'children': [], 'value': "'No record has been defined for %s.'"},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '27', 'type': 'return_statement', 'children': ['28']},{'id': '28', 'type': 'False', 'children': []},{'id': '29', 'type': 'if_statement', 'children': ['30', '36']},{'id': '30', 'type': 'not_operator', 'children': ['31']},{'id': '31', 'type': 'call', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'signalsBlocked'},{'id': '35', 'type': 'argument_list', 'children': []},{'id': '36', 'type': 'block', 'children': ['37', '46']},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'call', 'children': ['39', '44']},{'id': '39', 'type': 'attribute', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'aboutToSaveRecord'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'emit'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'record'},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'call', 'children': ['48', '53']},{'id': '48', 'type': 'attribute', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'aboutToSave'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'emit'},{'id': '53', 'type': 'argument_list', 'children': []},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '57', 'type': 'call', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'saveValues'},{'id': '61', 'type': 'argument_list', 'children': []},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'check'},{'id': '65', 'type': 'call', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '69', 'type': 'argument_list', 'children': []},{'id': '70', 'type': 'for_statement', 'children': ['71', '74', '79']},{'id': '71', 'type': 'pattern_list', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'column_name'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '74', 'type': 'call', 'children': ['75', '78']},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'check'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '78', 'type': 'argument_list', 'children': []},{'id': '79', 'type': 'block', 'children': ['80', '100']},{'id': '80', 'type': 'try_statement', 'children': ['81', '93']},{'id': '81', 'type': 'block', 'children': ['82']},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'assignment', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'equals'},{'id': '85', 'type': 'comparison_operator', 'children': ['86', '87'], 'value': '=='},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '87', 'type': 'call', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'record'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'recordValue'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'column_name'},{'id': '93', 'type': 'except_clause', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'UnicodeWarning'},{'id': '95', 'type': 'block', 'children': ['96']},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'assignment', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'equals'},{'id': '99', 'type': 'False', 'children': []},{'id': '100', 'type': 'if_statement', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'equals'},{'id': '102', 'type': 'block', 'children': ['103']},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'call', 'children': ['105', '108']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'check'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '108', 'type': 'argument_list', 'children': ['109']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'column_name'},{'id': '110', 'type': 'if_statement', 'children': ['111', '119']},{'id': '111', 'type': 'boolean_operator', 'children': ['112', '114'], 'value': 'and'},{'id': '112', 'type': 'not_operator', 'children': ['113']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'check'},{'id': '114', 'type': 'call', 'children': ['115', '118']},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'record'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'isRecord'},{'id': '118', 'type': 'argument_list', 'children': []},{'id': '119', 'type': 'block', 'children': ['120', '159', '212']},{'id': '120', 'type': 'if_statement', 'children': ['121', '127', '151']},{'id': '121', 'type': 'not_operator', 'children': ['122']},{'id': '122', 'type': 'call', 'children': ['123', '126']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'signalsBlocked'},{'id': '126', 'type': 'argument_list', 'children': []},{'id': '127', 'type': 'block', 'children': ['128', '137', '145']},{'id': '128', 'type': 'expression_statement', 'children': ['129']},{'id': '129', 'type': 'call', 'children': ['130', '135']},{'id': '130', 'type': 'attribute', 'children': ['131', '134']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'recordSaved'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'emit'},{'id': '135', 'type': 'argument_list', 'children': ['136']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'record'},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'call', 'children': ['139', '144']},{'id': '139', 'type': 'attribute', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'saved'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'emit'},{'id': '144', 'type': 'argument_list', 'children': []},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'assignment', 'children': ['147', '150']},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '149', 'type': 'identifier', 'children': [], 'value': '_saveSignalBlocked'},{'id': '150', 'type': 'False', 'children': []},{'id': '151', 'type': 'else_clause', 'children': ['152']},{'id': '152', 'type': 'block', 'children': ['153']},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'assignment', 'children': ['155', '158']},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '157', 'type': 'identifier', 'children': [], 'value': '_saveSignalBlocked'},{'id': '158', 'type': 'True', 'children': []},{'id': '159', 'type': 'if_statement', 'children': ['160', '165']},{'id': '160', 'type': 'call', 'children': ['161', '164']},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'autoCommitOnSave'},{'id': '164', 'type': 'argument_list', 'children': []},{'id': '165', 'type': 'block', 'children': ['166', '176']},{'id': '166', 'type': 'expression_statement', 'children': ['167']},{'id': '167', 'type': 'assignment', 'children': ['168', '171']},{'id': '168', 'type': 'pattern_list', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '171', 'type': 'call', 'children': ['172', '175']},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'record'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'commit'},{'id': '175', 'type': 'argument_list', 'children': []},{'id': '176', 'type': 'if_statement', 'children': ['177', '180']},{'id': '177', 'type': 'comparison_operator', 'children': ['178', '179'], 'value': '=='},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '179', 'type': 'string', 'children': [], 'value': "'errored'"},{'id': '180', 'type': 'block', 'children': ['181', '201', '210']},{'id': '181', 'type': 'if_statement', 'children': ['182', '185', '195']},{'id': '182', 'type': 'comparison_operator', 'children': ['183', '184'], 'value': 'in'},{'id': '183', 'type': 'string', 'children': [], 'value': "'db_error'"},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '185', 'type': 'block', 'children': ['186']},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'assignment', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '189', 'type': 'call', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'nativestring'},{'id': '191', 'type': 'argument_list', 'children': ['192']},{'id': '192', 'type': 'subscript', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '194', 'type': 'string', 'children': [], 'value': "'db_error'"},{'id': '195', 'type': 'else_clause', 'children': ['196']},{'id': '196', 'type': 'block', 'children': ['197']},{'id': '197', 'type': 'expression_statement', 'children': ['198']},{'id': '198', 'type': 'assignment', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '200', 'type': 'string', 'children': [], 'value': "'An unknown database error has occurred.'"},{'id': '201', 'type': 'expression_statement', 'children': ['202']},{'id': '202', 'type': 'call', 'children': ['203', '206']},{'id': '203', 'type': 'attribute', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'QMessageBox'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'information'},{'id': '206', 'type': 'argument_list', 'children': ['207', '208', '209']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '208', 'type': 'string', 'children': [], 'value': "'Commit Error'"},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '210', 'type': 'return_statement', 'children': ['211']},{'id': '211', 'type': 'False', 'children': []},{'id': '212', 'type': 'return_statement', 'children': ['213']},{'id': '213', 'type': 'True', 'children': []},{'id': '214', 'type': 'expression_statement', 'children': ['215']},{'id': '215', 'type': 'assignment', 'children': ['216', '219']},{'id': '216', 'type': 'pattern_list', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'success'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '219', 'type': 'call', 'children': ['220', '223']},{'id': '220', 'type': 'attribute', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'record'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'validateValues'},{'id': '223', 'type': 'argument_list', 'children': ['224']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'check'},{'id': '225', 'type': 'if_statement', 'children': ['226', '229']},{'id': '226', 'type': '()', 'children': ['227']},{'id': '227', 'type': 'not_operator', 'children': ['228']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'success'},{'id': '229', 'type': 'block', 'children': ['230', '239']},{'id': '230', 'type': 'expression_statement', 'children': ['231']},{'id': '231', 'type': 'call', 'children': ['232', '235']},{'id': '232', 'type': 'attribute', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'QMessageBox'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'information'},{'id': '235', 'type': 'argument_list', 'children': ['236', '237', '238']},{'id': '236', 'type': 'None', 'children': []},{'id': '237', 'type': 'string', 'children': [], 'value': "'Could Not Save'"},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '239', 'type': 'return_statement', 'children': ['240']},{'id': '240', 'type': 'False', 'children': []},{'id': '241', 'type': 'expression_statement', 'children': ['242']},{'id': '242', 'type': 'call', 'children': ['243', '246']},{'id': '243', 'type': 'attribute', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'record'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'setRecordValues'},{'id': '246', 'type': 'argument_list', 'children': ['247']},{'id': '247', 'type': 'dictionary_splat', 'children': ['248']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '249', 'type': 'expression_statement', 'children': ['250']},{'id': '250', 'type': 'assignment', 'children': ['251', '254']},{'id': '251', 'type': 'pattern_list', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'success'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '254', 'type': 'call', 'children': ['255', '258']},{'id': '255', 'type': 'attribute', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'record'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'validateRecord'},{'id': '258', 'type': 'argument_list', 'children': []},{'id': '259', 'type': 'if_statement', 'children': ['260', '262']},{'id': '260', 'type': 'not_operator', 'children': ['261']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'success'},{'id': '262', 'type': 'block', 'children': ['263', '272']},{'id': '263', 'type': 'expression_statement', 'children': ['264']},{'id': '264', 'type': 'call', 'children': ['265', '268']},{'id': '265', 'type': 'attribute', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'QMessageBox'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'information'},{'id': '268', 'type': 'argument_list', 'children': ['269', '270', '271']},{'id': '269', 'type': 'None', 'children': []},{'id': '270', 'type': 'string', 'children': [], 'value': "'Could Not Save'"},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '272', 'type': 'return_statement', 'children': ['273']},{'id': '273', 'type': 'False', 'children': []},{'id': '274', 'type': 'if_statement', 'children': ['275', '281']},{'id': '275', 'type': '()', 'children': ['276']},{'id': '276', 'type': 'call', 'children': ['277', '280']},{'id': '277', 'type': 'attribute', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'autoCommitOnSave'},{'id': '280', 'type': 'argument_list', 'children': []},{'id': '281', 'type': 'block', 'children': ['282', '290']},{'id': '282', 'type': 'expression_statement', 'children': ['283']},{'id': '283', 'type': 'assignment', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '285', 'type': 'call', 'children': ['286', '289']},{'id': '286', 'type': 'attribute', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'record'},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'commit'},{'id': '289', 'type': 'argument_list', 'children': []},{'id': '290', 'type': 'if_statement', 'children': ['291', '294']},{'id': '291', 'type': 'comparison_operator', 'children': ['292', '293'], 'value': 'in'},{'id': '292', 'type': 'string', 'children': [], 'value': "'errored'"},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '294', 'type': 'block', 'children': ['295', '304']},{'id': '295', 'type': 'expression_statement', 'children': ['296']},{'id': '296', 'type': 'call', 'children': ['297', '300']},{'id': '297', 'type': 'attribute', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'QMessageBox'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'information'},{'id': '300', 'type': 'argument_list', 'children': ['301', '302', '303']},{'id': '301', 'type': 'None', 'children': []},{'id': '302', 'type': 'string', 'children': [], 'value': "'Could Not Save'"},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '304', 'type': 'return_statement', 'children': ['305']},{'id': '305', 'type': 'False', 'children': []},{'id': '306', 'type': 'if_statement', 'children': ['307', '314', '338']},{'id': '307', 'type': '()', 'children': ['308']},{'id': '308', 'type': 'not_operator', 'children': ['309']},{'id': '309', 'type': 'call', 'children': ['310', '313']},{'id': '310', 'type': 'attribute', 'children': ['311', '312']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'signalsBlocked'},{'id': '313', 'type': 'argument_list', 'children': []},{'id': '314', 'type': 'block', 'children': ['315', '324', '332']},{'id': '315', 'type': 'expression_statement', 'children': ['316']},{'id': '316', 'type': 'call', 'children': ['317', '322']},{'id': '317', 'type': 'attribute', 'children': ['318', '321']},{'id': '318', 'type': 'attribute', 'children': ['319', '320']},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'recordSaved'},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'emit'},{'id': '322', 'type': 'argument_list', 'children': ['323']},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'record'},{'id': '324', 'type': 'expression_statement', 'children': ['325']},{'id': '325', 'type': 'call', 'children': ['326', '331']},{'id': '326', 'type': 'attribute', 'children': ['327', '330']},{'id': '327', 'type': 'attribute', 'children': ['328', '329']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'saved'},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'emit'},{'id': '331', 'type': 'argument_list', 'children': []},{'id': '332', 'type': 'expression_statement', 'children': ['333']},{'id': '333', 'type': 'assignment', 'children': ['334', '337']},{'id': '334', 'type': 'attribute', 'children': ['335', '336']},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '336', 'type': 'identifier', 'children': [], 'value': '_saveSignalBlocked'},{'id': '337', 'type': 'False', 'children': []},{'id': '338', 'type': 'else_clause', 'children': ['339']},{'id': '339', 'type': 'block', 'children': ['340']},{'id': '340', 'type': 'expression_statement', 'children': ['341']},{'id': '341', 'type': 'assignment', 'children': ['342', '345']},{'id': '342', 'type': 'attribute', 'children': ['343', '344']},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '344', 'type': 'identifier', 'children': [], 'value': '_saveSignalBlocked'},{'id': '345', 'type': 'True', 'children': []},{'id': '346', 'type': 'return_statement', 'children': ['347']},{'id': '347', 'type': 'True', 'children': []}
def save(self): 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() 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) 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 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
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'prepare'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '15', '30', '39', '72', '143', '161', '281', '290', '325', '329', '339', '349', '359', '369', '389', '397', '404']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'pixmap'},{'id': '9', 'type': 'call', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'property'},{'id': '13', 'type': 'argument_list', 'children': ['14']},{'id': '14', 'type': 'string', 'children': [], 'value': "'pixmap'"},{'id': '15', 'type': 'if_statement', 'children': ['16', '19']},{'id': '16', 'type': 'comparison_operator', 'children': ['17', '18'], 'value': 'is'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'pixmap'},{'id': '18', 'type': 'None', 'children': []},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'return_statement', 'children': ['21']},{'id': '21', 'type': 'call', 'children': ['22', '29']},{'id': '22', 'type': 'attribute', 'children': ['23', '28']},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'super'},{'id': '25', 'type': 'argument_list', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'XWalkthroughSnapshot'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'prepare'},{'id': '29', 'type': 'argument_list', 'children': []},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'widget'},{'id': '33', 'type': 'call', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'property'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'string', 'children': [], 'value': "'widget'"},{'id': '39', 'type': 'if_statement', 'children': ['40', '48']},{'id': '40', 'type': 'comparison_operator', 'children': ['41', '45'], 'value': 'in'},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'widget'},{'id': '45', 'type': 'tuple', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'unicode'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '48', 'type': 'block', 'children': ['49', '58']},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'widget'},{'id': '52', 'type': 'call', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'findReference'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'widget'},{'id': '58', 'type': 'if_statement', 'children': ['59', '61']},{'id': '59', 'type': 'not_operator', 'children': ['60']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'widget'},{'id': '61', 'type': 'block', 'children': ['62']},{'id': '62', 'type': 'return_statement', 'children': ['63']},{'id': '63', 'type': 'call', 'children': ['64', '71']},{'id': '64', 'type': 'attribute', 'children': ['65', '70']},{'id': '65', 'type': 'call', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'super'},{'id': '67', 'type': 'argument_list', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'XWalkthroughSnapshot'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'prepare'},{'id': '71', 'type': 'argument_list', 'children': []},{'id': '72', 'type': 'if_statement', 'children': ['73', '85']},{'id': '73', 'type': 'boolean_operator', 'children': ['74', '80'], 'value': 'and'},{'id': '74', 'type': 'call', 'children': ['75', '78']},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'property'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'string', 'children': [], 'value': "'overlay'"},{'id': '80', 'type': 'call', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'widget'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '84', 'type': 'argument_list', 'children': []},{'id': '85', 'type': 'block', 'children': ['86', '94', '135']},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'assignment', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'ref'},{'id': '89', 'type': 'call', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'referenceWidget'},{'id': '93', 'type': 'argument_list', 'children': []},{'id': '94', 'type': 'if_statement', 'children': ['95', '98', '109']},{'id': '95', 'type': 'comparison_operator', 'children': ['96', '97'], 'value': '=='},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'ref'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'widget'},{'id': '98', 'type': 'block', 'children': ['99']},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'assignment', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'pos'},{'id': '102', 'type': 'call', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'QtCore'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'QPoint'},{'id': '106', 'type': 'argument_list', 'children': ['107', '108']},{'id': '107', 'type': 'integer', 'children': [], 'value': '0'},{'id': '108', 'type': 'integer', 'children': [], 'value': '0'},{'id': '109', 'type': 'else_clause', 'children': ['110']},{'id': '110', 'type': 'block', 'children': ['111', '126']},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'assignment', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'glbl_pos'},{'id': '114', 'type': 'call', 'children': ['115', '118']},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'widget'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'mapToGlobal'},{'id': '118', 'type': 'argument_list', 'children': ['119']},{'id': '119', 'type': 'call', 'children': ['120', '123']},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'QtCore'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'QPoint'},{'id': '123', 'type': 'argument_list', 'children': ['124', '125']},{'id': '124', 'type': 'integer', 'children': [], 'value': '0'},{'id': '125', 'type': 'integer', 'children': [], 'value': '0'},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'assignment', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'pos'},{'id': '129', 'type': 'call', 'children': ['130', '133']},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'ref'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'mapFromGlobal'},{'id': '133', 'type': 'argument_list', 'children': ['134']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'glbl_pos'},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'call', 'children': ['137', '140']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'setProperty'},{'id': '140', 'type': 'argument_list', 'children': ['141', '142']},{'id': '141', 'type': 'string', 'children': [], 'value': "'pos'"},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'pos'},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'assignment', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'crop'},{'id': '146', 'type': 'call', 'children': ['147', '150']},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'property'},{'id': '150', 'type': 'argument_list', 'children': ['151', '152']},{'id': '151', 'type': 'string', 'children': [], 'value': "'crop'"},{'id': '152', 'type': 'call', 'children': ['153', '156']},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'QtCore'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'QRect'},{'id': '156', 'type': 'argument_list', 'children': ['157', '158', '159', '160']},{'id': '157', 'type': 'integer', 'children': [], 'value': '0'},{'id': '158', 'type': 'integer', 'children': [], 'value': '0'},{'id': '159', 'type': 'integer', 'children': [], 'value': '0'},{'id': '160', 'type': 'integer', 'children': [], 'value': '0'},{'id': '161', 'type': 'if_statement', 'children': ['162', '163', '268']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'crop'},{'id': '163', 'type': 'block', 'children': ['164', '172', '190', '208', '232', '256']},{'id': '164', 'type': 'expression_statement', 'children': ['165']},{'id': '165', 'type': 'assignment', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'rect'},{'id': '167', 'type': 'call', 'children': ['168', '171']},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'widget'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'rect'},{'id': '171', 'type': 'argument_list', 'children': []},{'id': '172', 'type': 'if_statement', 'children': ['173', '178']},{'id': '173', 'type': 'call', 'children': ['174', '177']},{'id': '174', 'type': 'attribute', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'crop'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'width'},{'id': '177', 'type': 'argument_list', 'children': []},{'id': '178', 'type': 'block', 'children': ['179']},{'id': '179', 'type': 'expression_statement', 'children': ['180']},{'id': '180', 'type': 'call', 'children': ['181', '184']},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'rect'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'setWidth'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'call', 'children': ['186', '189']},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'crop'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'width'},{'id': '189', 'type': 'argument_list', 'children': []},{'id': '190', 'type': 'if_statement', 'children': ['191', '196']},{'id': '191', 'type': 'call', 'children': ['192', '195']},{'id': '192', 'type': 'attribute', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'crop'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'height'},{'id': '195', 'type': 'argument_list', 'children': []},{'id': '196', 'type': 'block', 'children': ['197']},{'id': '197', 'type': 'expression_statement', 'children': ['198']},{'id': '198', 'type': 'call', 'children': ['199', '202']},{'id': '199', 'type': 'attribute', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'rect'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'setHeight'},{'id': '202', 'type': 'argument_list', 'children': ['203']},{'id': '203', 'type': 'call', 'children': ['204', '207']},{'id': '204', 'type': 'attribute', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'crop'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'height'},{'id': '207', 'type': 'argument_list', 'children': []},{'id': '208', 'type': 'if_statement', 'children': ['209', '214']},{'id': '209', 'type': 'call', 'children': ['210', '213']},{'id': '210', 'type': 'attribute', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'crop'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '213', 'type': 'argument_list', 'children': []},{'id': '214', 'type': 'block', 'children': ['215']},{'id': '215', 'type': 'expression_statement', 'children': ['216']},{'id': '216', 'type': 'call', 'children': ['217', '220']},{'id': '217', 'type': 'attribute', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'rect'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'setX'},{'id': '220', 'type': 'argument_list', 'children': ['221']},{'id': '221', 'type': 'binary_operator', 'children': ['222', '227'], 'value': '-'},{'id': '222', 'type': 'call', 'children': ['223', '226']},{'id': '223', 'type': 'attribute', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'rect'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'width'},{'id': '226', 'type': 'argument_list', 'children': []},{'id': '227', 'type': 'call', 'children': ['228', '231']},{'id': '228', 'type': 'attribute', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'crop'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '231', 'type': 'argument_list', 'children': []},{'id': '232', 'type': 'if_statement', 'children': ['233', '238']},{'id': '233', 'type': 'call', 'children': ['234', '237']},{'id': '234', 'type': 'attribute', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'crop'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '237', 'type': 'argument_list', 'children': []},{'id': '238', 'type': 'block', 'children': ['239']},{'id': '239', 'type': 'expression_statement', 'children': ['240']},{'id': '240', 'type': 'call', 'children': ['241', '244']},{'id': '241', 'type': 'attribute', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'rect'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'setY'},{'id': '244', 'type': 'argument_list', 'children': ['245']},{'id': '245', 'type': 'binary_operator', 'children': ['246', '251'], 'value': '-'},{'id': '246', 'type': 'call', 'children': ['247', '250']},{'id': '247', 'type': 'attribute', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'rect'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'height'},{'id': '250', 'type': 'argument_list', 'children': []},{'id': '251', 'type': 'call', 'children': ['252', '255']},{'id': '252', 'type': 'attribute', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'crop'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '255', 'type': 'argument_list', 'children': []},{'id': '256', 'type': 'expression_statement', 'children': ['257']},{'id': '257', 'type': 'assignment', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'pixmap'},{'id': '259', 'type': 'call', 'children': ['260', '265']},{'id': '260', 'type': 'attribute', 'children': ['261', '264']},{'id': '261', 'type': 'attribute', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'QtGui'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'QPixmap'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'grabWidget'},{'id': '265', 'type': 'argument_list', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'widget'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'rect'},{'id': '268', 'type': 'else_clause', 'children': ['269']},{'id': '269', 'type': 'block', 'children': ['270']},{'id': '270', 'type': 'expression_statement', 'children': ['271']},{'id': '271', 'type': 'assignment', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'pixmap'},{'id': '273', 'type': 'call', 'children': ['274', '279']},{'id': '274', 'type': 'attribute', 'children': ['275', '278']},{'id': '275', 'type': 'attribute', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'QtGui'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'QPixmap'},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'grabWidget'},{'id': '279', 'type': 'argument_list', 'children': ['280']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'widget'},{'id': '281', 'type': 'expression_statement', 'children': ['282']},{'id': '282', 'type': 'assignment', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'scaled'},{'id': '284', 'type': 'call', 'children': ['285', '288']},{'id': '285', 'type': 'attribute', 'children': ['286', '287']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'property'},{'id': '288', 'type': 'argument_list', 'children': ['289']},{'id': '289', 'type': 'string', 'children': [], 'value': "'scaled'"},{'id': '290', 'type': 'if_statement', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'scaled'},{'id': '292', 'type': 'block', 'children': ['293']},{'id': '293', 'type': 'expression_statement', 'children': ['294']},{'id': '294', 'type': 'assignment', 'children': ['295', '296']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'pixmap'},{'id': '296', 'type': 'call', 'children': ['297', '300']},{'id': '297', 'type': 'attribute', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'pixmap'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'scaled'},{'id': '300', 'type': 'argument_list', 'children': ['301', '308', '315', '320']},{'id': '301', 'type': 'binary_operator', 'children': ['302', '307'], 'value': '*'},{'id': '302', 'type': 'call', 'children': ['303', '306']},{'id': '303', 'type': 'attribute', 'children': ['304', '305']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'pixmap'},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'width'},{'id': '306', 'type': 'argument_list', 'children': []},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'scaled'},{'id': '308', 'type': 'binary_operator', 'children': ['309', '314'], 'value': '*'},{'id': '309', 'type': 'call', 'children': ['310', '313']},{'id': '310', 'type': 'attribute', 'children': ['311', '312']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'pixmap'},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'height'},{'id': '313', 'type': 'argument_list', 'children': []},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'scaled'},{'id': '315', 'type': 'attribute', 'children': ['316', '319']},{'id': '316', 'type': 'attribute', 'children': ['317', '318']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'QtCore'},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'Qt'},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'KeepAspectRatio'},{'id': '320', 'type': 'attribute', 'children': ['321', '324']},{'id': '321', 'type': 'attribute', 'children': ['322', '323']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'QtCore'},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'Qt'},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'SmoothTransformation'},{'id': '325', 'type': 'expression_statement', 'children': ['326']},{'id': '326', 'type': 'assignment', 'children': ['327', '328']},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'kwds'},{'id': '328', 'type': 'dictionary', 'children': []},{'id': '329', 'type': 'expression_statement', 'children': ['330']},{'id': '330', 'type': 'assignment', 'children': ['331', '334']},{'id': '331', 'type': 'subscript', 'children': ['332', '333']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'kwds'},{'id': '333', 'type': 'string', 'children': [], 'value': "'whatsThis'"},{'id': '334', 'type': 'call', 'children': ['335', '338']},{'id': '335', 'type': 'attribute', 'children': ['336', '337']},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'widget'},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'whatsThis'},{'id': '338', 'type': 'argument_list', 'children': []},{'id': '339', 'type': 'expression_statement', 'children': ['340']},{'id': '340', 'type': 'assignment', 'children': ['341', '344']},{'id': '341', 'type': 'subscript', 'children': ['342', '343']},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'kwds'},{'id': '343', 'type': 'string', 'children': [], 'value': "'toolTip'"},{'id': '344', 'type': 'call', 'children': ['345', '348']},{'id': '345', 'type': 'attribute', 'children': ['346', '347']},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'widget'},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'toolTip'},{'id': '348', 'type': 'argument_list', 'children': []},{'id': '349', 'type': 'expression_statement', 'children': ['350']},{'id': '350', 'type': 'assignment', 'children': ['351', '354']},{'id': '351', 'type': 'subscript', 'children': ['352', '353']},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'kwds'},{'id': '353', 'type': 'string', 'children': [], 'value': "'windowTitle'"},{'id': '354', 'type': 'call', 'children': ['355', '358']},{'id': '355', 'type': 'attribute', 'children': ['356', '357']},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'widget'},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'windowTitle'},{'id': '358', 'type': 'argument_list', 'children': []},{'id': '359', 'type': 'expression_statement', 'children': ['360']},{'id': '360', 'type': 'assignment', 'children': ['361', '364']},{'id': '361', 'type': 'subscript', 'children': ['362', '363']},{'id': '362', 'type': 'identifier', 'children': [], 'value': 'kwds'},{'id': '363', 'type': 'string', 'children': [], 'value': "'objectName'"},{'id': '364', 'type': 'call', 'children': ['365', '368']},{'id': '365', 'type': 'attribute', 'children': ['366', '367']},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'widget'},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'objectName'},{'id': '368', 'type': 'argument_list', 'children': []},{'id': '369', 'type': 'expression_statement', 'children': ['370']},{'id': '370', 'type': 'call', 'children': ['371', '374']},{'id': '371', 'type': 'attribute', 'children': ['372', '373']},{'id': '372', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '373', 'type': 'identifier', 'children': [], 'value': 'setProperty'},{'id': '374', 'type': 'argument_list', 'children': ['375', '376']},{'id': '375', 'type': 'string', 'children': [], 'value': "'caption'"},{'id': '376', 'type': 'call', 'children': ['377', '386']},{'id': '377', 'type': 'attribute', 'children': ['378', '385']},{'id': '378', 'type': 'call', 'children': ['379', '382']},{'id': '379', 'type': 'attribute', 'children': ['380', '381']},{'id': '380', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '381', 'type': 'identifier', 'children': [], 'value': 'property'},{'id': '382', 'type': 'argument_list', 'children': ['383', '384']},{'id': '383', 'type': 'string', 'children': [], 'value': "'caption'"},{'id': '384', 'type': 'string', 'children': [], 'value': "''"},{'id': '385', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '386', 'type': 'argument_list', 'children': ['387']},{'id': '387', 'type': 'dictionary_splat', 'children': ['388']},{'id': '388', 'type': 'identifier', 'children': [], 'value': 'kwds'},{'id': '389', 'type': 'expression_statement', 'children': ['390']},{'id': '390', 'type': 'call', 'children': ['391', '394']},{'id': '391', 'type': 'attribute', 'children': ['392', '393']},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '393', 'type': 'identifier', 'children': [], 'value': 'setProperty'},{'id': '394', 'type': 'argument_list', 'children': ['395', '396']},{'id': '395', 'type': 'string', 'children': [], 'value': "'pixmap'"},{'id': '396', 'type': 'identifier', 'children': [], 'value': 'pixmap'},{'id': '397', 'type': 'expression_statement', 'children': ['398']},{'id': '398', 'type': 'call', 'children': ['399', '402']},{'id': '399', 'type': 'attribute', 'children': ['400', '401']},{'id': '400', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '401', 'type': 'identifier', 'children': [], 'value': 'addPixmap'},{'id': '402', 'type': 'argument_list', 'children': ['403']},{'id': '403', 'type': 'identifier', 'children': [], 'value': 'pixmap'},{'id': '404', 'type': 'return_statement', 'children': ['405']},{'id': '405', 'type': 'call', 'children': ['406', '413']},{'id': '406', 'type': 'attribute', 'children': ['407', '412']},{'id': '407', 'type': 'call', 'children': ['408', '409']},{'id': '408', 'type': 'identifier', 'children': [], 'value': 'super'},{'id': '409', 'type': 'argument_list', 'children': ['410', '411']},{'id': '410', 'type': 'identifier', 'children': [], 'value': 'XWalkthroughSnapshot'},{'id': '411', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '412', 'type': 'identifier', 'children': [], 'value': 'prepare'},{'id': '413', 'type': 'argument_list', 'children': []}
def prepare(self): pixmap = self.property('pixmap') if pixmap is not None: return super(XWalkthroughSnapshot, self).prepare() widget = self.property('widget') if type(widget) in (unicode, str): widget = self.findReference(widget) if not widget: return super(XWalkthroughSnapshot, self).prepare() 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 = 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()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'depends'},{'id': '3', 'type': 'parameters', 'children': ['4', '7', '10', '13']},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '6', 'type': 'None', 'children': []},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'after'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'before'},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'default_parameter', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'priority'},{'id': '15', 'type': 'None', 'children': []},{'id': '16', 'type': 'block', 'children': ['17', '43', '57', '76', '97', '173', '178', '184', '195', '217']},{'id': '17', 'type': 'if_statement', 'children': ['18', '37']},{'id': '18', 'type': 'not_operator', 'children': ['19']},{'id': '19', 'type': '()', 'children': ['20']},{'id': '20', 'type': 'boolean_operator', 'children': ['21', '31'], 'value': 'or'},{'id': '21', 'type': 'boolean_operator', 'children': ['22', '25'], 'value': 'or'},{'id': '22', 'type': 'comparison_operator', 'children': ['23', '24'], 'value': 'is'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '24', 'type': 'None', 'children': []},{'id': '25', 'type': 'call', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'inspect'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'ismethod'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '31', 'type': 'call', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'inspect'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'isfunction'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '37', 'type': 'block', 'children': ['38']},{'id': '38', 'type': 'raise_statement', 'children': ['39']},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'string', 'children': [], 'value': '"depends decorator can only be used on functions or methods"'},{'id': '43', 'type': 'if_statement', 'children': ['44', '51']},{'id': '44', 'type': 'not_operator', 'children': ['45']},{'id': '45', 'type': '()', 'children': ['46']},{'id': '46', 'type': 'boolean_operator', 'children': ['47', '50'], 'value': 'or'},{'id': '47', 'type': 'boolean_operator', 'children': ['48', '49'], 'value': 'or'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'after'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'before'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'priority'},{'id': '51', 'type': 'block', 'children': ['52']},{'id': '52', 'type': 'raise_statement', 'children': ['53']},{'id': '53', 'type': 'call', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'string', 'children': [], 'value': '"depends decorator needs at least one argument"'},{'id': '57', 'type': 'if_statement', 'children': ['58', '61']},{'id': '58', 'type': 'comparison_operator', 'children': ['59', '60'], 'value': 'is'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '60', 'type': 'None', 'children': []},{'id': '61', 'type': 'block', 'children': ['62']},{'id': '62', 'type': 'return_statement', 'children': ['63']},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'partial'},{'id': '65', 'type': 'argument_list', 'children': ['66', '67', '70', '73']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'depends'},{'id': '67', 'type': 'keyword_argument', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'after'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'after'},{'id': '70', 'type': 'keyword_argument', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'before'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'before'},{'id': '73', 'type': 'keyword_argument', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'priority'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'priority'},{'id': '76', 'type': 'function_definition', 'children': ['77', '78', '81']},{'id': '77', 'type': 'function_name', 'children': [], 'value': 'self_check'},{'id': '78', 'type': 'parameters', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '81', 'type': 'block', 'children': ['82']},{'id': '82', 'type': 'if_statement', 'children': ['83', '86']},{'id': '83', 'type': 'comparison_operator', 'children': ['84', '85'], 'value': '=='},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '86', 'type': 'block', 'children': ['87']},{'id': '87', 'type': 'raise_statement', 'children': ['88']},{'id': '88', 'type': 'call', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'call', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'string', 'children': [], 'value': '"Test \'{}\' cannot depend on itself"'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '97', 'type': 'function_definition', 'children': ['98', '99', '104']},{'id': '98', 'type': 'function_name', 'children': [], 'value': 'handle_dep'},{'id': '99', 'type': 'parameters', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'conditions'},{'id': '101', 'type': 'default_parameter', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': '_before'},{'id': '103', 'type': 'True', 'children': []},{'id': '104', 'type': 'block', 'children': ['105']},{'id': '105', 'type': 'if_statement', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'conditions'},{'id': '107', 'type': 'block', 'children': ['108', '121']},{'id': '108', 'type': 'if_statement', 'children': ['109', '115']},{'id': '109', 'type': 'comparison_operator', 'children': ['110', '114'], 'value': 'is'},{'id': '110', 'type': 'call', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'conditions'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '115', 'type': 'block', 'children': ['116']},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'assignment', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'conditions'},{'id': '119', 'type': 'list', 'children': ['120'], 'value': '[conditions]'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'conditions'},{'id': '121', 'type': 'for_statement', 'children': ['122', '123', '124']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'cond'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'conditions'},{'id': '124', 'type': 'block', 'children': ['125', '138', '146']},{'id': '125', 'type': 'if_statement', 'children': ['126', '131']},{'id': '126', 'type': 'call', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '128', 'type': 'argument_list', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'cond'},{'id': '130', 'type': 'string', 'children': [], 'value': "'__call__'"},{'id': '131', 'type': 'block', 'children': ['132']},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'assignment', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'cond'},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'cond'},{'id': '137', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'call', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'self_check'},{'id': '141', 'type': 'argument_list', 'children': ['142', '145']},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '144', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'cond'},{'id': '146', 'type': 'if_statement', 'children': ['147', '148', '160']},{'id': '147', 'type': 'identifier', 'children': [], 'value': '_before'},{'id': '148', 'type': 'block', 'children': ['149']},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'call', 'children': ['151', '156']},{'id': '151', 'type': 'attribute', 'children': ['152', '155']},{'id': '152', 'type': 'subscript', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'soft_dependencies'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'cond'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '156', 'type': 'argument_list', 'children': ['157']},{'id': '157', 'type': 'attribute', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '159', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '160', 'type': 'else_clause', 'children': ['161']},{'id': '161', 'type': 'block', 'children': ['162']},{'id': '162', 'type': 'expression_statement', 'children': ['163']},{'id': '163', 'type': 'call', 'children': ['164', '171']},{'id': '164', 'type': 'attribute', 'children': ['165', '170']},{'id': '165', 'type': 'subscript', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'dependencies'},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '169', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '171', 'type': 'argument_list', 'children': ['172']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'cond'},{'id': '173', 'type': 'expression_statement', 'children': ['174']},{'id': '174', 'type': 'call', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'handle_dep'},{'id': '176', 'type': 'argument_list', 'children': ['177']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'before'},{'id': '178', 'type': 'expression_statement', 'children': ['179']},{'id': '179', 'type': 'call', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'handle_dep'},{'id': '181', 'type': 'argument_list', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'after'},{'id': '183', 'type': 'False', 'children': []},{'id': '184', 'type': 'if_statement', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'priority'},{'id': '186', 'type': 'block', 'children': ['187']},{'id': '187', 'type': 'expression_statement', 'children': ['188']},{'id': '188', 'type': 'assignment', 'children': ['189', '194']},{'id': '189', 'type': 'subscript', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'priorities'},{'id': '191', 'type': 'attribute', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '193', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'priority'},{'id': '195', 'type': 'decorated_definition', 'children': ['196', '201']},{'id': '196', 'type': 'decorator', 'children': ['197']},{'id': '197', 'type': 'call', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'wraps'},{'id': '199', 'type': 'argument_list', 'children': ['200']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '201', 'type': 'function_definition', 'children': ['202', '203', '208']},{'id': '202', 'type': 'function_name', 'children': [], 'value': 'inner'},{'id': '203', 'type': 'parameters', 'children': ['204', '206']},{'id': '204', 'type': 'list_splat_pattern', 'children': ['205']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '206', 'type': 'dictionary_splat_pattern', 'children': ['207']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '208', 'type': 'block', 'children': ['209']},{'id': '209', 'type': 'return_statement', 'children': ['210']},{'id': '210', 'type': 'call', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '212', 'type': 'argument_list', 'children': ['213', '215']},{'id': '213', 'type': 'list_splat', 'children': ['214']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '215', 'type': 'dictionary_splat', 'children': ['216']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '217', 'type': 'return_statement', 'children': ['218']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'inner'}
def depends(func=None, after=None, before=None, priority=None): 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") 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
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_translate_language_name'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'language_name'},{'id': '6', 'type': 'block', 'children': ['7', '15', '19', '44', '73', '98', '112', '128', '145', '152']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'languages'},{'id': '10', 'type': 'call', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'languages'},{'id': '14', 'type': 'argument_list', 'children': []},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'language_id'},{'id': '18', 'type': 'None', 'children': []},{'id': '19', 'type': 'for_statement', 'children': ['20', '23', '28']},{'id': '20', 'type': 'pattern_list', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'ideone_index'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'ideone_language'},{'id': '23', 'type': 'call', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'languages'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '27', 'type': 'argument_list', 'children': []},{'id': '28', 'type': 'block', 'children': ['29']},{'id': '29', 'type': 'if_statement', 'children': ['30', '41']},{'id': '30', 'type': 'comparison_operator', 'children': ['31', '36'], 'value': '=='},{'id': '31', 'type': 'call', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'ideone_language'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '35', 'type': 'argument_list', 'children': []},{'id': '36', 'type': 'call', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'language_name'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '40', 'type': 'argument_list', 'children': []},{'id': '41', 'type': 'block', 'children': ['42']},{'id': '42', 'type': 'return_statement', 'children': ['43']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'ideone_index'},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'simple_languages'},{'id': '47', 'type': 'call', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '49', 'type': 'generator_expression', 'children': ['50', '64']},{'id': '50', 'type': 'tuple', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '52', 'type': 'call', 'children': ['53', '63']},{'id': '53', 'type': 'attribute', 'children': ['54', '62']},{'id': '54', 'type': 'subscript', 'children': ['55', '61']},{'id': '55', 'type': 'call', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'string', 'children': [], 'value': "'('"},{'id': '61', 'type': 'integer', 'children': [], 'value': '0'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '63', 'type': 'argument_list', 'children': []},{'id': '64', 'type': 'for_in_clause', 'children': ['65', '68']},{'id': '65', 'type': 'tuple_pattern', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '68', 'type': 'call', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'languages'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '72', 'type': 'argument_list', 'children': []},{'id': '73', 'type': 'for_statement', 'children': ['74', '77', '82']},{'id': '74', 'type': 'pattern_list', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'ideone_index'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'simple_name'},{'id': '77', 'type': 'call', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'simple_languages'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '81', 'type': 'argument_list', 'children': []},{'id': '82', 'type': 'block', 'children': ['83']},{'id': '83', 'type': 'if_statement', 'children': ['84', '95']},{'id': '84', 'type': 'comparison_operator', 'children': ['85', '90'], 'value': '=='},{'id': '85', 'type': 'call', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'simple_name'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '89', 'type': 'argument_list', 'children': []},{'id': '90', 'type': 'call', 'children': ['91', '94']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'language_name'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '94', 'type': 'argument_list', 'children': []},{'id': '95', 'type': 'block', 'children': ['96']},{'id': '96', 'type': 'return_statement', 'children': ['97']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'ideone_index'},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'language_choices'},{'id': '101', 'type': 'binary_operator', 'children': ['102', '107'], 'value': '+'},{'id': '102', 'type': 'call', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'languages'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '106', 'type': 'argument_list', 'children': []},{'id': '107', 'type': 'call', 'children': ['108', '111']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'simple_languages'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '111', 'type': 'argument_list', 'children': []},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'assignment', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'similar_choices'},{'id': '115', 'type': 'call', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'difflib'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'get_close_matches'},{'id': '119', 'type': 'argument_list', 'children': ['120', '121', '122', '125']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'language_name'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'language_choices'},{'id': '122', 'type': 'keyword_argument', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '124', 'type': 'integer', 'children': [], 'value': '3'},{'id': '125', 'type': 'keyword_argument', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'cutoff'},{'id': '127', 'type': 'float', 'children': [], 'value': '0.3'},{'id': '128', 'type': 'expression_statement', 'children': ['129']},{'id': '129', 'type': 'assignment', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'similar_choices_string'},{'id': '131', 'type': 'call', 'children': ['132', '135']},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'string', 'children': [], 'value': '", "'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '135', 'type': 'argument_list', 'children': ['136']},{'id': '136', 'type': 'list_comprehension', 'children': ['137', '142']},{'id': '137', 'type': 'binary_operator', 'children': ['138', '141'], 'value': '+'},{'id': '138', 'type': 'binary_operator', 'children': ['139', '140'], 'value': '+'},{'id': '139', 'type': 'string', 'children': [], 'value': '"\'"'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '141', 'type': 'string', 'children': [], 'value': '"\'"'},{'id': '142', 'type': 'for_in_clause', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'similar_choices'},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'assignment', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'error_string'},{'id': '148', 'type': '()', 'children': ['149']},{'id': '149', 'type': 'concatenated_string', 'children': ['150', '151']},{'id': '150', 'type': 'string', 'children': [], 'value': '"Couldn\'t match \'%s\' to an Ideone accepted language.\\n"'},{'id': '151', 'type': 'string', 'children': [], 'value': '"Did you mean one of the following: %s"'},{'id': '152', 'type': 'raise_statement', 'children': ['153']},{'id': '153', 'type': 'call', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'IdeoneError'},{'id': '155', 'type': 'argument_list', 'children': ['156']},{'id': '156', 'type': 'binary_operator', 'children': ['157', '158'], 'value': '%'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'error_string'},{'id': '158', 'type': 'tuple', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'language_name'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'similar_choices_string'}
def _translate_language_name(self, language_name): languages = self.languages() language_id = None for ideone_index, ideone_language in languages.items(): if ideone_language.lower() == language_name.lower(): return ideone_index 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 language_choices = languages.values() + simple_languages.values() similar_choices = difflib.get_close_matches(language_name, language_choices, n=3, cutoff=0.3) 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))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'headerSortAscending'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '13']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'call', 'children': ['8', '11']},{'id': '8', 'type': 'attribute', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'setSortingEnabled'},{'id': '11', 'type': 'argument_list', 'children': ['12']},{'id': '12', 'type': 'True', 'children': []},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'call', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'sortByColumn'},{'id': '18', 'type': 'argument_list', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '21', 'type': 'identifier', 'children': [], 'value': '_headerIndex'},{'id': '22', 'type': 'attribute', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'QtCore'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'Qt'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'AscendingOrder'}
def headerSortAscending( self ): self.setSortingEnabled(True) self.sortByColumn(self._headerIndex, QtCore.Qt.AscendingOrder)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'headerSortDescending'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '13']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'call', 'children': ['8', '11']},{'id': '8', 'type': 'attribute', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'setSortingEnabled'},{'id': '11', 'type': 'argument_list', 'children': ['12']},{'id': '12', 'type': 'True', 'children': []},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'call', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'sortByColumn'},{'id': '18', 'type': 'argument_list', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '21', 'type': 'identifier', 'children': [], 'value': '_headerIndex'},{'id': '22', 'type': 'attribute', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'QtCore'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'Qt'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'DescendingOrder'}
def headerSortDescending( self ): self.setSortingEnabled(True) self.sortByColumn(self._headerIndex, QtCore.Qt.DescendingOrder)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'from_api'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'api'},{'id': '6', 'type': 'dictionary_splat_pattern', 'children': ['7']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '8', 'type': 'block', 'children': ['9', '19', '90', '114', '147', '172', '179', '252']},{'id': '9', 'type': 'if_statement', 'children': ['10', '14']},{'id': '10', 'type': 'not_operator', 'children': ['11']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '13', 'type': 'identifier', 'children': [], 'value': '_api_attrs'},{'id': '14', 'type': 'block', 'children': ['15']},{'id': '15', 'type': 'raise_statement', 'children': ['16']},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'NotImplementedError'},{'id': '18', 'type': 'argument_list', 'children': []},{'id': '19', 'type': 'function_definition', 'children': ['20', '21', '23']},{'id': '20', 'type': 'function_name', 'children': [], 'value': 'resolve_attribute_type'},{'id': '21', 'type': 'parameters', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'attr_type'},{'id': '23', 'type': 'block', 'children': ['24', '37', '46', '59', '68', '88']},{'id': '24', 'type': 'while_statement', 'children': ['25', '30']},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '27', 'type': 'argument_list', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'attr_type'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '30', 'type': 'block', 'children': ['31']},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'attr_type'},{'id': '34', 'type': 'subscript', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'attr_type'},{'id': '36', 'type': 'integer', 'children': [], 'value': '0'},{'id': '37', 'type': 'if_statement', 'children': ['38', '41']},{'id': '38', 'type': 'comparison_operator', 'children': ['39', '40'], 'value': '=='},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'attr_type'},{'id': '40', 'type': 'string', 'children': [], 'value': "'self'"},{'id': '41', 'type': 'block', 'children': ['42']},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'attr_type'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '46', 'type': 'if_statement', 'children': ['47', '50']},{'id': '47', 'type': 'comparison_operator', 'children': ['48', '49'], 'value': '=='},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'attr_type'},{'id': '49', 'type': 'string', 'children': [], 'value': "'date'"},{'id': '50', 'type': 'block', 'children': ['51']},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'attr_type'},{'id': '54', 'type': 'attribute', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'fromtimestamp'},{'id': '59', 'type': 'if_statement', 'children': ['60', '63']},{'id': '60', 'type': 'comparison_operator', 'children': ['61', '62'], 'value': 'is'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'attr_type'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '63', 'type': 'block', 'children': ['64']},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'attr_type'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'unicode'},{'id': '68', 'type': 'if_statement', 'children': ['69', '74']},{'id': '69', 'type': 'call', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '71', 'type': 'argument_list', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'attr_type'},{'id': '73', 'type': 'string', 'children': [], 'value': "'from_api'"},{'id': '74', 'type': 'block', 'children': ['75']},{'id': '75', 'type': 'return_statement', 'children': ['76']},{'id': '76', 'type': 'lambda', 'children': ['77', '80']},{'id': '77', 'type': 'lambda_parameters', 'children': ['78']},{'id': '78', 'type': 'dictionary_splat_pattern', 'children': ['79']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'kw'},{'id': '80', 'type': 'call', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'attr_type'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'from_api'},{'id': '84', 'type': 'argument_list', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'api'},{'id': '86', 'type': 'dictionary_splat', 'children': ['87']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'kw'},{'id': '88', 'type': 'return_statement', 'children': ['89']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'attr_type'},{'id': '90', 'type': 'function_definition', 'children': ['91', '92', '95']},{'id': '91', 'type': 'function_name', 'children': [], 'value': 'instantiate_attr'},{'id': '92', 'type': 'parameters', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'attr_value'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'attr_type'},{'id': '95', 'type': 'block', 'children': ['96', '109']},{'id': '96', 'type': 'if_statement', 'children': ['97', '102']},{'id': '97', 'type': 'call', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '99', 'type': 'argument_list', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'attr_value'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '102', 'type': 'block', 'children': ['103']},{'id': '103', 'type': 'return_statement', 'children': ['104']},{'id': '104', 'type': 'call', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'attr_type'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'dictionary_splat', 'children': ['108']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'attr_value'},{'id': '109', 'type': 'return_statement', 'children': ['110']},{'id': '110', 'type': 'call', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'attr_type'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'attr_value'},{'id': '114', 'type': 'function_definition', 'children': ['115', '116', '119']},{'id': '115', 'type': 'function_name', 'children': [], 'value': 'instantiate_array'},{'id': '116', 'type': 'parameters', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'attr_values'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'attr_type'},{'id': '119', 'type': 'block', 'children': ['120', '124', '137']},{'id': '120', 'type': 'expression_statement', 'children': ['121']},{'id': '121', 'type': 'assignment', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'instantiate_attr'},{'id': '124', 'type': 'if_statement', 'children': ['125', '132']},{'id': '125', 'type': 'call', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '127', 'type': 'argument_list', 'children': ['128', '131']},{'id': '128', 'type': 'subscript', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'attr_values'},{'id': '130', 'type': 'integer', 'children': [], 'value': '0'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '132', 'type': 'block', 'children': ['133']},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'assignment', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'instantiate_array'},{'id': '137', 'type': 'return_statement', 'children': ['138']},{'id': '138', 'type': 'list_comprehension', 'children': ['139', '144']},{'id': '139', 'type': 'call', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '141', 'type': 'argument_list', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'attr_type'},{'id': '144', 'type': 'for_in_clause', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'attr_values'},{'id': '147', 'type': 'function_definition', 'children': ['148', '149', '152']},{'id': '148', 'type': 'function_name', 'children': [], 'value': 'instantiate'},{'id': '149', 'type': 'parameters', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'attr_value'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'attr_type'},{'id': '152', 'type': 'block', 'children': ['153', '166']},{'id': '153', 'type': 'if_statement', 'children': ['154', '159']},{'id': '154', 'type': 'call', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '156', 'type': 'argument_list', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'attr_value'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '159', 'type': 'block', 'children': ['160']},{'id': '160', 'type': 'return_statement', 'children': ['161']},{'id': '161', 'type': 'call', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'instantiate_array'},{'id': '163', 'type': 'argument_list', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'attr_value'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'attr_type'},{'id': '166', 'type': 'return_statement', 'children': ['167']},{'id': '167', 'type': 'call', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'instantiate_attr'},{'id': '169', 'type': 'argument_list', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'attr_value'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'attr_type'},{'id': '172', 'type': 'expression_statement', 'children': ['173']},{'id': '173', 'type': 'assignment', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '175', 'type': 'call', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '177', 'type': 'argument_list', 'children': ['178']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'api'},{'id': '179', 'type': 'for_statement', 'children': ['180', '184', '187']},{'id': '180', 'type': 'pattern_list', 'children': ['181', '182', '183']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'attr_name'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'attr_type'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'attr_default'},{'id': '184', 'type': 'attribute', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '186', 'type': 'identifier', 'children': [], 'value': '_api_attrs'},{'id': '187', 'type': 'block', 'children': ['188', '198', '216', '223', '236', '245']},{'id': '188', 'type': 'expression_statement', 'children': ['189']},{'id': '189', 'type': 'assignment', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'attr_value'},{'id': '191', 'type': 'call', 'children': ['192', '195']},{'id': '192', 'type': 'attribute', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '195', 'type': 'argument_list', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'attr_name'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'attr_default'},{'id': '198', 'type': 'if_statement', 'children': ['199', '202']},{'id': '199', 'type': 'comparison_operator', 'children': ['200', '201'], 'value': 'is'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'attr_value'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '202', 'type': 'block', 'children': ['203']},{'id': '203', 'type': 'raise_statement', 'children': ['204']},{'id': '204', 'type': 'call', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '206', 'type': 'argument_list', 'children': ['207']},{'id': '207', 'type': 'call', 'children': ['208', '211']},{'id': '208', 'type': 'attribute', 'children': ['209', '210']},{'id': '209', 'type': 'string', 'children': [], 'value': "'{} requires argument {}'"},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '211', 'type': 'argument_list', 'children': ['212', '215']},{'id': '212', 'type': 'attribute', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '214', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'attr_name'},{'id': '216', 'type': 'expression_statement', 'children': ['217']},{'id': '217', 'type': 'assignment', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'attr_type'},{'id': '219', 'type': 'call', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'resolve_attribute_type'},{'id': '221', 'type': 'argument_list', 'children': ['222']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'attr_type'},{'id': '223', 'type': 'if_statement', 'children': ['224', '227']},{'id': '224', 'type': 'comparison_operator', 'children': ['225', '226'], 'value': '!='},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'attr_value'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'attr_default'},{'id': '227', 'type': 'block', 'children': ['228']},{'id': '228', 'type': 'expression_statement', 'children': ['229']},{'id': '229', 'type': 'assignment', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'attr_value'},{'id': '231', 'type': 'call', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'instantiate'},{'id': '233', 'type': 'argument_list', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'attr_value'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'attr_type'},{'id': '236', 'type': 'if_statement', 'children': ['237', '240']},{'id': '237', 'type': 'comparison_operator', 'children': ['238', '239'], 'value': '=='},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'attr_name'},{'id': '239', 'type': 'string', 'children': [], 'value': "'from'"},{'id': '240', 'type': 'block', 'children': ['241']},{'id': '241', 'type': 'expression_statement', 'children': ['242']},{'id': '242', 'type': 'assignment', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'attr_name'},{'id': '244', 'type': 'string', 'children': [], 'value': "'froom'"},{'id': '245', 'type': 'expression_statement', 'children': ['246']},{'id': '246', 'type': 'call', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'setattr'},{'id': '248', 'type': 'argument_list', 'children': ['249', '250', '251']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'attr_name'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'attr_value'},{'id': '252', 'type': 'return_statement', 'children': ['253']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'instance'}
def from_api(cls, api, **kwargs): if not cls._api_attrs: raise NotImplementedError() def resolve_attribute_type(attr_type): while isinstance(attr_type, list): attr_type = attr_type[0] if attr_type == 'self': attr_type = cls if attr_type == 'date': attr_type = datetime.datetime.fromtimestamp if attr_type is str: attr_type = unicode 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: attr_value = kwargs.get(attr_name, attr_default) if attr_value is TypeError: raise TypeError('{} requires argument {}'.format(cls.__name__, attr_name)) attr_type = resolve_attribute_type(attr_type) if attr_value != attr_default: attr_value = instantiate(attr_value, attr_type) if attr_name == 'from': attr_name = 'froom' setattr(instance, attr_name, attr_value) return instance
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'updateEditor'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '14', '22', '32', '36', '40', '53', '101', '110']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'rule'},{'id': '9', 'type': 'call', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'currentRule'},{'id': '13', 'type': 'argument_list', 'children': []},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'operator'},{'id': '17', 'type': 'call', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'currentOperator'},{'id': '21', 'type': 'argument_list', 'children': []},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'widget'},{'id': '25', 'type': 'call', 'children': ['26', '31']},{'id': '26', 'type': 'attribute', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'uiWidgetAREA'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'widget'},{'id': '31', 'type': 'argument_list', 'children': []},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'editorType'},{'id': '35', 'type': 'None', 'children': []},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '39', 'type': 'string', 'children': [], 'value': "''"},{'id': '40', 'type': 'if_statement', 'children': ['41', '43']},{'id': '41', 'type': '()', 'children': ['42']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'rule'},{'id': '43', 'type': 'block', 'children': ['44']},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'editorType'},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'rule'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'editorType'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'operator'},{'id': '53', 'type': 'if_statement', 'children': ['54', '65', '67']},{'id': '54', 'type': '()', 'children': ['55']},{'id': '55', 'type': 'boolean_operator', 'children': ['56', '59'], 'value': 'and'},{'id': '56', 'type': 'boolean_operator', 'children': ['57', '58'], 'value': 'and'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'widget'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'editorType'},{'id': '59', 'type': 'comparison_operator', 'children': ['60', '64'], 'value': '=='},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'widget'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'editorType'},{'id': '65', 'type': 'block', 'children': ['66']},{'id': '66', 'type': 'return_statement', 'children': []},{'id': '67', 'type': 'elif_clause', 'children': ['68', '70']},{'id': '68', 'type': '()', 'children': ['69']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'widget'},{'id': '70', 'type': 'block', 'children': ['71', '88', '95']},{'id': '71', 'type': 'if_statement', 'children': ['72', '79']},{'id': '72', 'type': '()', 'children': ['73']},{'id': '73', 'type': 'comparison_operator', 'children': ['74', '78'], 'value': '!='},{'id': '74', 'type': 'call', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'widget'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'QWidget'},{'id': '79', 'type': 'block', 'children': ['80']},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '83', 'type': 'call', 'children': ['84', '87']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'widget'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '87', 'type': 'argument_list', 'children': []},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'call', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'widget'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'setParent'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'None', 'children': []},{'id': '95', 'type': 'expression_statement', 'children': ['96']},{'id': '96', 'type': 'call', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'widget'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'deleteLater'},{'id': '100', 'type': 'argument_list', 'children': []},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'call', 'children': ['103', '108']},{'id': '103', 'type': 'attribute', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'uiWidgetAREA'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'setWidget'},{'id': '108', 'type': 'argument_list', 'children': ['109']},{'id': '109', 'type': 'None', 'children': []},{'id': '110', 'type': 'if_statement', 'children': ['111', '113']},{'id': '111', 'type': '()', 'children': ['112']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'editorType'},{'id': '113', 'type': 'block', 'children': ['114', '121', '177', '186']},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'assignment', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'widget'},{'id': '117', 'type': 'call', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'editorType'},{'id': '119', 'type': 'argument_list', 'children': ['120']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '121', 'type': 'if_statement', 'children': ['122', '128']},{'id': '122', 'type': '()', 'children': ['123']},{'id': '123', 'type': 'call', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '125', 'type': 'argument_list', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'widget'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'QLineEdit'},{'id': '128', 'type': 'block', 'children': ['129', '137', '162']},{'id': '129', 'type': 'expression_statement', 'children': ['130']},{'id': '130', 'type': 'assignment', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'terms'},{'id': '132', 'type': 'call', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'rule'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'completionTerms'},{'id': '136', 'type': 'argument_list', 'children': []},{'id': '137', 'type': 'if_statement', 'children': ['138', '141']},{'id': '138', 'type': '()', 'children': ['139']},{'id': '139', 'type': 'not_operator', 'children': ['140']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'terms'},{'id': '141', 'type': 'block', 'children': ['142', '150']},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'assignment', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'qwidget'},{'id': '145', 'type': 'call', 'children': ['146', '149']},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'queryBuilderWidget'},{'id': '149', 'type': 'argument_list', 'children': []},{'id': '150', 'type': 'if_statement', 'children': ['151', '153']},{'id': '151', 'type': '()', 'children': ['152']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'qwidget'},{'id': '153', 'type': 'block', 'children': ['154']},{'id': '154', 'type': 'expression_statement', 'children': ['155']},{'id': '155', 'type': 'assignment', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'terms'},{'id': '157', 'type': 'call', 'children': ['158', '161']},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'qwidget'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'completionTerms'},{'id': '161', 'type': 'argument_list', 'children': []},{'id': '162', 'type': 'if_statement', 'children': ['163', '165']},{'id': '163', 'type': '()', 'children': ['164']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'terms'},{'id': '165', 'type': 'block', 'children': ['166']},{'id': '166', 'type': 'expression_statement', 'children': ['167']},{'id': '167', 'type': 'call', 'children': ['168', '171']},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'widget'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'setCompleter'},{'id': '171', 'type': 'argument_list', 'children': ['172']},{'id': '172', 'type': 'call', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'XQueryCompleter'},{'id': '174', 'type': 'argument_list', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'terms'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'widget'},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'call', 'children': ['179', '184']},{'id': '179', 'type': 'attribute', 'children': ['180', '183']},{'id': '180', 'type': 'attribute', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'uiWidgetAREA'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'setWidget'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'widget'},{'id': '186', 'type': 'if_statement', 'children': ['187', '194']},{'id': '187', 'type': '()', 'children': ['188']},{'id': '188', 'type': 'comparison_operator', 'children': ['189', '193'], 'value': '!='},{'id': '189', 'type': 'call', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '191', 'type': 'argument_list', 'children': ['192']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'widget'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'QWidget'},{'id': '194', 'type': 'block', 'children': ['195']},{'id': '195', 'type': 'expression_statement', 'children': ['196']},{'id': '196', 'type': 'call', 'children': ['197', '200']},{'id': '197', 'type': 'attribute', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'widget'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'setText'},{'id': '200', 'type': 'argument_list', 'children': ['201']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'text'}
def updateEditor( self ): rule = self.currentRule() operator = self.currentOperator() widget = self.uiWidgetAREA.widget() editorType = None text = '' if ( rule ): editorType = rule.editorType(operator) 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) 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)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'StreamMetrics'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'request_iterator'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '7', 'type': 'block', 'children': ['8', '15', '23', '27', '31', '46', '77', '108', '119', '130', '147', '153', '159', '163', '167', '173', '402']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'call', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'LOG'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '13', 'type': 'argument_list', 'children': ['14']},{'id': '14', 'type': 'string', 'children': [], 'value': '"StreamMetrics called"'},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'collect_args'},{'id': '18', 'type': '()', 'children': ['19']},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'next'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'request_iterator'},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'max_metrics_buffer'},{'id': '26', 'type': 'integer', 'children': [], 'value': '0'},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'max_collect_duration'},{'id': '30', 'type': 'integer', 'children': [], 'value': '0'},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'cfg'},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'Metric'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'keyword_argument', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'pb'},{'id': '39', 'type': 'subscript', 'children': ['40', '45']},{'id': '40', 'type': 'attribute', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'collect_args'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'Metrics_Arg'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'metrics'},{'id': '45', 'type': 'integer', 'children': [], 'value': '0'},{'id': '46', 'type': 'try_statement', 'children': ['47', '59']},{'id': '47', 'type': 'block', 'children': ['48']},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'max_metrics_buffer'},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'subscript', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'cfg'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '58', 'type': 'string', 'children': [], 'value': '"max-metrics-buffer"'},{'id': '59', 'type': 'except_clause', 'children': ['60', '64']},{'id': '60', 'type': 'as_pattern', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '62', 'type': 'as_pattern_target', 'children': ['63']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'ex'},{'id': '64', 'type': 'block', 'children': ['65']},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'call', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'LOG'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'call', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'string', 'children': [], 'value': '"Unable to get schedule parameters: {}"'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'ex'},{'id': '77', 'type': 'try_statement', 'children': ['78', '90']},{'id': '78', 'type': 'block', 'children': ['79']},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'max_collect_duration'},{'id': '82', 'type': 'call', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'subscript', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'cfg'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '89', 'type': 'string', 'children': [], 'value': '"max-collect-duration"'},{'id': '90', 'type': 'except_clause', 'children': ['91', '95']},{'id': '91', 'type': 'as_pattern', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '93', 'type': 'as_pattern_target', 'children': ['94']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'ex'},{'id': '95', 'type': 'block', 'children': ['96']},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'call', 'children': ['98', '101']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'LOG'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '101', 'type': 'argument_list', 'children': ['102']},{'id': '102', 'type': 'call', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'string', 'children': [], 'value': '"Unable to get schedule parameters: {}"'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'ex'},{'id': '108', 'type': 'if_statement', 'children': ['109', '112']},{'id': '109', 'type': 'comparison_operator', 'children': ['110', '111'], 'value': '>'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'max_metrics_buffer'},{'id': '111', 'type': 'integer', 'children': [], 'value': '0'},{'id': '112', 'type': 'block', 'children': ['113']},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'assignment', 'children': ['115', '118']},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'max_metrics_buffer'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'max_metrics_buffer'},{'id': '119', 'type': 'if_statement', 'children': ['120', '123']},{'id': '120', 'type': 'comparison_operator', 'children': ['121', '122'], 'value': '>'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'max_collect_duration'},{'id': '122', 'type': 'integer', 'children': [], 'value': '0'},{'id': '123', 'type': 'block', 'children': ['124']},{'id': '124', 'type': 'expression_statement', 'children': ['125']},{'id': '125', 'type': 'assignment', 'children': ['126', '129']},{'id': '126', 'type': 'attribute', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'max_collect_duration'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'max_collect_duration'},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'assignment', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'thread'},{'id': '133', 'type': 'call', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'threading'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'Thread'},{'id': '137', 'type': 'argument_list', 'children': ['138', '143']},{'id': '138', 'type': 'keyword_argument', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '142', 'type': 'identifier', 'children': [], 'value': '_stream_wrapper'},{'id': '143', 'type': 'keyword_argument', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '145', 'type': 'tuple', 'children': ['146']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'collect_args'},{'id': '147', 'type': 'expression_statement', 'children': ['148']},{'id': '148', 'type': 'assignment', 'children': ['149', '152']},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'thread'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'daemon'},{'id': '152', 'type': 'True', 'children': []},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'call', 'children': ['155', '158']},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'thread'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '158', 'type': 'argument_list', 'children': []},{'id': '159', 'type': 'expression_statement', 'children': ['160']},{'id': '160', 'type': 'assignment', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'metrics'},{'id': '162', 'type': 'list', 'children': [], 'value': '[]'},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'assignment', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'metrics_to_stream'},{'id': '166', 'type': 'list', 'children': [], 'value': '[]'},{'id': '167', 'type': 'expression_statement', 'children': ['168']},{'id': '168', 'type': 'assignment', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'stream_timeout'},{'id': '170', 'type': 'attribute', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'max_collect_duration'},{'id': '173', 'type': 'while_statement', 'children': ['174', '179']},{'id': '174', 'type': 'call', 'children': ['175', '178']},{'id': '175', 'type': 'attribute', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'is_active'},{'id': '178', 'type': 'argument_list', 'children': []},{'id': '179', 'type': 'block', 'children': ['180']},{'id': '180', 'type': 'try_statement', 'children': ['181', '223', '276']},{'id': '181', 'type': 'block', 'children': ['182', '190', '206', '219']},{'id': '182', 'type': 'expression_statement', 'children': ['183']},{'id': '183', 'type': 'assignment', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 't_start'},{'id': '185', 'type': 'call', 'children': ['186', '189']},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '189', 'type': 'argument_list', 'children': []},{'id': '190', 'type': 'expression_statement', 'children': ['191']},{'id': '191', 'type': 'assignment', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'metrics'},{'id': '193', 'type': 'call', 'children': ['194', '199']},{'id': '194', 'type': 'attribute', 'children': ['195', '198']},{'id': '195', 'type': 'attribute', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'metrics_queue'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '199', 'type': 'argument_list', 'children': ['200', '203']},{'id': '200', 'type': 'keyword_argument', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'block'},{'id': '202', 'type': 'True', 'children': []},{'id': '203', 'type': 'keyword_argument', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'stream_timeout'},{'id': '206', 'type': 'expression_statement', 'children': ['207']},{'id': '207', 'type': 'assignment', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'elapsed'},{'id': '209', 'type': 'call', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'round'},{'id': '211', 'type': 'argument_list', 'children': ['212']},{'id': '212', 'type': 'binary_operator', 'children': ['213', '218'], 'value': '-'},{'id': '213', 'type': 'call', 'children': ['214', '217']},{'id': '214', 'type': 'attribute', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '217', 'type': 'argument_list', 'children': []},{'id': '218', 'type': 'identifier', 'children': [], 'value': 't_start'},{'id': '219', 'type': 'expression_statement', 'children': ['220']},{'id': '220', 'type': 'augmented_assignment', 'children': ['221', '222'], 'value': '-='},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'stream_timeout'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'elapsed'},{'id': '223', 'type': 'except_clause', 'children': ['224', '227']},{'id': '224', 'type': 'attribute', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'queue'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'Empty'},{'id': '227', 'type': 'block', 'children': ['228', '243', '263', '267', '273']},{'id': '228', 'type': 'expression_statement', 'children': ['229']},{'id': '229', 'type': 'call', 'children': ['230', '233']},{'id': '230', 'type': 'attribute', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'LOG'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '233', 'type': 'argument_list', 'children': ['234']},{'id': '234', 'type': 'call', 'children': ['235', '238']},{'id': '235', 'type': 'attribute', 'children': ['236', '237']},{'id': '236', 'type': 'string', 'children': [], 'value': '"Max collect duration exceeded. Streaming {} metrics"'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '238', 'type': 'argument_list', 'children': ['239']},{'id': '239', 'type': 'call', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '241', 'type': 'argument_list', 'children': ['242']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'metrics_to_stream'},{'id': '243', 'type': 'expression_statement', 'children': ['244']},{'id': '244', 'type': 'assignment', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'metrics_col'},{'id': '246', 'type': 'call', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'CollectReply'},{'id': '248', 'type': 'argument_list', 'children': ['249']},{'id': '249', 'type': 'keyword_argument', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'Metrics_Reply'},{'id': '251', 'type': 'call', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'MetricsReply'},{'id': '253', 'type': 'argument_list', 'children': ['254']},{'id': '254', 'type': 'keyword_argument', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'metrics'},{'id': '256', 'type': 'list_comprehension', 'children': ['257', '260']},{'id': '257', 'type': 'attribute', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'pb'},{'id': '260', 'type': 'for_in_clause', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'metrics_to_stream'},{'id': '263', 'type': 'expression_statement', 'children': ['264']},{'id': '264', 'type': 'assignment', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'metrics_to_stream'},{'id': '266', 'type': 'list', 'children': [], 'value': '[]'},{'id': '267', 'type': 'expression_statement', 'children': ['268']},{'id': '268', 'type': 'assignment', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'stream_timeout'},{'id': '270', 'type': 'attribute', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'max_collect_duration'},{'id': '273', 'type': 'expression_statement', 'children': ['274']},{'id': '274', 'type': 'yield', 'children': ['275']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'metrics_col'},{'id': '276', 'type': 'else_clause', 'children': ['277']},{'id': '277', 'type': 'block', 'children': ['278', '347']},{'id': '278', 'type': 'for_statement', 'children': ['279', '280', '281']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'metric'},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'metrics'},{'id': '281', 'type': 'block', 'children': ['282', '289']},{'id': '282', 'type': 'expression_statement', 'children': ['283']},{'id': '283', 'type': 'call', 'children': ['284', '287']},{'id': '284', 'type': 'attribute', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'metrics_to_stream'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '287', 'type': 'argument_list', 'children': ['288']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'metric'},{'id': '289', 'type': 'if_statement', 'children': ['290', '298']},{'id': '290', 'type': 'comparison_operator', 'children': ['291', '295'], 'value': '=='},{'id': '291', 'type': 'call', 'children': ['292', '293']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '293', 'type': 'argument_list', 'children': ['294']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'metrics_to_stream'},{'id': '295', 'type': 'attribute', 'children': ['296', '297']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'max_metrics_buffer'},{'id': '298', 'type': 'block', 'children': ['299', '314', '334', '338', '344']},{'id': '299', 'type': 'expression_statement', 'children': ['300']},{'id': '300', 'type': 'call', 'children': ['301', '304']},{'id': '301', 'type': 'attribute', 'children': ['302', '303']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'LOG'},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '304', 'type': 'argument_list', 'children': ['305']},{'id': '305', 'type': 'call', 'children': ['306', '309']},{'id': '306', 'type': 'attribute', 'children': ['307', '308']},{'id': '307', 'type': 'string', 'children': [], 'value': '"Max metrics buffer reached. Streaming {} metrics"'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '309', 'type': 'argument_list', 'children': ['310']},{'id': '310', 'type': 'call', 'children': ['311', '312']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '312', 'type': 'argument_list', 'children': ['313']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'metrics_to_stream'},{'id': '314', 'type': 'expression_statement', 'children': ['315']},{'id': '315', 'type': 'assignment', 'children': ['316', '317']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'metrics_col'},{'id': '317', 'type': 'call', 'children': ['318', '319']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'CollectReply'},{'id': '319', 'type': 'argument_list', 'children': ['320']},{'id': '320', 'type': 'keyword_argument', 'children': ['321', '322']},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'Metrics_Reply'},{'id': '322', 'type': 'call', 'children': ['323', '324']},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'MetricsReply'},{'id': '324', 'type': 'argument_list', 'children': ['325']},{'id': '325', 'type': 'keyword_argument', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'metrics'},{'id': '327', 'type': 'list_comprehension', 'children': ['328', '331']},{'id': '328', 'type': 'attribute', 'children': ['329', '330']},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'pb'},{'id': '331', 'type': 'for_in_clause', 'children': ['332', '333']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'metrics_to_stream'},{'id': '334', 'type': 'expression_statement', 'children': ['335']},{'id': '335', 'type': 'assignment', 'children': ['336', '337']},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'metrics_to_stream'},{'id': '337', 'type': 'list', 'children': [], 'value': '[]'},{'id': '338', 'type': 'expression_statement', 'children': ['339']},{'id': '339', 'type': 'assignment', 'children': ['340', '341']},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'stream_timeout'},{'id': '341', 'type': 'attribute', 'children': ['342', '343']},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'max_collect_duration'},{'id': '344', 'type': 'expression_statement', 'children': ['345']},{'id': '345', 'type': 'yield', 'children': ['346']},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'metrics_col'},{'id': '347', 'type': 'if_statement', 'children': ['348', '353']},{'id': '348', 'type': 'comparison_operator', 'children': ['349', '352'], 'value': '=='},{'id': '349', 'type': 'attribute', 'children': ['350', '351']},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'max_metrics_buffer'},{'id': '352', 'type': 'integer', 'children': [], 'value': '0'},{'id': '353', 'type': 'block', 'children': ['354', '369', '389', '393', '399']},{'id': '354', 'type': 'expression_statement', 'children': ['355']},{'id': '355', 'type': 'call', 'children': ['356', '359']},{'id': '356', 'type': 'attribute', 'children': ['357', '358']},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'LOG'},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '359', 'type': 'argument_list', 'children': ['360']},{'id': '360', 'type': 'call', 'children': ['361', '364']},{'id': '361', 'type': 'attribute', 'children': ['362', '363']},{'id': '362', 'type': 'string', 'children': [], 'value': '"Max metrics buffer set to 0. Streaming {} metrics"'},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '364', 'type': 'argument_list', 'children': ['365']},{'id': '365', 'type': 'call', 'children': ['366', '367']},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '367', 'type': 'argument_list', 'children': ['368']},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'metrics_to_stream'},{'id': '369', 'type': 'expression_statement', 'children': ['370']},{'id': '370', 'type': 'assignment', 'children': ['371', '372']},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'metrics_col'},{'id': '372', 'type': 'call', 'children': ['373', '374']},{'id': '373', 'type': 'identifier', 'children': [], 'value': 'CollectReply'},{'id': '374', 'type': 'argument_list', 'children': ['375']},{'id': '375', 'type': 'keyword_argument', 'children': ['376', '377']},{'id': '376', 'type': 'identifier', 'children': [], 'value': 'Metrics_Reply'},{'id': '377', 'type': 'call', 'children': ['378', '379']},{'id': '378', 'type': 'identifier', 'children': [], 'value': 'MetricsReply'},{'id': '379', 'type': 'argument_list', 'children': ['380']},{'id': '380', 'type': 'keyword_argument', 'children': ['381', '382']},{'id': '381', 'type': 'identifier', 'children': [], 'value': 'metrics'},{'id': '382', 'type': 'list_comprehension', 'children': ['383', '386']},{'id': '383', 'type': 'attribute', 'children': ['384', '385']},{'id': '384', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '385', 'type': 'identifier', 'children': [], 'value': 'pb'},{'id': '386', 'type': 'for_in_clause', 'children': ['387', '388']},{'id': '387', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '388', 'type': 'identifier', 'children': [], 'value': 'metrics_to_stream'},{'id': '389', 'type': 'expression_statement', 'children': ['390']},{'id': '390', 'type': 'assignment', 'children': ['391', '392']},{'id': '391', 'type': 'identifier', 'children': [], 'value': 'metrics_to_stream'},{'id': '392', 'type': 'list', 'children': [], 'value': '[]'},{'id': '393', 'type': 'expression_statement', 'children': ['394']},{'id': '394', 'type': 'assignment', 'children': ['395', '396']},{'id': '395', 'type': 'identifier', 'children': [], 'value': 'stream_timeout'},{'id': '396', 'type': 'attribute', 'children': ['397', '398']},{'id': '397', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '398', 'type': 'identifier', 'children': [], 'value': 'max_collect_duration'},{'id': '399', 'type': 'expression_statement', 'children': ['400']},{'id': '400', 'type': 'yield', 'children': ['401']},{'id': '401', 'type': 'identifier', 'children': [], 'value': 'metrics_col'},{'id': '402', 'type': 'expression_statement', 'children': ['403']},{'id': '403', 'type': 'call', 'children': ['404', '409']},{'id': '404', 'type': 'attribute', 'children': ['405', '408']},{'id': '405', 'type': 'attribute', 'children': ['406', '407']},{'id': '406', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '407', 'type': 'identifier', 'children': [], 'value': 'done_queue'},{'id': '408', 'type': 'identifier', 'children': [], 'value': 'put'},{'id': '409', 'type': 'argument_list', 'children': ['410']},{'id': '410', 'type': 'True', 'children': []}
def StreamMetrics(self, request_iterator, context): LOG.debug("StreamMetrics called") 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 thread = threading.Thread(target=self._stream_wrapper, args=(collect_args,),) thread.daemon = True thread.start() metrics = [] metrics_to_stream = [] stream_timeout = self.max_collect_duration while context.is_active(): try: 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 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 self.done_queue.put(True)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'prepare_node'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '5', 'type': 'block', 'children': ['6', '14', '25', '49', '53', '66', '90', '105']},{'id': '6', 'type': 'if_statement', 'children': ['7', '9']},{'id': '7', 'type': 'not_operator', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '9', 'type': 'block', 'children': ['10']},{'id': '10', 'type': 'return_statement', 'children': ['11']},{'id': '11', 'type': 'expression_list', 'children': ['12', '13']},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'dictionary', 'children': []},{'id': '14', 'type': 'if_statement', 'children': ['15', '20']},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '17', 'type': 'argument_list', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '20', 'type': 'block', 'children': ['21']},{'id': '21', 'type': 'return_statement', 'children': ['22']},{'id': '22', 'type': 'expression_list', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '24', 'type': 'dictionary', 'children': []},{'id': '25', 'type': 'if_statement', 'children': ['26', '38']},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '28', 'type': 'generator_expression', 'children': ['29', '32']},{'id': '29', 'type': 'comparison_operator', 'children': ['30', '31'], 'value': 'in'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '32', 'type': 'for_in_clause', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '34', 'type': 'tuple', 'children': ['35', '36', '37']},{'id': '35', 'type': 'string', 'children': [], 'value': '"Node"'},{'id': '36', 'type': 'string', 'children': [], 'value': '"Service"'},{'id': '37', 'type': 'string', 'children': [], 'value': '"Checks"'},{'id': '38', 'type': 'block', 'children': ['39']},{'id': '39', 'type': 'return_statement', 'children': ['40']},{'id': '40', 'type': 'expression_list', 'children': ['41', '46']},{'id': '41', 'type': 'subscript', 'children': ['42', '45']},{'id': '42', 'type': 'subscript', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '44', 'type': 'string', 'children': [], 'value': '"Node"'},{'id': '45', 'type': 'string', 'children': [], 'value': '"Node"'},{'id': '46', 'type': 'subscript', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '48', 'type': 'string', 'children': [], 'value': '"Node"'},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '52', 'type': 'dictionary', 'children': []},{'id': '53', 'type': 'if_statement', 'children': ['54', '57']},{'id': '54', 'type': 'comparison_operator', 'children': ['55', '56'], 'value': 'in'},{'id': '55', 'type': 'string', 'children': [], 'value': '"ID"'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '57', 'type': 'block', 'children': ['58']},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '63']},{'id': '60', 'type': 'subscript', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '62', 'type': 'string', 'children': [], 'value': '"Node"'},{'id': '63', 'type': 'subscript', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '65', 'type': 'string', 'children': [], 'value': '"ID"'},{'id': '66', 'type': 'for_statement', 'children': ['67', '68', '76']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '68', 'type': 'tuple', 'children': ['69', '70', '71', '72', '73', '74', '75']},{'id': '69', 'type': 'string', 'children': [], 'value': '"Datacenter"'},{'id': '70', 'type': 'string', 'children': [], 'value': '"Node"'},{'id': '71', 'type': 'string', 'children': [], 'value': '"Address"'},{'id': '72', 'type': 'string', 'children': [], 'value': '"TaggedAddresses"'},{'id': '73', 'type': 'string', 'children': [], 'value': '"Service"'},{'id': '74', 'type': 'string', 'children': [], 'value': '"Check"'},{'id': '75', 'type': 'string', 'children': [], 'value': '"Checks"'},{'id': '76', 'type': 'block', 'children': ['77']},{'id': '77', 'type': 'if_statement', 'children': ['78', '81']},{'id': '78', 'type': 'comparison_operator', 'children': ['79', '80'], 'value': 'in'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '81', 'type': 'block', 'children': ['82']},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'assignment', 'children': ['84', '87']},{'id': '84', 'type': 'subscript', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '87', 'type': 'subscript', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '90', 'type': 'if_statement', 'children': ['91', '98']},{'id': '91', 'type': 'comparison_operator', 'children': ['92', '96'], 'value': '=='},{'id': '92', 'type': 'call', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '96', 'type': 'list', 'children': ['97'], 'value': '["Node"]'},{'id': '97', 'type': 'string', 'children': [], 'value': '"Node"'},{'id': '98', 'type': 'block', 'children': ['99']},{'id': '99', 'type': 'return_statement', 'children': ['100']},{'id': '100', 'type': 'expression_list', 'children': ['101', '104']},{'id': '101', 'type': 'subscript', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '103', 'type': 'string', 'children': [], 'value': '"Node"'},{'id': '104', 'type': 'dictionary', 'children': []},{'id': '105', 'type': 'return_statement', 'children': ['106']},{'id': '106', 'type': 'expression_list', 'children': ['107', '113']},{'id': '107', 'type': 'call', 'children': ['108', '111']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '111', 'type': 'argument_list', 'children': ['112']},{'id': '112', 'type': 'string', 'children': [], 'value': '"Node"'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'result'}
def prepare_node(data): if not data: return None, {} if isinstance(data, str): return data, {} 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
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'prepare_service'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '5', 'type': 'block', 'children': ['6', '14', '25', '49', '102', '117', '121', '134', '156']},{'id': '6', 'type': 'if_statement', 'children': ['7', '9']},{'id': '7', 'type': 'not_operator', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '9', 'type': 'block', 'children': ['10']},{'id': '10', 'type': 'return_statement', 'children': ['11']},{'id': '11', 'type': 'expression_list', 'children': ['12', '13']},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'dictionary', 'children': []},{'id': '14', 'type': 'if_statement', 'children': ['15', '20']},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '17', 'type': 'argument_list', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '20', 'type': 'block', 'children': ['21']},{'id': '21', 'type': 'return_statement', 'children': ['22']},{'id': '22', 'type': 'expression_list', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '24', 'type': 'dictionary', 'children': []},{'id': '25', 'type': 'if_statement', 'children': ['26', '38']},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '28', 'type': 'generator_expression', 'children': ['29', '32']},{'id': '29', 'type': 'comparison_operator', 'children': ['30', '31'], 'value': 'in'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '32', 'type': 'for_in_clause', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '34', 'type': 'tuple', 'children': ['35', '36', '37']},{'id': '35', 'type': 'string', 'children': [], 'value': '"Node"'},{'id': '36', 'type': 'string', 'children': [], 'value': '"Service"'},{'id': '37', 'type': 'string', 'children': [], 'value': '"Checks"'},{'id': '38', 'type': 'block', 'children': ['39']},{'id': '39', 'type': 'return_statement', 'children': ['40']},{'id': '40', 'type': 'expression_list', 'children': ['41', '46']},{'id': '41', 'type': 'subscript', 'children': ['42', '45']},{'id': '42', 'type': 'subscript', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '44', 'type': 'string', 'children': [], 'value': '"Service"'},{'id': '45', 'type': 'string', 'children': [], 'value': '"ID"'},{'id': '46', 'type': 'subscript', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '48', 'type': 'string', 'children': [], 'value': '"Service"'},{'id': '49', 'type': 'if_statement', 'children': ['50', '61']},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '52', 'type': 'generator_expression', 'children': ['53', '56']},{'id': '53', 'type': 'comparison_operator', 'children': ['54', '55'], 'value': 'in'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '56', 'type': 'for_in_clause', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '58', 'type': 'tuple', 'children': ['59', '60']},{'id': '59', 'type': 'string', 'children': [], 'value': '"ServiceName"'},{'id': '60', 'type': 'string', 'children': [], 'value': '"ServiceID"'},{'id': '61', 'type': 'block', 'children': ['62']},{'id': '62', 'type': 'return_statement', 'children': ['63']},{'id': '63', 'type': 'expression_list', 'children': ['64', '67']},{'id': '64', 'type': 'subscript', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '66', 'type': 'string', 'children': [], 'value': '"ServiceID"'},{'id': '67', 'type': 'dictionary', 'children': ['68', '73', '78', '86', '94']},{'id': '68', 'type': 'pair', 'children': ['69', '70']},{'id': '69', 'type': 'string', 'children': [], 'value': '"ID"'},{'id': '70', 'type': 'subscript', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '72', 'type': 'string', 'children': [], 'value': '"ServiceID"'},{'id': '73', 'type': 'pair', 'children': ['74', '75']},{'id': '74', 'type': 'string', 'children': [], 'value': '"Service"'},{'id': '75', 'type': 'subscript', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '77', 'type': 'string', 'children': [], 'value': '"ServiceName"'},{'id': '78', 'type': 'pair', 'children': ['79', '80']},{'id': '79', 'type': 'string', 'children': [], 'value': '"Tags"'},{'id': '80', 'type': 'call', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'string', 'children': [], 'value': '"ServiceTags"'},{'id': '86', 'type': 'pair', 'children': ['87', '88']},{'id': '87', 'type': 'string', 'children': [], 'value': '"Address"'},{'id': '88', 'type': 'call', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'string', 'children': [], 'value': '"ServiceAddress"'},{'id': '94', 'type': 'pair', 'children': ['95', '96']},{'id': '95', 'type': 'string', 'children': [], 'value': '"Port"'},{'id': '96', 'type': 'call', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'string', 'children': [], 'value': '"ServicePort"'},{'id': '102', 'type': 'if_statement', 'children': ['103', '110']},{'id': '103', 'type': 'comparison_operator', 'children': ['104', '108'], 'value': '=='},{'id': '104', 'type': 'call', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '108', 'type': 'list', 'children': ['109'], 'value': '["ID"]'},{'id': '109', 'type': 'string', 'children': [], 'value': '"ID"'},{'id': '110', 'type': 'block', 'children': ['111']},{'id': '111', 'type': 'return_statement', 'children': ['112']},{'id': '112', 'type': 'expression_list', 'children': ['113', '116']},{'id': '113', 'type': 'subscript', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '115', 'type': 'string', 'children': [], 'value': '"ID"'},{'id': '116', 'type': 'dictionary', 'children': []},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '120', 'type': 'dictionary', 'children': []},{'id': '121', 'type': 'if_statement', 'children': ['122', '125']},{'id': '122', 'type': 'comparison_operator', 'children': ['123', '124'], 'value': 'in'},{'id': '123', 'type': 'string', 'children': [], 'value': '"Name"'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '125', 'type': 'block', 'children': ['126']},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'assignment', 'children': ['128', '131']},{'id': '128', 'type': 'subscript', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '130', 'type': 'string', 'children': [], 'value': '"Service"'},{'id': '131', 'type': 'subscript', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '133', 'type': 'string', 'children': [], 'value': '"Name"'},{'id': '134', 'type': 'for_statement', 'children': ['135', '136', '142']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '136', 'type': 'tuple', 'children': ['137', '138', '139', '140', '141']},{'id': '137', 'type': 'string', 'children': [], 'value': '"Service"'},{'id': '138', 'type': 'string', 'children': [], 'value': '"ID"'},{'id': '139', 'type': 'string', 'children': [], 'value': '"Tags"'},{'id': '140', 'type': 'string', 'children': [], 'value': '"Address"'},{'id': '141', 'type': 'string', 'children': [], 'value': '"Port"'},{'id': '142', 'type': 'block', 'children': ['143']},{'id': '143', 'type': 'if_statement', 'children': ['144', '147']},{'id': '144', 'type': 'comparison_operator', 'children': ['145', '146'], 'value': 'in'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '147', 'type': 'block', 'children': ['148']},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'assignment', 'children': ['150', '153']},{'id': '150', 'type': 'subscript', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '153', 'type': 'subscript', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '156', 'type': 'return_statement', 'children': ['157']},{'id': '157', 'type': 'expression_list', 'children': ['158', '164']},{'id': '158', 'type': 'call', 'children': ['159', '162']},{'id': '159', 'type': 'attribute', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '162', 'type': 'argument_list', 'children': ['163']},{'id': '163', 'type': 'string', 'children': [], 'value': '"ID"'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'result'}
def prepare_service(data): if not data: return None, {} if isinstance(data, str): return data, {} if all(field in data for field in ("Node", "Service", "Checks")): return data["Service"]["ID"], data["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
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'add_measurement'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'measurement'},{'id': '5', 'type': 'block', 'children': ['6', '8', '23', '37', '50', '61', '76', '84', '95', '116', '122']},{'id': '6', 'type': 'global_statement', 'children': ['7']},{'id': '7', 'type': 'identifier', 'children': [], 'value': '_buffer_size'},{'id': '8', 'type': 'if_statement', 'children': ['9', '11']},{'id': '9', 'type': 'not_operator', 'children': ['10']},{'id': '10', 'type': 'identifier', 'children': [], 'value': '_enabled'},{'id': '11', 'type': 'block', 'children': ['12', '22']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'call', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'LOGGER'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '17', 'type': 'argument_list', 'children': ['18', '19']},{'id': '18', 'type': 'string', 'children': [], 'value': "'Discarding measurement for %s while not enabled'"},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'measurement'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'database'},{'id': '22', 'type': 'return_statement', 'children': []},{'id': '23', 'type': 'if_statement', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': '_stopping'},{'id': '25', 'type': 'block', 'children': ['26', '36']},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'LOGGER'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '31', 'type': 'argument_list', 'children': ['32', '33']},{'id': '32', 'type': 'string', 'children': [], 'value': "'Discarding measurement for %s while stopping'"},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'measurement'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'database'},{'id': '36', 'type': 'return_statement', 'children': []},{'id': '37', 'type': 'if_statement', 'children': ['38', '41']},{'id': '38', 'type': 'comparison_operator', 'children': ['39', '40'], 'value': '>'},{'id': '39', 'type': 'identifier', 'children': [], 'value': '_buffer_size'},{'id': '40', 'type': 'identifier', 'children': [], 'value': '_max_buffer_size'},{'id': '41', 'type': 'block', 'children': ['42', '49']},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'call', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'LOGGER'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'string', 'children': [], 'value': "'Discarding measurement due to buffer size limit'"},{'id': '49', 'type': 'return_statement', 'children': []},{'id': '50', 'type': 'if_statement', 'children': ['51', '55']},{'id': '51', 'type': 'not_operator', 'children': ['52']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'measurement'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '55', 'type': 'block', 'children': ['56']},{'id': '56', 'type': 'raise_statement', 'children': ['57']},{'id': '57', 'type': 'call', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'string', 'children': [], 'value': "'Measurement does not contain a field'"},{'id': '61', 'type': 'if_statement', 'children': ['62', '67']},{'id': '62', 'type': 'comparison_operator', 'children': ['63', '66'], 'value': 'not'},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'measurement'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'database'},{'id': '66', 'type': 'identifier', 'children': [], 'value': '_measurements'},{'id': '67', 'type': 'block', 'children': ['68']},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '75']},{'id': '70', 'type': 'subscript', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': '_measurements'},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'measurement'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'database'},{'id': '75', 'type': 'list', 'children': [], 'value': '[]'},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'assignment', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '79', 'type': 'call', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'measurement'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'marshall'},{'id': '83', 'type': 'argument_list', 'children': []},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'call', 'children': ['86', '93']},{'id': '86', 'type': 'attribute', 'children': ['87', '92']},{'id': '87', 'type': 'subscript', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': '_measurements'},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'measurement'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'database'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '95', 'type': 'if_statement', 'children': ['96', '98']},{'id': '96', 'type': 'not_operator', 'children': ['97']},{'id': '97', 'type': 'identifier', 'children': [], 'value': '_timeout'},{'id': '98', 'type': 'block', 'children': ['99']},{'id': '99', 'type': 'if_statement', 'children': ['100', '111']},{'id': '100', 'type': 'boolean_operator', 'children': ['101', '109'], 'value': 'or'},{'id': '101', 'type': '()', 'children': ['102']},{'id': '102', 'type': 'boolean_operator', 'children': ['103', '104'], 'value': 'and'},{'id': '103', 'type': 'identifier', 'children': [], 'value': '_batch_future'},{'id': '104', 'type': 'call', 'children': ['105', '108']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': '_batch_future'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'done'},{'id': '108', 'type': 'argument_list', 'children': []},{'id': '109', 'type': 'not_operator', 'children': ['110']},{'id': '110', 'type': 'identifier', 'children': [], 'value': '_batch_future'},{'id': '111', 'type': 'block', 'children': ['112']},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'call', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': '_start_timeout'},{'id': '115', 'type': 'argument_list', 'children': []},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'assignment', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': '_buffer_size'},{'id': '119', 'type': 'call', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': '_pending_measurements'},{'id': '121', 'type': 'argument_list', 'children': []},{'id': '122', 'type': 'if_statement', 'children': ['123', '126']},{'id': '123', 'type': 'comparison_operator', 'children': ['124', '125'], 'value': '>='},{'id': '124', 'type': 'identifier', 'children': [], 'value': '_buffer_size'},{'id': '125', 'type': 'identifier', 'children': [], 'value': '_trigger_size'},{'id': '126', 'type': 'block', 'children': ['127']},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'call', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': '_trigger_batch_write'},{'id': '130', 'type': 'argument_list', 'children': []}
def add_measurement(measurement): 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) if not _timeout: if (_batch_future and _batch_future.done()) or not _batch_future: _start_timeout() _buffer_size = _pending_measurements() if _buffer_size >= _trigger_size: _trigger_batch_write()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'refresh'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'reloadData'},{'id': '7', 'type': 'False', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'force'},{'id': '10', 'type': 'False', 'children': []},{'id': '11', 'type': 'block', 'children': ['12', '32', '40', '49', '57', '67', '80', '88', '103', '118', '167', '192', '208', '237', '250']},{'id': '12', 'type': 'if_statement', 'children': ['13', '22']},{'id': '13', 'type': 'not_operator', 'children': ['14']},{'id': '14', 'type': '()', 'children': ['15']},{'id': '15', 'type': 'boolean_operator', 'children': ['16', '21'], 'value': 'or'},{'id': '16', 'type': 'call', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'isVisible'},{'id': '20', 'type': 'argument_list', 'children': []},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'force'},{'id': '22', 'type': 'block', 'children': ['23', '31']},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'call', 'children': ['25', '30']},{'id': '25', 'type': 'attribute', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '28', 'type': 'identifier', 'children': [], 'value': '_refreshTimer'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '30', 'type': 'argument_list', 'children': []},{'id': '31', 'type': 'return_statement', 'children': []},{'id': '32', 'type': 'if_statement', 'children': ['33', '38']},{'id': '33', 'type': 'call', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'isLoading'},{'id': '37', 'type': 'argument_list', 'children': []},{'id': '38', 'type': 'block', 'children': ['39']},{'id': '39', 'type': 'return_statement', 'children': []},{'id': '40', 'type': 'if_statement', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'reloadData'},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'call', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'refreshQueryRecords'},{'id': '48', 'type': 'argument_list', 'children': []},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'call', 'children': ['51', '56']},{'id': '51', 'type': 'attribute', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '54', 'type': 'identifier', 'children': [], 'value': '_refreshTimer'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'stop'},{'id': '56', 'type': 'argument_list', 'children': []},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'call', 'children': ['59', '66']},{'id': '59', 'type': 'attribute', 'children': ['60', '65']},{'id': '60', 'type': 'call', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'worker'},{'id': '64', 'type': 'argument_list', 'children': []},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'cancel'},{'id': '66', 'type': 'argument_list', 'children': []},{'id': '67', 'type': 'if_statement', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '70', 'type': 'identifier', 'children': [], 'value': '_popup'},{'id': '71', 'type': 'block', 'children': ['72']},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'call', 'children': ['74', '79']},{'id': '74', 'type': 'attribute', 'children': ['75', '78']},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '77', 'type': 'identifier', 'children': [], 'value': '_popup'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '79', 'type': 'argument_list', 'children': []},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'currset'},{'id': '83', 'type': 'call', 'children': ['84', '87']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'currentRecordSet'},{'id': '87', 'type': 'argument_list', 'children': []},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'call', 'children': ['90', '97']},{'id': '90', 'type': 'attribute', 'children': ['91', '96']},{'id': '91', 'type': 'call', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'worker'},{'id': '95', 'type': 'argument_list', 'children': []},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'setBatched'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'call', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'isPaged'},{'id': '102', 'type': 'argument_list', 'children': []},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'call', 'children': ['105', '112']},{'id': '105', 'type': 'attribute', 'children': ['106', '111']},{'id': '106', 'type': 'call', 'children': ['107', '110']},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'worker'},{'id': '110', 'type': 'argument_list', 'children': []},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'setBatchSize'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'call', 'children': ['114', '117']},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'pageSize'},{'id': '117', 'type': 'argument_list', 'children': []},{'id': '118', 'type': 'if_statement', 'children': ['119', '122', '134', '158']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '121', 'type': 'identifier', 'children': [], 'value': '_searchTerms'},{'id': '122', 'type': 'block', 'children': ['123', '130']},{'id': '123', 'type': 'expression_statement', 'children': ['124']},{'id': '124', 'type': 'call', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'currset'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'setGroupBy'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'id': '129', 'type': 'None', 'children': []},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'assignment', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'pageSize'},{'id': '133', 'type': 'integer', 'children': [], 'value': '0'},{'id': '134', 'type': 'elif_clause', 'children': ['135', '146']},{'id': '135', 'type': 'boolean_operator', 'children': ['136', '141'], 'value': 'and'},{'id': '136', 'type': 'call', 'children': ['137', '140']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'groupBy'},{'id': '140', 'type': 'argument_list', 'children': []},{'id': '141', 'type': 'call', 'children': ['142', '145']},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'isGroupingActive'},{'id': '145', 'type': 'argument_list', 'children': []},{'id': '146', 'type': 'block', 'children': ['147']},{'id': '147', 'type': 'expression_statement', 'children': ['148']},{'id': '148', 'type': 'call', 'children': ['149', '152']},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'currset'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'setGroupBy'},{'id': '152', 'type': 'argument_list', 'children': ['153']},{'id': '153', 'type': 'call', 'children': ['154', '157']},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'groupBy'},{'id': '157', 'type': 'argument_list', 'children': []},{'id': '158', 'type': 'else_clause', 'children': ['159']},{'id': '159', 'type': 'block', 'children': ['160']},{'id': '160', 'type': 'expression_statement', 'children': ['161']},{'id': '161', 'type': 'call', 'children': ['162', '165']},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'currset'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'setGroupBy'},{'id': '165', 'type': 'argument_list', 'children': ['166']},{'id': '166', 'type': 'None', 'children': []},{'id': '167', 'type': 'if_statement', 'children': ['168', '173']},{'id': '168', 'type': 'call', 'children': ['169', '172']},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '172', 'type': 'argument_list', 'children': []},{'id': '173', 'type': 'block', 'children': ['174', '181']},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'id': '175', 'type': 'call', 'children': ['176', '179']},{'id': '176', 'type': 'attribute', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'currset'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'setOrdered'},{'id': '179', 'type': 'argument_list', 'children': ['180']},{'id': '180', 'type': 'True', 'children': []},{'id': '181', 'type': 'expression_statement', 'children': ['182']},{'id': '182', 'type': 'call', 'children': ['183', '186']},{'id': '183', 'type': 'attribute', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'currset'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'setOrder'},{'id': '186', 'type': 'argument_list', 'children': ['187']},{'id': '187', 'type': 'call', 'children': ['188', '191']},{'id': '188', 'type': 'attribute', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '191', 'type': 'argument_list', 'children': []},{'id': '192', 'type': 'if_statement', 'children': ['193', '198']},{'id': '193', 'type': 'call', 'children': ['194', '197']},{'id': '194', 'type': 'attribute', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'useLoader'},{'id': '197', 'type': 'argument_list', 'children': []},{'id': '198', 'type': 'block', 'children': ['199']},{'id': '199', 'type': 'expression_statement', 'children': ['200']},{'id': '200', 'type': 'assignment', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'loader'},{'id': '202', 'type': 'call', 'children': ['203', '206']},{'id': '203', 'type': 'attribute', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'XLoaderWidget'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '206', 'type': 'argument_list', 'children': ['207']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '208', 'type': 'if_statement', 'children': ['209', '214']},{'id': '209', 'type': 'call', 'children': ['210', '213']},{'id': '210', 'type': 'attribute', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'specifiedColumnsOnly'},{'id': '213', 'type': 'argument_list', 'children': []},{'id': '214', 'type': 'block', 'children': ['215']},{'id': '215', 'type': 'expression_statement', 'children': ['216']},{'id': '216', 'type': 'call', 'children': ['217', '220']},{'id': '217', 'type': 'attribute', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'currset'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'setColumns'},{'id': '220', 'type': 'argument_list', 'children': ['221']},{'id': '221', 'type': 'call', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '223', 'type': 'argument_list', 'children': ['224', '232']},{'id': '224', 'type': 'lambda', 'children': ['225', '227']},{'id': '225', 'type': 'lambda_parameters', 'children': ['226']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '227', 'type': 'call', 'children': ['228', '231']},{'id': '228', 'type': 'attribute', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '231', 'type': 'argument_list', 'children': []},{'id': '232', 'type': 'call', 'children': ['233', '236']},{'id': '233', 'type': 'attribute', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'specifiedColumns'},{'id': '236', 'type': 'argument_list', 'children': []},{'id': '237', 'type': 'expression_statement', 'children': ['238']},{'id': '238', 'type': 'assignment', 'children': ['239', '242']},{'id': '239', 'type': 'attribute', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '241', 'type': 'identifier', 'children': [], 'value': '_loadedColumns'},{'id': '242', 'type': 'call', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '244', 'type': 'argument_list', 'children': ['245']},{'id': '245', 'type': 'call', 'children': ['246', '249']},{'id': '246', 'type': 'attribute', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'visibleColumns'},{'id': '249', 'type': 'argument_list', 'children': []},{'id': '250', 'type': 'if_statement', 'children': ['251', '262', '285']},{'id': '251', 'type': 'boolean_operator', 'children': ['252', '257'], 'value': 'and'},{'id': '252', 'type': 'call', 'children': ['253', '256']},{'id': '253', 'type': 'attribute', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'isThreadEnabled'},{'id': '256', 'type': 'argument_list', 'children': []},{'id': '257', 'type': 'call', 'children': ['258', '261']},{'id': '258', 'type': 'attribute', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'currset'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'isThreadEnabled'},{'id': '261', 'type': 'argument_list', 'children': []},{'id': '262', 'type': 'block', 'children': ['263', '276']},{'id': '263', 'type': 'expression_statement', 'children': ['264']},{'id': '264', 'type': 'call', 'children': ['265', '272']},{'id': '265', 'type': 'attribute', 'children': ['266', '271']},{'id': '266', 'type': 'call', 'children': ['267', '270']},{'id': '267', 'type': 'attribute', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'worker'},{'id': '270', 'type': 'argument_list', 'children': []},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'setPreloadColumns'},{'id': '272', 'type': 'argument_list', 'children': ['273']},{'id': '273', 'type': 'attribute', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '275', 'type': 'identifier', 'children': [], 'value': '_preloadColumns'},{'id': '276', 'type': 'expression_statement', 'children': ['277']},{'id': '277', 'type': 'call', 'children': ['278', '283']},{'id': '278', 'type': 'attribute', 'children': ['279', '282']},{'id': '279', 'type': 'attribute', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'loadRequested'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'emit'},{'id': '283', 'type': 'argument_list', 'children': ['284']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'currset'},{'id': '285', 'type': 'else_clause', 'children': ['286']},{'id': '286', 'type': 'block', 'children': ['287', '296', '307']},{'id': '287', 'type': 'expression_statement', 'children': ['288']},{'id': '288', 'type': 'call', 'children': ['289', '292']},{'id': '289', 'type': 'attribute', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'QApplication'},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'setOverrideCursor'},{'id': '292', 'type': 'argument_list', 'children': ['293']},{'id': '293', 'type': 'attribute', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'Qt'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'WaitCursor'},{'id': '296', 'type': 'expression_statement', 'children': ['297']},{'id': '297', 'type': 'call', 'children': ['298', '305']},{'id': '298', 'type': 'attribute', 'children': ['299', '304']},{'id': '299', 'type': 'call', 'children': ['300', '303']},{'id': '300', 'type': 'attribute', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'worker'},{'id': '303', 'type': 'argument_list', 'children': []},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'loadRecords'},{'id': '305', 'type': 'argument_list', 'children': ['306']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'currset'},{'id': '307', 'type': 'expression_statement', 'children': ['308']},{'id': '308', 'type': 'call', 'children': ['309', '312']},{'id': '309', 'type': 'attribute', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'QApplication'},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'restoreOverrideCursor'},{'id': '312', 'type': 'argument_list', 'children': []}
def refresh(self, reloadData=False, force=False): if not (self.isVisible() or force): self._refreshTimer.start() return if self.isLoading(): return if reloadData: self.refreshQueryRecords() self._refreshTimer.stop() self.worker().cancel() if self._popup: self._popup.close() currset = self.currentRecordSet() self.worker().setBatched(self.isPaged()) self.worker().setBatchSize(self.pageSize()) if self._searchTerms: currset.setGroupBy(None) pageSize = 0 elif self.groupBy() and self.isGroupingActive(): currset.setGroupBy(self.groupBy()) else: currset.setGroupBy(None) if self.order(): currset.setOrdered(True) currset.setOrder(self.order()) if self.useLoader(): loader = XLoaderWidget.start(self) 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()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '29']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'tornado_run'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'port'},{'id': '7', 'type': 'integer', 'children': [], 'value': '5000'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'address'},{'id': '10', 'type': 'string', 'children': [], 'value': '""'},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'use_gevent'},{'id': '13', 'type': 'False', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '16', 'type': 'True', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'monkey_patch'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'Container'},{'id': '22', 'type': 'None', 'children': []},{'id': '23', 'type': 'default_parameter', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'Server'},{'id': '25', 'type': 'None', 'children': []},{'id': '26', 'type': 'default_parameter', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'threadpool'},{'id': '28', 'type': 'None', 'children': []},{'id': '29', 'type': 'block', 'children': ['30', '45', '60', '69', '73', '136', '205', '215', '223', '230']},{'id': '30', 'type': 'if_statement', 'children': ['31', '34']},{'id': '31', 'type': 'comparison_operator', 'children': ['32', '33'], 'value': 'is'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'Container'},{'id': '33', 'type': 'None', 'children': []},{'id': '34', 'type': 'block', 'children': ['35', '41']},{'id': '35', 'type': 'import_from_statement', 'children': ['36', '39']},{'id': '36', 'type': 'dotted_name', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'tornado'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'wsgi'},{'id': '39', 'type': 'dotted_name', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'WSGIContainer'},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'Container'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'WSGIContainer'},{'id': '45', 'type': 'if_statement', 'children': ['46', '49']},{'id': '46', 'type': 'comparison_operator', 'children': ['47', '48'], 'value': 'is'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'Server'},{'id': '48', 'type': 'None', 'children': []},{'id': '49', 'type': 'block', 'children': ['50', '56']},{'id': '50', 'type': 'import_from_statement', 'children': ['51', '54']},{'id': '51', 'type': 'dotted_name', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'tornado'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'httpserver'},{'id': '54', 'type': 'dotted_name', 'children': ['55']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'HTTPServer'},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'Server'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'HTTPServer'},{'id': '60', 'type': 'if_statement', 'children': ['61', '64']},{'id': '61', 'type': 'comparison_operator', 'children': ['62', '63'], 'value': 'is'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'monkey_patch'},{'id': '63', 'type': 'None', 'children': []},{'id': '64', 'type': 'block', 'children': ['65']},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'monkey_patch'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'use_gevent'},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'CustomWSGIContainer'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'Container'},{'id': '73', 'type': 'if_statement', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'use_gevent'},{'id': '75', 'type': 'block', 'children': ['76', '90', '93', '132']},{'id': '76', 'type': 'if_statement', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'monkey_patch'},{'id': '78', 'type': 'block', 'children': ['79', '84']},{'id': '79', 'type': 'import_from_statement', 'children': ['80', '82']},{'id': '80', 'type': 'dotted_name', 'children': ['81']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'gevent'},{'id': '82', 'type': 'dotted_name', 'children': ['83']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'monkey'},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'call', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'monkey'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'patch_all'},{'id': '89', 'type': 'argument_list', 'children': []},{'id': '90', 'type': 'import_statement', 'children': ['91']},{'id': '91', 'type': 'dotted_name', 'children': ['92']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'gevent'},{'id': '93', 'type': 'class_definition', 'children': ['94', '95', '97']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'GeventWSGIContainer'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'Container'},{'id': '97', 'type': 'block', 'children': ['98']},{'id': '98', 'type': 'function_definition', 'children': ['99', '100', '106']},{'id': '99', 'type': 'function_name', 'children': [], 'value': '__call__'},{'id': '100', 'type': 'parameters', 'children': ['101', '102', '104']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '102', 'type': 'list_splat_pattern', 'children': ['103']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '104', 'type': 'dictionary_splat_pattern', 'children': ['105']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '106', 'type': 'block', 'children': ['107', '125']},{'id': '107', 'type': 'function_definition', 'children': ['108', '109', '110']},{'id': '108', 'type': 'function_name', 'children': [], 'value': 'async_task'},{'id': '109', 'type': 'parameters', 'children': []},{'id': '110', 'type': 'block', 'children': ['111']},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'call', 'children': ['113', '120']},{'id': '113', 'type': 'attribute', 'children': ['114', '119']},{'id': '114', 'type': 'call', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'super'},{'id': '116', 'type': 'argument_list', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'GeventWSGIContainer'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '119', 'type': 'identifier', 'children': [], 'value': '__call__'},{'id': '120', 'type': 'argument_list', 'children': ['121', '123']},{'id': '121', 'type': 'list_splat', 'children': ['122']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '123', 'type': 'dictionary_splat', 'children': ['124']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'call', 'children': ['127', '130']},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'gevent'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'spawn'},{'id': '130', 'type': 'argument_list', 'children': ['131']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'async_task'},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'assignment', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'CustomWSGIContainer'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'GeventWSGIContainer'},{'id': '136', 'type': 'if_statement', 'children': ['137', '140']},{'id': '137', 'type': 'comparison_operator', 'children': ['138', '139'], 'value': 'is'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'threadpool'},{'id': '139', 'type': 'None', 'children': []},{'id': '140', 'type': 'block', 'children': ['141', '147', '162', '201']},{'id': '141', 'type': 'import_from_statement', 'children': ['142', '145']},{'id': '142', 'type': 'dotted_name', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'multiprocessing'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'pool'},{'id': '145', 'type': 'dotted_name', 'children': ['146']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'ThreadPool'},{'id': '147', 'type': 'if_statement', 'children': ['148', '154']},{'id': '148', 'type': 'not_operator', 'children': ['149']},{'id': '149', 'type': 'call', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '151', 'type': 'argument_list', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'threadpool'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'ThreadPool'},{'id': '154', 'type': 'block', 'children': ['155']},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'assignment', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'threadpool'},{'id': '158', 'type': 'call', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'ThreadPool'},{'id': '160', 'type': 'argument_list', 'children': ['161']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'threadpool'},{'id': '162', 'type': 'class_definition', 'children': ['163', '164', '166']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'ThreadPoolWSGIContainer'},{'id': '164', 'type': 'argument_list', 'children': ['165']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'Container'},{'id': '166', 'type': 'block', 'children': ['167']},{'id': '167', 'type': 'function_definition', 'children': ['168', '169', '175']},{'id': '168', 'type': 'function_name', 'children': [], 'value': '__call__'},{'id': '169', 'type': 'parameters', 'children': ['170', '171', '173']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '171', 'type': 'list_splat_pattern', 'children': ['172']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '173', 'type': 'dictionary_splat_pattern', 'children': ['174']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '175', 'type': 'block', 'children': ['176', '194']},{'id': '176', 'type': 'function_definition', 'children': ['177', '178', '179']},{'id': '177', 'type': 'function_name', 'children': [], 'value': 'async_task'},{'id': '178', 'type': 'parameters', 'children': []},{'id': '179', 'type': 'block', 'children': ['180']},{'id': '180', 'type': 'expression_statement', 'children': ['181']},{'id': '181', 'type': 'call', 'children': ['182', '189']},{'id': '182', 'type': 'attribute', 'children': ['183', '188']},{'id': '183', 'type': 'call', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'super'},{'id': '185', 'type': 'argument_list', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'ThreadPoolWSGIContainer'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '188', 'type': 'identifier', 'children': [], 'value': '__call__'},{'id': '189', 'type': 'argument_list', 'children': ['190', '192']},{'id': '190', 'type': 'list_splat', 'children': ['191']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '192', 'type': 'dictionary_splat', 'children': ['193']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '194', 'type': 'expression_statement', 'children': ['195']},{'id': '195', 'type': 'call', 'children': ['196', '199']},{'id': '196', 'type': 'attribute', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'threadpool'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'apply_async'},{'id': '199', 'type': 'argument_list', 'children': ['200']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'async_task'},{'id': '201', 'type': 'expression_statement', 'children': ['202']},{'id': '202', 'type': 'assignment', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'CustomWSGIContainer'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'ThreadPoolWSGIContainer'},{'id': '205', 'type': 'expression_statement', 'children': ['206']},{'id': '206', 'type': 'assignment', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'http_server'},{'id': '208', 'type': 'call', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'Server'},{'id': '210', 'type': 'argument_list', 'children': ['211']},{'id': '211', 'type': 'call', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'CustomWSGIContainer'},{'id': '213', 'type': 'argument_list', 'children': ['214']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '215', 'type': 'expression_statement', 'children': ['216']},{'id': '216', 'type': 'call', 'children': ['217', '220']},{'id': '217', 'type': 'attribute', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'http_server'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'listen'},{'id': '220', 'type': 'argument_list', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'port'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'address'},{'id': '223', 'type': 'if_statement', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '225', 'type': 'block', 'children': ['226']},{'id': '226', 'type': 'expression_statement', 'children': ['227']},{'id': '227', 'type': 'call', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'tornado_start'},{'id': '229', 'type': 'argument_list', 'children': []},{'id': '230', 'type': 'return_statement', 'children': ['231']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'http_server'}
def tornado_run(app, port=5000, address="", use_gevent=False, start=True, monkey_patch=None, Container=None, Server=None, threadpool=None): 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
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '23']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'tornado_combiner'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'configs'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'use_gevent'},{'id': '7', 'type': 'False', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '10', 'type': 'True', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'monkey_patch'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'Container'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'Server'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'threadpool'},{'id': '22', 'type': 'None', 'children': []},{'id': '23', 'type': 'block', 'children': ['24', '28', '37', '54', '80', '148', '155']},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'servers'},{'id': '27', 'type': 'list', 'children': [], 'value': '[]'},{'id': '28', 'type': 'if_statement', 'children': ['29', '32']},{'id': '29', 'type': 'comparison_operator', 'children': ['30', '31'], 'value': 'is'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'monkey_patch'},{'id': '31', 'type': 'None', 'children': []},{'id': '32', 'type': 'block', 'children': ['33']},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'monkey_patch'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'use_gevent'},{'id': '37', 'type': 'if_statement', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'use_gevent'},{'id': '39', 'type': 'block', 'children': ['40']},{'id': '40', 'type': 'if_statement', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'monkey_patch'},{'id': '42', 'type': 'block', 'children': ['43', '48']},{'id': '43', 'type': 'import_from_statement', 'children': ['44', '46']},{'id': '44', 'type': 'dotted_name', 'children': ['45']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'gevent'},{'id': '46', 'type': 'dotted_name', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'monkey'},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'call', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'monkey'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'patch_all'},{'id': '53', 'type': 'argument_list', 'children': []},{'id': '54', 'type': 'if_statement', 'children': ['55', '58']},{'id': '55', 'type': 'comparison_operator', 'children': ['56', '57'], 'value': 'is'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'threadpool'},{'id': '57', 'type': 'None', 'children': []},{'id': '58', 'type': 'block', 'children': ['59', '65']},{'id': '59', 'type': 'import_from_statement', 'children': ['60', '63']},{'id': '60', 'type': 'dotted_name', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'multiprocessing'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'pool'},{'id': '63', 'type': 'dotted_name', 'children': ['64']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'ThreadPool'},{'id': '65', 'type': 'if_statement', 'children': ['66', '72']},{'id': '66', 'type': 'not_operator', 'children': ['67']},{'id': '67', 'type': 'call', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '69', 'type': 'argument_list', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'threadpool'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'ThreadPool'},{'id': '72', 'type': 'block', 'children': ['73']},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'threadpool'},{'id': '76', 'type': 'call', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'ThreadPool'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'threadpool'},{'id': '80', 'type': 'for_statement', 'children': ['81', '82', '83']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'configs'},{'id': '83', 'type': 'block', 'children': ['84', '90', '100', '110', '141']},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '87', 'type': 'subscript', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '89', 'type': 'string', 'children': [], 'value': "'app'"},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'port'},{'id': '93', 'type': 'call', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '97', 'type': 'argument_list', 'children': ['98', '99']},{'id': '98', 'type': 'string', 'children': [], 'value': "'port'"},{'id': '99', 'type': 'integer', 'children': [], 'value': '5000'},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'address'},{'id': '103', 'type': 'call', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '107', 'type': 'argument_list', 'children': ['108', '109']},{'id': '108', 'type': 'string', 'children': [], 'value': "'address'"},{'id': '109', 'type': 'string', 'children': [], 'value': "''"},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'assignment', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'server'},{'id': '113', 'type': 'call', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'tornado_run'},{'id': '115', 'type': 'argument_list', 'children': ['116', '117', '120', '123', '126', '129', '132', '135', '138']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '117', 'type': 'keyword_argument', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'use_gevent'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'use_gevent'},{'id': '120', 'type': 'keyword_argument', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'port'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'port'},{'id': '123', 'type': 'keyword_argument', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'monkey_patch'},{'id': '125', 'type': 'False', 'children': []},{'id': '126', 'type': 'keyword_argument', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'address'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'address'},{'id': '129', 'type': 'keyword_argument', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '131', 'type': 'False', 'children': []},{'id': '132', 'type': 'keyword_argument', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'Container'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'Container'},{'id': '135', 'type': 'keyword_argument', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'Server'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'Server'},{'id': '138', 'type': 'keyword_argument', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'threadpool'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'threadpool'},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'call', 'children': ['143', '146']},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'servers'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '146', 'type': 'argument_list', 'children': ['147']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'server'},{'id': '148', 'type': 'if_statement', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '150', 'type': 'block', 'children': ['151']},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'call', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'tornado_start'},{'id': '154', 'type': 'argument_list', 'children': []},{'id': '155', 'type': 'return_statement', 'children': ['156']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'servers'}
def tornado_combiner(configs, use_gevent=False, start=True, monkey_patch=None, Container=None, Server=None, threadpool=None): 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
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'rebuild'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '14', '24', '31', '41', '47', '55', '93', '101', '109', '116', '123', '130', '139', '150', '161', '165', '174', '182', '221', '228', '451', '490', '497']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'navitem'},{'id': '9', 'type': 'call', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'currentItem'},{'id': '13', 'type': 'argument_list', 'children': []},{'id': '14', 'type': 'if_statement', 'children': ['15', '17']},{'id': '15', 'type': '()', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'navitem'},{'id': '17', 'type': 'block', 'children': ['18']},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'call', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'navitem'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'initialize'},{'id': '23', 'type': 'argument_list', 'children': []},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'setUpdatesEnabled'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'False', 'children': []},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'call', 'children': ['33', '40']},{'id': '33', 'type': 'attribute', 'children': ['34', '39']},{'id': '34', 'type': 'call', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'scrollWidget'},{'id': '38', 'type': 'argument_list', 'children': []},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'show'},{'id': '40', 'type': 'argument_list', 'children': []},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '45', 'type': 'identifier', 'children': [], 'value': '_originalText'},{'id': '46', 'type': 'string', 'children': [], 'value': "''"},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'partsw'},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'partsWidget'},{'id': '54', 'type': 'argument_list', 'children': []},{'id': '55', 'type': 'for_statement', 'children': ['56', '57', '64']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'button'},{'id': '57', 'type': 'call', 'children': ['58', '63']},{'id': '58', 'type': 'attribute', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '61', 'type': 'identifier', 'children': [], 'value': '_buttonGroup'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'buttons'},{'id': '63', 'type': 'argument_list', 'children': []},{'id': '64', 'type': 'block', 'children': ['65', '74', '80', '87']},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'call', 'children': ['67', '72']},{'id': '67', 'type': 'attribute', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '70', 'type': 'identifier', 'children': [], 'value': '_buttonGroup'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'removeButton'},{'id': '72', 'type': 'argument_list', 'children': ['73']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'button'},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'call', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'button'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '79', 'type': 'argument_list', 'children': []},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'call', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'button'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'setParent'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'None', 'children': []},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'call', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'button'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'deleteLater'},{'id': '92', 'type': 'argument_list', 'children': []},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'assignment', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'layout'},{'id': '96', 'type': 'call', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'partsw'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'layout'},{'id': '100', 'type': 'argument_list', 'children': []},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'assignment', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '104', 'type': 'call', 'children': ['105', '108']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '108', 'type': 'argument_list', 'children': []},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'button'},{'id': '112', 'type': 'call', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'QToolButton'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'partsw'},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'call', 'children': ['118', '121']},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'button'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'setAutoRaise'},{'id': '121', 'type': 'argument_list', 'children': ['122']},{'id': '122', 'type': 'True', 'children': []},{'id': '123', 'type': 'expression_statement', 'children': ['124']},{'id': '124', 'type': 'call', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'button'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'setMaximumWidth'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'id': '129', 'type': 'integer', 'children': [], 'value': '12'},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'call', 'children': ['132', '135']},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'button'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'setArrowType'},{'id': '135', 'type': 'argument_list', 'children': ['136']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'Qt'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'RightArrow'},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'id': '140', 'type': 'call', 'children': ['141', '144']},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'button'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'setProperty'},{'id': '144', 'type': 'argument_list', 'children': ['145', '146']},{'id': '145', 'type': 'string', 'children': [], 'value': "'path'"},{'id': '146', 'type': 'call', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'wrapVariant'},{'id': '148', 'type': 'argument_list', 'children': ['149']},{'id': '149', 'type': 'string', 'children': [], 'value': "''"},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'call', 'children': ['152', '155']},{'id': '152', 'type': 'attribute', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'button'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'setProperty'},{'id': '155', 'type': 'argument_list', 'children': ['156', '157']},{'id': '156', 'type': 'string', 'children': [], 'value': "'is_completer'"},{'id': '157', 'type': 'call', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'wrapVariant'},{'id': '159', 'type': 'argument_list', 'children': ['160']},{'id': '160', 'type': 'True', 'children': []},{'id': '161', 'type': 'expression_statement', 'children': ['162']},{'id': '162', 'type': 'assignment', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'last_button'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'button'},{'id': '165', 'type': 'expression_statement', 'children': ['166']},{'id': '166', 'type': 'call', 'children': ['167', '172']},{'id': '167', 'type': 'attribute', 'children': ['168', '171']},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '170', 'type': 'identifier', 'children': [], 'value': '_buttonGroup'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'addButton'},{'id': '172', 'type': 'argument_list', 'children': ['173']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'button'},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'id': '175', 'type': 'call', 'children': ['176', '179']},{'id': '176', 'type': 'attribute', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'layout'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'insertWidget'},{'id': '179', 'type': 'argument_list', 'children': ['180', '181']},{'id': '180', 'type': 'integer', 'children': [], 'value': '0'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'button'},{'id': '182', 'type': 'if_statement', 'children': ['183', '187', '215']},{'id': '183', 'type': '()', 'children': ['184']},{'id': '184', 'type': 'attribute', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '186', 'type': 'identifier', 'children': [], 'value': '_navigationModel'},{'id': '187', 'type': 'block', 'children': ['188', '203']},{'id': '188', 'type': 'expression_statement', 'children': ['189']},{'id': '189', 'type': 'assignment', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'last_item'},{'id': '191', 'type': 'call', 'children': ['192', '197']},{'id': '192', 'type': 'attribute', 'children': ['193', '196']},{'id': '193', 'type': 'attribute', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '195', 'type': 'identifier', 'children': [], 'value': '_navigationModel'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'itemByPath'},{'id': '197', 'type': 'argument_list', 'children': ['198']},{'id': '198', 'type': 'call', 'children': ['199', '202']},{'id': '199', 'type': 'attribute', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '202', 'type': 'argument_list', 'children': []},{'id': '203', 'type': 'expression_statement', 'children': ['204']},{'id': '204', 'type': 'assignment', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'show_last'},{'id': '206', 'type': 'boolean_operator', 'children': ['207', '208'], 'value': 'and'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'last_item'},{'id': '208', 'type': 'comparison_operator', 'children': ['209', '214'], 'value': '>'},{'id': '209', 'type': 'call', 'children': ['210', '213']},{'id': '210', 'type': 'attribute', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'last_item'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'rowCount'},{'id': '213', 'type': 'argument_list', 'children': []},{'id': '214', 'type': 'integer', 'children': [], 'value': '0'},{'id': '215', 'type': 'else_clause', 'children': ['216']},{'id': '216', 'type': 'block', 'children': ['217']},{'id': '217', 'type': 'expression_statement', 'children': ['218']},{'id': '218', 'type': 'assignment', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'show_last'},{'id': '220', 'type': 'False', 'children': []},{'id': '221', 'type': 'expression_statement', 'children': ['222']},{'id': '222', 'type': 'assignment', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '224', 'type': 'call', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '226', 'type': 'argument_list', 'children': ['227']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '228', 'type': 'for_statement', 'children': ['229', '232', '236']},{'id': '229', 'type': 'pattern_list', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'part'},{'id': '232', 'type': 'call', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '234', 'type': 'argument_list', 'children': ['235']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '236', 'type': 'block', 'children': ['237', '256', '263', '270', '277', '318', '329', '340', '349', '362']},{'id': '237', 'type': 'expression_statement', 'children': ['238']},{'id': '238', 'type': 'assignment', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '240', 'type': 'call', 'children': ['241', '248']},{'id': '241', 'type': 'attribute', 'children': ['242', '247']},{'id': '242', 'type': 'call', 'children': ['243', '246']},{'id': '243', 'type': 'attribute', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'separator'},{'id': '246', 'type': 'argument_list', 'children': []},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '248', 'type': 'argument_list', 'children': ['249']},{'id': '249', 'type': 'subscript', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '251', 'type': 'slice', 'children': ['252', '253']},{'id': '252', 'type': 'colon', 'children': []},{'id': '253', 'type': 'binary_operator', 'children': ['254', '255'], 'value': '+'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '255', 'type': 'integer', 'children': [], 'value': '1'},{'id': '256', 'type': 'expression_statement', 'children': ['257']},{'id': '257', 'type': 'assignment', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'button'},{'id': '259', 'type': 'call', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'QToolButton'},{'id': '261', 'type': 'argument_list', 'children': ['262']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'partsw'},{'id': '263', 'type': 'expression_statement', 'children': ['264']},{'id': '264', 'type': 'call', 'children': ['265', '268']},{'id': '265', 'type': 'attribute', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'button'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'setAutoRaise'},{'id': '268', 'type': 'argument_list', 'children': ['269']},{'id': '269', 'type': 'True', 'children': []},{'id': '270', 'type': 'expression_statement', 'children': ['271']},{'id': '271', 'type': 'call', 'children': ['272', '275']},{'id': '272', 'type': 'attribute', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'button'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'setText'},{'id': '275', 'type': 'argument_list', 'children': ['276']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'part'},{'id': '277', 'type': 'if_statement', 'children': ['278', '282']},{'id': '278', 'type': '()', 'children': ['279']},{'id': '279', 'type': 'attribute', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '281', 'type': 'identifier', 'children': [], 'value': '_navigationModel'},{'id': '282', 'type': 'block', 'children': ['283', '294']},{'id': '283', 'type': 'expression_statement', 'children': ['284']},{'id': '284', 'type': 'assignment', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '286', 'type': 'call', 'children': ['287', '292']},{'id': '287', 'type': 'attribute', 'children': ['288', '291']},{'id': '288', 'type': 'attribute', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '290', 'type': 'identifier', 'children': [], 'value': '_navigationModel'},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'itemByPath'},{'id': '292', 'type': 'argument_list', 'children': ['293']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '294', 'type': 'if_statement', 'children': ['295', '297']},{'id': '295', 'type': '()', 'children': ['296']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '297', 'type': 'block', 'children': ['298', '309']},{'id': '298', 'type': 'expression_statement', 'children': ['299']},{'id': '299', 'type': 'call', 'children': ['300', '303']},{'id': '300', 'type': 'attribute', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'button'},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'setIcon'},{'id': '303', 'type': 'argument_list', 'children': ['304']},{'id': '304', 'type': 'call', 'children': ['305', '308']},{'id': '305', 'type': 'attribute', 'children': ['306', '307']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'icon'},{'id': '308', 'type': 'argument_list', 'children': []},{'id': '309', 'type': 'expression_statement', 'children': ['310']},{'id': '310', 'type': 'call', 'children': ['311', '314']},{'id': '311', 'type': 'attribute', 'children': ['312', '313']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'button'},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'setToolButtonStyle'},{'id': '314', 'type': 'argument_list', 'children': ['315']},{'id': '315', 'type': 'attribute', 'children': ['316', '317']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'Qt'},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'ToolButtonTextBesideIcon'},{'id': '318', 'type': 'expression_statement', 'children': ['319']},{'id': '319', 'type': 'call', 'children': ['320', '323']},{'id': '320', 'type': 'attribute', 'children': ['321', '322']},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'button'},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'setProperty'},{'id': '323', 'type': 'argument_list', 'children': ['324', '325']},{'id': '324', 'type': 'string', 'children': [], 'value': "'path'"},{'id': '325', 'type': 'call', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'wrapVariant'},{'id': '327', 'type': 'argument_list', 'children': ['328']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '329', 'type': 'expression_statement', 'children': ['330']},{'id': '330', 'type': 'call', 'children': ['331', '334']},{'id': '331', 'type': 'attribute', 'children': ['332', '333']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'button'},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'setProperty'},{'id': '334', 'type': 'argument_list', 'children': ['335', '336']},{'id': '335', 'type': 'string', 'children': [], 'value': "'is_completer'"},{'id': '336', 'type': 'call', 'children': ['337', '338']},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'wrapVariant'},{'id': '338', 'type': 'argument_list', 'children': ['339']},{'id': '339', 'type': 'False', 'children': []},{'id': '340', 'type': 'expression_statement', 'children': ['341']},{'id': '341', 'type': 'call', 'children': ['342', '347']},{'id': '342', 'type': 'attribute', 'children': ['343', '346']},{'id': '343', 'type': 'attribute', 'children': ['344', '345']},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '345', 'type': 'identifier', 'children': [], 'value': '_buttonGroup'},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'addButton'},{'id': '347', 'type': 'argument_list', 'children': ['348']},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'button'},{'id': '349', 'type': 'expression_statement', 'children': ['350']},{'id': '350', 'type': 'call', 'children': ['351', '354']},{'id': '351', 'type': 'attribute', 'children': ['352', '353']},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'layout'},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'insertWidget'},{'id': '354', 'type': 'argument_list', 'children': ['355', '361']},{'id': '355', 'type': 'binary_operator', 'children': ['356', '360'], 'value': '+'},{'id': '356', 'type': '()', 'children': ['357']},{'id': '357', 'type': 'binary_operator', 'children': ['358', '359'], 'value': '*'},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '359', 'type': 'integer', 'children': [], 'value': '2'},{'id': '360', 'type': 'integer', 'children': [], 'value': '1'},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'button'},{'id': '362', 'type': 'if_statement', 'children': ['363', '372']},{'id': '363', 'type': '()', 'children': ['364']},{'id': '364', 'type': 'boolean_operator', 'children': ['365', '366'], 'value': 'or'},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'show_last'},{'id': '366', 'type': 'comparison_operator', 'children': ['367', '368'], 'value': '<'},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '368', 'type': '()', 'children': ['369']},{'id': '369', 'type': 'binary_operator', 'children': ['370', '371'], 'value': '-'},{'id': '370', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '371', 'type': 'integer', 'children': [], 'value': '1'},{'id': '372', 'type': 'block', 'children': ['373', '380', '387', '394', '403', '414', '425', '434', '447']},{'id': '373', 'type': 'expression_statement', 'children': ['374']},{'id': '374', 'type': 'assignment', 'children': ['375', '376']},{'id': '375', 'type': 'identifier', 'children': [], 'value': 'button'},{'id': '376', 'type': 'call', 'children': ['377', '378']},{'id': '377', 'type': 'identifier', 'children': [], 'value': 'QToolButton'},{'id': '378', 'type': 'argument_list', 'children': ['379']},{'id': '379', 'type': 'identifier', 'children': [], 'value': 'partsw'},{'id': '380', 'type': 'expression_statement', 'children': ['381']},{'id': '381', 'type': 'call', 'children': ['382', '385']},{'id': '382', 'type': 'attribute', 'children': ['383', '384']},{'id': '383', 'type': 'identifier', 'children': [], 'value': 'button'},{'id': '384', 'type': 'identifier', 'children': [], 'value': 'setAutoRaise'},{'id': '385', 'type': 'argument_list', 'children': ['386']},{'id': '386', 'type': 'True', 'children': []},{'id': '387', 'type': 'expression_statement', 'children': ['388']},{'id': '388', 'type': 'call', 'children': ['389', '392']},{'id': '389', 'type': 'attribute', 'children': ['390', '391']},{'id': '390', 'type': 'identifier', 'children': [], 'value': 'button'},{'id': '391', 'type': 'identifier', 'children': [], 'value': 'setMaximumWidth'},{'id': '392', 'type': 'argument_list', 'children': ['393']},{'id': '393', 'type': 'integer', 'children': [], 'value': '12'},{'id': '394', 'type': 'expression_statement', 'children': ['395']},{'id': '395', 'type': 'call', 'children': ['396', '399']},{'id': '396', 'type': 'attribute', 'children': ['397', '398']},{'id': '397', 'type': 'identifier', 'children': [], 'value': 'button'},{'id': '398', 'type': 'identifier', 'children': [], 'value': 'setArrowType'},{'id': '399', 'type': 'argument_list', 'children': ['400']},{'id': '400', 'type': 'attribute', 'children': ['401', '402']},{'id': '401', 'type': 'identifier', 'children': [], 'value': 'Qt'},{'id': '402', 'type': 'identifier', 'children': [], 'value': 'RightArrow'},{'id': '403', 'type': 'expression_statement', 'children': ['404']},{'id': '404', 'type': 'call', 'children': ['405', '408']},{'id': '405', 'type': 'attribute', 'children': ['406', '407']},{'id': '406', 'type': 'identifier', 'children': [], 'value': 'button'},{'id': '407', 'type': 'identifier', 'children': [], 'value': 'setProperty'},{'id': '408', 'type': 'argument_list', 'children': ['409', '410']},{'id': '409', 'type': 'string', 'children': [], 'value': "'path'"},{'id': '410', 'type': 'call', 'children': ['411', '412']},{'id': '411', 'type': 'identifier', 'children': [], 'value': 'wrapVariant'},{'id': '412', 'type': 'argument_list', 'children': ['413']},{'id': '413', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '414', 'type': 'expression_statement', 'children': ['415']},{'id': '415', 'type': 'call', 'children': ['416', '419']},{'id': '416', 'type': 'attribute', 'children': ['417', '418']},{'id': '417', 'type': 'identifier', 'children': [], 'value': 'button'},{'id': '418', 'type': 'identifier', 'children': [], 'value': 'setProperty'},{'id': '419', 'type': 'argument_list', 'children': ['420', '421']},{'id': '420', 'type': 'string', 'children': [], 'value': "'is_completer'"},{'id': '421', 'type': 'call', 'children': ['422', '423']},{'id': '422', 'type': 'identifier', 'children': [], 'value': 'wrapVariant'},{'id': '423', 'type': 'argument_list', 'children': ['424']},{'id': '424', 'type': 'True', 'children': []},{'id': '425', 'type': 'expression_statement', 'children': ['426']},{'id': '426', 'type': 'call', 'children': ['427', '432']},{'id': '427', 'type': 'attribute', 'children': ['428', '431']},{'id': '428', 'type': 'attribute', 'children': ['429', '430']},{'id': '429', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '430', 'type': 'identifier', 'children': [], 'value': '_buttonGroup'},{'id': '431', 'type': 'identifier', 'children': [], 'value': 'addButton'},{'id': '432', 'type': 'argument_list', 'children': ['433']},{'id': '433', 'type': 'identifier', 'children': [], 'value': 'button'},{'id': '434', 'type': 'expression_statement', 'children': ['435']},{'id': '435', 'type': 'call', 'children': ['436', '439']},{'id': '436', 'type': 'attribute', 'children': ['437', '438']},{'id': '437', 'type': 'identifier', 'children': [], 'value': 'layout'},{'id': '438', 'type': 'identifier', 'children': [], 'value': 'insertWidget'},{'id': '439', 'type': 'argument_list', 'children': ['440', '446']},{'id': '440', 'type': 'binary_operator', 'children': ['441', '445'], 'value': '+'},{'id': '441', 'type': '()', 'children': ['442']},{'id': '442', 'type': 'binary_operator', 'children': ['443', '444'], 'value': '*'},{'id': '443', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '444', 'type': 'integer', 'children': [], 'value': '2'},{'id': '445', 'type': 'integer', 'children': [], 'value': '2'},{'id': '446', 'type': 'identifier', 'children': [], 'value': 'button'},{'id': '447', 'type': 'expression_statement', 'children': ['448']},{'id': '448', 'type': 'assignment', 'children': ['449', '450']},{'id': '449', 'type': 'identifier', 'children': [], 'value': 'last_button'},{'id': '450', 'type': 'identifier', 'children': [], 'value': 'button'},{'id': '451', 'type': 'if_statement', 'children': ['452', '468']},{'id': '452', 'type': '()', 'children': ['453']},{'id': '453', 'type': 'comparison_operator', 'children': ['454', '463'], 'value': '<'},{'id': '454', 'type': 'call', 'children': ['455', '462']},{'id': '455', 'type': 'attribute', 'children': ['456', '461']},{'id': '456', 'type': 'call', 'children': ['457', '460']},{'id': '457', 'type': 'attribute', 'children': ['458', '459']},{'id': '458', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '459', 'type': 'identifier', 'children': [], 'value': 'scrollWidget'},{'id': '460', 'type': 'argument_list', 'children': []},{'id': '461', 'type': 'identifier', 'children': [], 'value': 'width'},{'id': '462', 'type': 'argument_list', 'children': []},{'id': '463', 'type': 'call', 'children': ['464', '467']},{'id': '464', 'type': 'attribute', 'children': ['465', '466']},{'id': '465', 'type': 'identifier', 'children': [], 'value': 'partsw'},{'id': '466', 'type': 'identifier', 'children': [], 'value': 'width'},{'id': '467', 'type': 'argument_list', 'children': []},{'id': '468', 'type': 'block', 'children': ['469']},{'id': '469', 'type': 'expression_statement', 'children': ['470']},{'id': '470', 'type': 'call', 'children': ['471', '474']},{'id': '471', 'type': 'attribute', 'children': ['472', '473']},{'id': '472', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '473', 'type': 'identifier', 'children': [], 'value': 'scrollParts'},{'id': '474', 'type': 'argument_list', 'children': ['475']},{'id': '475', 'type': 'binary_operator', 'children': ['476', '481'], 'value': '-'},{'id': '476', 'type': 'call', 'children': ['477', '480']},{'id': '477', 'type': 'attribute', 'children': ['478', '479']},{'id': '478', 'type': 'identifier', 'children': [], 'value': 'partsw'},{'id': '479', 'type': 'identifier', 'children': [], 'value': 'width'},{'id': '480', 'type': 'argument_list', 'children': []},{'id': '481', 'type': 'call', 'children': ['482', '489']},{'id': '482', 'type': 'attribute', 'children': ['483', '488']},{'id': '483', 'type': 'call', 'children': ['484', '487']},{'id': '484', 'type': 'attribute', 'children': ['485', '486']},{'id': '485', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '486', 'type': 'identifier', 'children': [], 'value': 'scrollWidget'},{'id': '487', 'type': 'argument_list', 'children': []},{'id': '488', 'type': 'identifier', 'children': [], 'value': 'width'},{'id': '489', 'type': 'argument_list', 'children': []},{'id': '490', 'type': 'expression_statement', 'children': ['491']},{'id': '491', 'type': 'call', 'children': ['492', '495']},{'id': '492', 'type': 'attribute', 'children': ['493', '494']},{'id': '493', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '494', 'type': 'identifier', 'children': [], 'value': 'setUpdatesEnabled'},{'id': '495', 'type': 'argument_list', 'children': ['496']},{'id': '496', 'type': 'True', 'children': []},{'id': '497', 'type': 'expression_statement', 'children': ['498']},{'id': '498', 'type': 'call', 'children': ['499', '504']},{'id': '499', 'type': 'attribute', 'children': ['500', '503']},{'id': '500', 'type': 'attribute', 'children': ['501', '502']},{'id': '501', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '502', 'type': 'identifier', 'children': [], 'value': 'navigationChanged'},{'id': '503', 'type': 'identifier', 'children': [], 'value': 'emit'},{'id': '504', 'type': 'argument_list', 'children': []}
def rebuild( self ): 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() 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) if ( self._navigationModel ): last_item = self._navigationModel.itemByPath(self.text()) show_last = last_item and last_item.rowCount() > 0 else: show_last = False 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) 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()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'syncView'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'recursive'},{'id': '7', 'type': 'False', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '17', '25', '30', '38', '46', '54', '68', '80', '85', '102']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'gantt'},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'ganttWidget'},{'id': '16', 'type': 'argument_list', 'children': []},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'tree'},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'treeWidget'},{'id': '24', 'type': 'argument_list', 'children': []},{'id': '25', 'type': 'if_statement', 'children': ['26', '28']},{'id': '26', 'type': 'not_operator', 'children': ['27']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'gantt'},{'id': '28', 'type': 'block', 'children': ['29']},{'id': '29', 'type': 'return_statement', 'children': []},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'vwidget'},{'id': '33', 'type': 'call', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'gantt'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'viewWidget'},{'id': '37', 'type': 'argument_list', 'children': []},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'scene'},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'vwidget'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'scene'},{'id': '45', 'type': 'argument_list', 'children': []},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'cell_w'},{'id': '49', 'type': 'call', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'gantt'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'cellWidth'},{'id': '53', 'type': 'argument_list', 'children': []},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'tree_offset_y'},{'id': '57', 'type': 'binary_operator', 'children': ['58', '67'], 'value': '+'},{'id': '58', 'type': 'call', 'children': ['59', '66']},{'id': '59', 'type': 'attribute', 'children': ['60', '65']},{'id': '60', 'type': 'call', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'tree'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '64', 'type': 'argument_list', 'children': []},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'height'},{'id': '66', 'type': 'argument_list', 'children': []},{'id': '67', 'type': 'integer', 'children': [], 'value': '1'},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'augmented_assignment', 'children': ['70', '71'], 'value': '+='},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'tree_offset_y'},{'id': '71', 'type': 'call', 'children': ['72', '79']},{'id': '72', 'type': 'attribute', 'children': ['73', '78']},{'id': '73', 'type': 'call', 'children': ['74', '77']},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'tree'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'verticalScrollBar'},{'id': '77', 'type': 'argument_list', 'children': []},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '79', 'type': 'argument_list', 'children': []},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '83', 'type': 'list', 'children': ['84'], 'value': '[self]'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '85', 'type': 'if_statement', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'recursive'},{'id': '87', 'type': 'block', 'children': ['88']},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'augmented_assignment', 'children': ['90', '91'], 'value': '+='},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '91', 'type': 'call', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'call', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'children'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'keyword_argument', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'recursive'},{'id': '101', 'type': 'True', 'children': []},{'id': '102', 'type': 'for_statement', 'children': ['103', '104', '105']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '105', 'type': 'block', 'children': ['106', '114', '129', '146', '152', '161', '171', '179', '195', '424', '432', '439', '447', '457', '464', '470', '476', '493', '500']},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'assignment', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'vitem'},{'id': '109', 'type': 'call', 'children': ['110', '113']},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'viewItem'},{'id': '113', 'type': 'argument_list', 'children': []},{'id': '114', 'type': 'if_statement', 'children': ['115', '121']},{'id': '115', 'type': 'not_operator', 'children': ['116']},{'id': '116', 'type': 'call', 'children': ['117', '120']},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'vitem'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'scene'},{'id': '120', 'type': 'argument_list', 'children': []},{'id': '121', 'type': 'block', 'children': ['122']},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'call', 'children': ['124', '127']},{'id': '124', 'type': 'attribute', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'scene'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'addItem'},{'id': '127', 'type': 'argument_list', 'children': ['128']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'vitem'},{'id': '129', 'type': 'if_statement', 'children': ['130', '138']},{'id': '130', 'type': 'boolean_operator', 'children': ['131', '136'], 'value': 'or'},{'id': '131', 'type': 'call', 'children': ['132', '135']},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'isHidden'},{'id': '135', 'type': 'argument_list', 'children': []},{'id': '136', 'type': 'not_operator', 'children': ['137']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'tree'},{'id': '138', 'type': 'block', 'children': ['139', '145']},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'id': '140', 'type': 'call', 'children': ['141', '144']},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'vitem'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'hide'},{'id': '144', 'type': 'argument_list', 'children': []},{'id': '145', 'type': 'continue_statement', 'children': []},{'id': '146', 'type': 'expression_statement', 'children': ['147']},{'id': '147', 'type': 'call', 'children': ['148', '151']},{'id': '148', 'type': 'attribute', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'vitem'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'show'},{'id': '151', 'type': 'argument_list', 'children': []},{'id': '152', 'type': 'expression_statement', 'children': ['153']},{'id': '153', 'type': 'assignment', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'tree_rect'},{'id': '155', 'type': 'call', 'children': ['156', '159']},{'id': '156', 'type': 'attribute', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'tree'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'visualItemRect'},{'id': '159', 'type': 'argument_list', 'children': ['160']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '161', 'type': 'expression_statement', 'children': ['162']},{'id': '162', 'type': 'assignment', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'tree_y'},{'id': '164', 'type': 'binary_operator', 'children': ['165', '170'], 'value': '+'},{'id': '165', 'type': 'call', 'children': ['166', '169']},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'tree_rect'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '169', 'type': 'argument_list', 'children': []},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'tree_offset_y'},{'id': '171', 'type': 'expression_statement', 'children': ['172']},{'id': '172', 'type': 'assignment', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'tree_h'},{'id': '174', 'type': 'call', 'children': ['175', '178']},{'id': '175', 'type': 'attribute', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'tree_rect'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'height'},{'id': '178', 'type': 'argument_list', 'children': []},{'id': '179', 'type': 'if_statement', 'children': ['180', '187']},{'id': '180', 'type': 'comparison_operator', 'children': ['181', '186'], 'value': '=='},{'id': '181', 'type': 'call', 'children': ['182', '185']},{'id': '182', 'type': 'attribute', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'tree_rect'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'height'},{'id': '185', 'type': 'argument_list', 'children': []},{'id': '186', 'type': 'integer', 'children': [], 'value': '0'},{'id': '187', 'type': 'block', 'children': ['188', '194']},{'id': '188', 'type': 'expression_statement', 'children': ['189']},{'id': '189', 'type': 'call', 'children': ['190', '193']},{'id': '190', 'type': 'attribute', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'vitem'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'hide'},{'id': '193', 'type': 'argument_list', 'children': []},{'id': '194', 'type': 'continue_statement', 'children': []},{'id': '195', 'type': 'if_statement', 'children': ['196', '218', '259']},{'id': '196', 'type': 'comparison_operator', 'children': ['197', '202'], 'value': 'in'},{'id': '197', 'type': 'call', 'children': ['198', '201']},{'id': '198', 'type': 'attribute', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'gantt'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'timescale'},{'id': '201', 'type': 'argument_list', 'children': []},{'id': '202', 'type': 'tuple', 'children': ['203', '208', '213']},{'id': '203', 'type': 'attribute', 'children': ['204', '207']},{'id': '204', 'type': 'attribute', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'gantt'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'Timescale'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'Minute'},{'id': '208', 'type': 'attribute', 'children': ['209', '212']},{'id': '209', 'type': 'attribute', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'gantt'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'Timescale'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'Hour'},{'id': '213', 'type': 'attribute', 'children': ['214', '217']},{'id': '214', 'type': 'attribute', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'gantt'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'Timescale'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'Day'},{'id': '218', 'type': 'block', 'children': ['219', '227', '235', '244', '253']},{'id': '219', 'type': 'expression_statement', 'children': ['220']},{'id': '220', 'type': 'assignment', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'dstart'},{'id': '222', 'type': 'call', 'children': ['223', '226']},{'id': '223', 'type': 'attribute', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'dateTimeStart'},{'id': '226', 'type': 'argument_list', 'children': []},{'id': '227', 'type': 'expression_statement', 'children': ['228']},{'id': '228', 'type': 'assignment', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'dend'},{'id': '230', 'type': 'call', 'children': ['231', '234']},{'id': '231', 'type': 'attribute', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'dateTimeEnd'},{'id': '234', 'type': 'argument_list', 'children': []},{'id': '235', 'type': 'expression_statement', 'children': ['236']},{'id': '236', 'type': 'assignment', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'view_x'},{'id': '238', 'type': 'call', 'children': ['239', '242']},{'id': '239', 'type': 'attribute', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'scene'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'datetimeXPos'},{'id': '242', 'type': 'argument_list', 'children': ['243']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'dstart'},{'id': '244', 'type': 'expression_statement', 'children': ['245']},{'id': '245', 'type': 'assignment', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'view_r'},{'id': '247', 'type': 'call', 'children': ['248', '251']},{'id': '248', 'type': 'attribute', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'scene'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'datetimeXPos'},{'id': '251', 'type': 'argument_list', 'children': ['252']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'dend'},{'id': '253', 'type': 'expression_statement', 'children': ['254']},{'id': '254', 'type': 'assignment', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'view_w'},{'id': '256', 'type': 'binary_operator', 'children': ['257', '258'], 'value': '-'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'view_r'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'view_x'},{'id': '259', 'type': 'else_clause', 'children': ['260']},{'id': '260', 'type': 'block', 'children': ['261', '274', '284']},{'id': '261', 'type': 'expression_statement', 'children': ['262']},{'id': '262', 'type': 'assignment', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'view_x'},{'id': '264', 'type': 'call', 'children': ['265', '268']},{'id': '265', 'type': 'attribute', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'scene'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'dateXPos'},{'id': '268', 'type': 'argument_list', 'children': ['269']},{'id': '269', 'type': 'call', 'children': ['270', '273']},{'id': '270', 'type': 'attribute', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'dateStart'},{'id': '273', 'type': 'argument_list', 'children': []},{'id': '274', 'type': 'expression_statement', 'children': ['275']},{'id': '275', 'type': 'assignment', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'view_w'},{'id': '277', 'type': 'binary_operator', 'children': ['278', '283'], 'value': '*'},{'id': '278', 'type': 'call', 'children': ['279', '282']},{'id': '279', 'type': 'attribute', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'duration'},{'id': '282', 'type': 'argument_list', 'children': []},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'cell_w'},{'id': '284', 'type': 'if_statement', 'children': ['285', '291']},{'id': '285', 'type': 'not_operator', 'children': ['286']},{'id': '286', 'type': 'call', 'children': ['287', '290']},{'id': '287', 'type': 'attribute', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'isAllDay'},{'id': '290', 'type': 'argument_list', 'children': []},{'id': '291', 'type': 'block', 'children': ['292', '300', '308', '321', '332', '341', '353', '361', '374', '385', '396', '409', '413', '417']},{'id': '292', 'type': 'expression_statement', 'children': ['293']},{'id': '293', 'type': 'assignment', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'full_day'},{'id': '295', 'type': 'binary_operator', 'children': ['296', '299'], 'value': '*'},{'id': '296', 'type': 'binary_operator', 'children': ['297', '298'], 'value': '*'},{'id': '297', 'type': 'integer', 'children': [], 'value': '24'},{'id': '298', 'type': 'integer', 'children': [], 'value': '60'},{'id': '299', 'type': 'integer', 'children': [], 'value': '60'},{'id': '300', 'type': 'expression_statement', 'children': ['301']},{'id': '301', 'type': 'assignment', 'children': ['302', '303']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '303', 'type': 'call', 'children': ['304', '307']},{'id': '304', 'type': 'attribute', 'children': ['305', '306']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'timeStart'},{'id': '307', 'type': 'argument_list', 'children': []},{'id': '308', 'type': 'expression_statement', 'children': ['309']},{'id': '309', 'type': 'assignment', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'start_day'},{'id': '311', 'type': '()', 'children': ['312']},{'id': '312', 'type': 'binary_operator', 'children': ['313', '320'], 'value': '*'},{'id': '313', 'type': 'binary_operator', 'children': ['314', '319'], 'value': '*'},{'id': '314', 'type': 'call', 'children': ['315', '318']},{'id': '315', 'type': 'attribute', 'children': ['316', '317']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'hour'},{'id': '318', 'type': 'argument_list', 'children': []},{'id': '319', 'type': 'integer', 'children': [], 'value': '60'},{'id': '320', 'type': 'integer', 'children': [], 'value': '60'},{'id': '321', 'type': 'expression_statement', 'children': ['322']},{'id': '322', 'type': 'augmented_assignment', 'children': ['323', '324'], 'value': '+='},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'start_day'},{'id': '324', 'type': '()', 'children': ['325']},{'id': '325', 'type': 'binary_operator', 'children': ['326', '331'], 'value': '*'},{'id': '326', 'type': 'call', 'children': ['327', '330']},{'id': '327', 'type': 'attribute', 'children': ['328', '329']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'minute'},{'id': '330', 'type': 'argument_list', 'children': []},{'id': '331', 'type': 'integer', 'children': [], 'value': '60'},{'id': '332', 'type': 'expression_statement', 'children': ['333']},{'id': '333', 'type': 'augmented_assignment', 'children': ['334', '335'], 'value': '+='},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'start_day'},{'id': '335', 'type': '()', 'children': ['336']},{'id': '336', 'type': 'call', 'children': ['337', '340']},{'id': '337', 'type': 'attribute', 'children': ['338', '339']},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'second'},{'id': '340', 'type': 'argument_list', 'children': []},{'id': '341', 'type': 'expression_statement', 'children': ['342']},{'id': '342', 'type': 'assignment', 'children': ['343', '344']},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'offset_start'},{'id': '344', 'type': 'binary_operator', 'children': ['345', '352'], 'value': '*'},{'id': '345', 'type': '()', 'children': ['346']},{'id': '346', 'type': 'binary_operator', 'children': ['347', '348'], 'value': '/'},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'start_day'},{'id': '348', 'type': 'call', 'children': ['349', '350']},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '350', 'type': 'argument_list', 'children': ['351']},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'full_day'},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'cell_w'},{'id': '353', 'type': 'expression_statement', 'children': ['354']},{'id': '354', 'type': 'assignment', 'children': ['355', '356']},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '356', 'type': 'call', 'children': ['357', '360']},{'id': '357', 'type': 'attribute', 'children': ['358', '359']},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '359', 'type': 'identifier', 'children': [], 'value': 'timeEnd'},{'id': '360', 'type': 'argument_list', 'children': []},{'id': '361', 'type': 'expression_statement', 'children': ['362']},{'id': '362', 'type': 'assignment', 'children': ['363', '364']},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'end_day'},{'id': '364', 'type': '()', 'children': ['365']},{'id': '365', 'type': 'binary_operator', 'children': ['366', '373'], 'value': '*'},{'id': '366', 'type': 'binary_operator', 'children': ['367', '372'], 'value': '*'},{'id': '367', 'type': 'call', 'children': ['368', '371']},{'id': '368', 'type': 'attribute', 'children': ['369', '370']},{'id': '369', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '370', 'type': 'identifier', 'children': [], 'value': 'hour'},{'id': '371', 'type': 'argument_list', 'children': []},{'id': '372', 'type': 'integer', 'children': [], 'value': '60'},{'id': '373', 'type': 'integer', 'children': [], 'value': '60'},{'id': '374', 'type': 'expression_statement', 'children': ['375']},{'id': '375', 'type': 'augmented_assignment', 'children': ['376', '377'], 'value': '+='},{'id': '376', 'type': 'identifier', 'children': [], 'value': 'end_day'},{'id': '377', 'type': '()', 'children': ['378']},{'id': '378', 'type': 'binary_operator', 'children': ['379', '384'], 'value': '*'},{'id': '379', 'type': 'call', 'children': ['380', '383']},{'id': '380', 'type': 'attribute', 'children': ['381', '382']},{'id': '381', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '382', 'type': 'identifier', 'children': [], 'value': 'minute'},{'id': '383', 'type': 'argument_list', 'children': []},{'id': '384', 'type': 'integer', 'children': [], 'value': '60'},{'id': '385', 'type': 'expression_statement', 'children': ['386']},{'id': '386', 'type': 'augmented_assignment', 'children': ['387', '388'], 'value': '+='},{'id': '387', 'type': 'identifier', 'children': [], 'value': 'end_day'},{'id': '388', 'type': '()', 'children': ['389']},{'id': '389', 'type': 'binary_operator', 'children': ['390', '395'], 'value': '+'},{'id': '390', 'type': 'call', 'children': ['391', '394']},{'id': '391', 'type': 'attribute', 'children': ['392', '393']},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '393', 'type': 'identifier', 'children': [], 'value': 'second'},{'id': '394', 'type': 'argument_list', 'children': []},{'id': '395', 'type': 'integer', 'children': [], 'value': '1'},{'id': '396', 'type': 'expression_statement', 'children': ['397']},{'id': '397', 'type': 'assignment', 'children': ['398', '399']},{'id': '398', 'type': 'identifier', 'children': [], 'value': 'offset_end'},{'id': '399', 'type': '()', 'children': ['400']},{'id': '400', 'type': 'binary_operator', 'children': ['401', '405'], 'value': '/'},{'id': '401', 'type': '()', 'children': ['402']},{'id': '402', 'type': 'binary_operator', 'children': ['403', '404'], 'value': '-'},{'id': '403', 'type': 'identifier', 'children': [], 'value': 'full_day'},{'id': '404', 'type': 'identifier', 'children': [], 'value': 'end_day'},{'id': '405', 'type': 'call', 'children': ['406', '407']},{'id': '406', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '407', 'type': 'argument_list', 'children': ['408']},{'id': '408', 'type': 'identifier', 'children': [], 'value': 'full_day'},{'id': '409', 'type': 'expression_statement', 'children': ['410']},{'id': '410', 'type': 'augmented_assignment', 'children': ['411', '412'], 'value': '*='},{'id': '411', 'type': 'identifier', 'children': [], 'value': 'offset_end'},{'id': '412', 'type': 'identifier', 'children': [], 'value': 'cell_w'},{'id': '413', 'type': 'expression_statement', 'children': ['414']},{'id': '414', 'type': 'augmented_assignment', 'children': ['415', '416'], 'value': '+='},{'id': '415', 'type': 'identifier', 'children': [], 'value': 'view_x'},{'id': '416', 'type': 'identifier', 'children': [], 'value': 'offset_start'},{'id': '417', 'type': 'expression_statement', 'children': ['418']},{'id': '418', 'type': 'augmented_assignment', 'children': ['419', '420'], 'value': '-='},{'id': '419', 'type': 'identifier', 'children': [], 'value': 'view_w'},{'id': '420', 'type': '()', 'children': ['421']},{'id': '421', 'type': 'binary_operator', 'children': ['422', '423'], 'value': '+'},{'id': '422', 'type': 'identifier', 'children': [], 'value': 'offset_start'},{'id': '423', 'type': 'identifier', 'children': [], 'value': 'offset_end'},{'id': '424', 'type': 'expression_statement', 'children': ['425']},{'id': '425', 'type': 'assignment', 'children': ['426', '427']},{'id': '426', 'type': 'identifier', 'children': [], 'value': 'view_w'},{'id': '427', 'type': 'call', 'children': ['428', '429']},{'id': '428', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '429', 'type': 'argument_list', 'children': ['430', '431']},{'id': '430', 'type': 'identifier', 'children': [], 'value': 'view_w'},{'id': '431', 'type': 'integer', 'children': [], 'value': '5'},{'id': '432', 'type': 'expression_statement', 'children': ['433']},{'id': '433', 'type': 'call', 'children': ['434', '437']},{'id': '434', 'type': 'attribute', 'children': ['435', '436']},{'id': '435', 'type': 'identifier', 'children': [], 'value': 'vitem'},{'id': '436', 'type': 'identifier', 'children': [], 'value': 'setSyncing'},{'id': '437', 'type': 'argument_list', 'children': ['438']},{'id': '438', 'type': 'True', 'children': []},{'id': '439', 'type': 'expression_statement', 'children': ['440']},{'id': '440', 'type': 'call', 'children': ['441', '444']},{'id': '441', 'type': 'attribute', 'children': ['442', '443']},{'id': '442', 'type': 'identifier', 'children': [], 'value': 'vitem'},{'id': '443', 'type': 'identifier', 'children': [], 'value': 'setPos'},{'id': '444', 'type': 'argument_list', 'children': ['445', '446']},{'id': '445', 'type': 'identifier', 'children': [], 'value': 'view_x'},{'id': '446', 'type': 'identifier', 'children': [], 'value': 'tree_y'},{'id': '447', 'type': 'expression_statement', 'children': ['448']},{'id': '448', 'type': 'call', 'children': ['449', '452']},{'id': '449', 'type': 'attribute', 'children': ['450', '451']},{'id': '450', 'type': 'identifier', 'children': [], 'value': 'vitem'},{'id': '451', 'type': 'identifier', 'children': [], 'value': 'setRect'},{'id': '452', 'type': 'argument_list', 'children': ['453', '454', '455', '456']},{'id': '453', 'type': 'integer', 'children': [], 'value': '0'},{'id': '454', 'type': 'integer', 'children': [], 'value': '0'},{'id': '455', 'type': 'identifier', 'children': [], 'value': 'view_w'},{'id': '456', 'type': 'identifier', 'children': [], 'value': 'tree_h'},{'id': '457', 'type': 'expression_statement', 'children': ['458']},{'id': '458', 'type': 'call', 'children': ['459', '462']},{'id': '459', 'type': 'attribute', 'children': ['460', '461']},{'id': '460', 'type': 'identifier', 'children': [], 'value': 'vitem'},{'id': '461', 'type': 'identifier', 'children': [], 'value': 'setSyncing'},{'id': '462', 'type': 'argument_list', 'children': ['463']},{'id': '463', 'type': 'False', 'children': []},{'id': '464', 'type': 'expression_statement', 'children': ['465']},{'id': '465', 'type': 'assignment', 'children': ['466', '467']},{'id': '466', 'type': 'identifier', 'children': [], 'value': 'flags'},{'id': '467', 'type': 'attribute', 'children': ['468', '469']},{'id': '468', 'type': 'identifier', 'children': [], 'value': 'vitem'},{'id': '469', 'type': 'identifier', 'children': [], 'value': 'ItemIsSelectable'},{'id': '470', 'type': 'expression_statement', 'children': ['471']},{'id': '471', 'type': 'augmented_assignment', 'children': ['472', '473'], 'value': '|='},{'id': '472', 'type': 'identifier', 'children': [], 'value': 'flags'},{'id': '473', 'type': 'attribute', 'children': ['474', '475']},{'id': '474', 'type': 'identifier', 'children': [], 'value': 'vitem'},{'id': '475', 'type': 'identifier', 'children': [], 'value': 'ItemIsFocusable'},{'id': '476', 'type': 'if_statement', 'children': ['477', '486']},{'id': '477', 'type': 'binary_operator', 'children': ['478', '483'], 'value': '&'},{'id': '478', 'type': 'call', 'children': ['479', '482']},{'id': '479', 'type': 'attribute', 'children': ['480', '481']},{'id': '480', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '481', 'type': 'identifier', 'children': [], 'value': 'flags'},{'id': '482', 'type': 'argument_list', 'children': []},{'id': '483', 'type': 'attribute', 'children': ['484', '485']},{'id': '484', 'type': 'identifier', 'children': [], 'value': 'Qt'},{'id': '485', 'type': 'identifier', 'children': [], 'value': 'ItemIsEditable'},{'id': '486', 'type': 'block', 'children': ['487']},{'id': '487', 'type': 'expression_statement', 'children': ['488']},{'id': '488', 'type': 'augmented_assignment', 'children': ['489', '490'], 'value': '|='},{'id': '489', 'type': 'identifier', 'children': [], 'value': 'flags'},{'id': '490', 'type': 'attribute', 'children': ['491', '492']},{'id': '491', 'type': 'identifier', 'children': [], 'value': 'vitem'},{'id': '492', 'type': 'identifier', 'children': [], 'value': 'ItemIsMovable'},{'id': '493', 'type': 'expression_statement', 'children': ['494']},{'id': '494', 'type': 'call', 'children': ['495', '498']},{'id': '495', 'type': 'attribute', 'children': ['496', '497']},{'id': '496', 'type': 'identifier', 'children': [], 'value': 'vitem'},{'id': '497', 'type': 'identifier', 'children': [], 'value': 'setFlags'},{'id': '498', 'type': 'argument_list', 'children': ['499']},{'id': '499', 'type': 'identifier', 'children': [], 'value': 'flags'},{'id': '500', 'type': 'expression_statement', 'children': ['501']},{'id': '501', 'type': 'call', 'children': ['502', '505']},{'id': '502', 'type': 'attribute', 'children': ['503', '504']},{'id': '503', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '504', 'type': 'identifier', 'children': [], 'value': 'syncDependencies'},{'id': '505', 'type': 'argument_list', 'children': []}
def syncView(self, recursive=False): 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() items = [self] if recursive: items += list(self.children(recursive=True)) for item in items: vitem = item.viewItem() if not vitem.scene(): scene.addItem(vitem) 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() 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 if not item.isAllDay(): full_day = 24 * 60 * 60 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 end = item.timeEnd() end_day = (end.hour() * 60 * 60) end_day += (start.minute() * 60) end_day += (start.second() + 1) offset_end = ((full_day - end_day) / float(full_day)) offset_end *= cell_w 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) flags = vitem.ItemIsSelectable flags |= vitem.ItemIsFocusable if item.flags() & Qt.ItemIsEditable: flags |= vitem.ItemIsMovable vitem.setFlags(flags) item.syncDependencies()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '18']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'nodes'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'keyword_separator', 'children': []},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'dc'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'near'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'watch'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'consistency'},{'id': '17', 'type': 'None', 'children': []},{'id': '18', 'type': 'block', 'children': ['19', '29', '50']},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '22', 'type': 'dictionary', 'children': ['23', '26']},{'id': '23', 'type': 'pair', 'children': ['24', '25']},{'id': '24', 'type': 'string', 'children': [], 'value': '"dc"'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'dc'},{'id': '26', 'type': 'pair', 'children': ['27', '28']},{'id': '27', 'type': 'string', 'children': [], 'value': '"near"'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'near'},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '32', 'type': 'await', 'children': ['33']},{'id': '33', 'type': 'call', 'children': ['34', '39']},{'id': '34', 'type': 'attribute', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '37', 'type': 'identifier', 'children': [], 'value': '_api'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '39', 'type': 'argument_list', 'children': ['40', '41', '44', '47']},{'id': '40', 'type': 'string', 'children': [], 'value': '"/v1/catalog/nodes"'},{'id': '41', 'type': 'keyword_argument', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '44', 'type': 'keyword_argument', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'watch'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'watch'},{'id': '47', 'type': 'keyword_argument', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'consistency'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'consistency'},{'id': '50', 'type': 'return_statement', 'children': ['51']},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'consul'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'response'}
async def nodes(self, *, dc=None, near=None, watch=None, consistency=None): params = {"dc": dc, "near": near} response = await self._api.get("/v1/catalog/nodes", params=params, watch=watch, consistency=consistency) return consul(response)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '28']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'keyphrases_graph'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18', '21']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'keyphrases'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'texts'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'referral_confidence'},{'id': '8', 'type': 'float', 'children': [], 'value': '0.6'},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'relevance_threshold'},{'id': '11', 'type': 'float', 'children': [], 'value': '0.25'},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'support_threshold'},{'id': '14', 'type': 'integer', 'children': [], 'value': '1'},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'similarity_measure'},{'id': '17', 'type': 'None', 'children': []},{'id': '18', 'type': 'default_parameter', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'synonimizer'},{'id': '20', 'type': 'None', 'children': []},{'id': '21', 'type': 'default_parameter', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'language'},{'id': '23', 'type': 'attribute', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'consts'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'Language'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'ENGLISH'},{'id': '28', 'type': 'block', 'children': ['29', '39', '50', '75', '117', '140', '237']},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'similarity_measure'},{'id': '32', 'type': 'boolean_operator', 'children': ['33', '34'], 'value': 'or'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'similarity_measure'},{'id': '34', 'type': 'call', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'relevance'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'ASTRelevanceMeasure'},{'id': '38', 'type': 'argument_list', 'children': []},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '42', 'type': 'call', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'keyphrases_table'},{'id': '44', 'type': 'argument_list', 'children': ['45', '46', '47', '48', '49']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'keyphrases'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'texts'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'similarity_measure'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'synonimizer'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'language'},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'keyphrase_texts'},{'id': '53', 'type': 'dictionary_comprehension', 'children': ['54', '72']},{'id': '54', 'type': 'pair', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'keyphrase'},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'list_comprehension', 'children': ['60', '61', '64']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '61', 'type': 'for_in_clause', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'texts'},{'id': '64', 'type': 'if_clause', 'children': ['65']},{'id': '65', 'type': 'comparison_operator', 'children': ['66', '71'], 'value': '>='},{'id': '66', 'type': 'subscript', 'children': ['67', '70']},{'id': '67', 'type': 'subscript', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'keyphrase'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'relevance_threshold'},{'id': '72', 'type': 'for_in_clause', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'keyphrase'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'keyphrases'},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'assignment', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '78', 'type': 'dictionary', 'children': ['79', '105', '108', '111', '114']},{'id': '79', 'type': 'pair', 'children': ['80', '81']},{'id': '80', 'type': 'string', 'children': [], 'value': '"nodes"'},{'id': '81', 'type': 'list_comprehension', 'children': ['82', '97']},{'id': '82', 'type': 'dictionary', 'children': ['83', '86', '89']},{'id': '83', 'type': 'pair', 'children': ['84', '85']},{'id': '84', 'type': 'string', 'children': [], 'value': '"id"'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '86', 'type': 'pair', 'children': ['87', '88']},{'id': '87', 'type': 'string', 'children': [], 'value': '"label"'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'keyphrase'},{'id': '89', 'type': 'pair', 'children': ['90', '91']},{'id': '90', 'type': 'string', 'children': [], 'value': '"support"'},{'id': '91', 'type': 'call', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'subscript', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'keyphrase_texts'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'keyphrase'},{'id': '97', 'type': 'for_in_clause', 'children': ['98', '101']},{'id': '98', 'type': 'pattern_list', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'keyphrase'},{'id': '101', 'type': 'call', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'keyphrases'},{'id': '105', 'type': 'pair', 'children': ['106', '107']},{'id': '106', 'type': 'string', 'children': [], 'value': '"edges"'},{'id': '107', 'type': 'list', 'children': [], 'value': '[]'},{'id': '108', 'type': 'pair', 'children': ['109', '110']},{'id': '109', 'type': 'string', 'children': [], 'value': '"referral_confidence"'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'referral_confidence'},{'id': '111', 'type': 'pair', 'children': ['112', '113']},{'id': '112', 'type': 'string', 'children': [], 'value': '"relevance_threshold"'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'relevance_threshold'},{'id': '114', 'type': 'pair', 'children': ['115', '116']},{'id': '115', 'type': 'string', 'children': [], 'value': '"support_threshold"'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'support_threshold'},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '122']},{'id': '119', 'type': 'subscript', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '121', 'type': 'string', 'children': [], 'value': '"nodes"'},{'id': '122', 'type': 'list_comprehension', 'children': ['123', '124', '129']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '124', 'type': 'for_in_clause', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '126', 'type': 'subscript', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '128', 'type': 'string', 'children': [], 'value': '"nodes"'},{'id': '129', 'type': 'if_clause', 'children': ['130']},{'id': '130', 'type': 'comparison_operator', 'children': ['131', '139'], 'value': '>='},{'id': '131', 'type': 'call', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '133', 'type': 'argument_list', 'children': ['134']},{'id': '134', 'type': 'subscript', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'keyphrase_texts'},{'id': '136', 'type': 'subscript', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '138', 'type': 'string', 'children': [], 'value': '"label"'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'support_threshold'},{'id': '140', 'type': 'for_statement', 'children': ['141', '144', '159']},{'id': '141', 'type': 'pattern_list', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'i1'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'i2'},{'id': '144', 'type': 'call', 'children': ['145', '148']},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'itertools'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'permutations'},{'id': '148', 'type': 'argument_list', 'children': ['149', '158']},{'id': '149', 'type': 'call', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '151', 'type': 'argument_list', 'children': ['152']},{'id': '152', 'type': 'call', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '154', 'type': 'argument_list', 'children': ['155']},{'id': '155', 'type': 'subscript', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '157', 'type': 'string', 'children': [], 'value': '"nodes"'},{'id': '158', 'type': 'integer', 'children': [], 'value': '2'},{'id': '159', 'type': 'block', 'children': ['160', '168', '176', '210']},{'id': '160', 'type': 'expression_statement', 'children': ['161']},{'id': '161', 'type': 'assignment', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'node1'},{'id': '163', 'type': 'subscript', 'children': ['164', '167']},{'id': '164', 'type': 'subscript', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '166', 'type': 'string', 'children': [], 'value': '"nodes"'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'i1'},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'id': '169', 'type': 'assignment', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'node2'},{'id': '171', 'type': 'subscript', 'children': ['172', '175']},{'id': '172', 'type': 'subscript', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '174', 'type': 'string', 'children': [], 'value': '"nodes"'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'i2'},{'id': '176', 'type': 'expression_statement', 'children': ['177']},{'id': '177', 'type': 'assignment', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'confidence'},{'id': '179', 'type': '()', 'children': ['180']},{'id': '180', 'type': 'binary_operator', 'children': ['181', '198'], 'value': '/'},{'id': '181', 'type': 'call', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '183', 'type': 'argument_list', 'children': ['184']},{'id': '184', 'type': 'call', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '186', 'type': 'argument_list', 'children': ['187']},{'id': '187', 'type': 'binary_operator', 'children': ['188', '193'], 'value': '&'},{'id': '188', 'type': 'subscript', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'keyphrase_texts'},{'id': '190', 'type': 'subscript', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'node1'},{'id': '192', 'type': 'string', 'children': [], 'value': '"label"'},{'id': '193', 'type': 'subscript', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'keyphrase_texts'},{'id': '195', 'type': 'subscript', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'node2'},{'id': '197', 'type': 'string', 'children': [], 'value': '"label"'},{'id': '198', 'type': 'call', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '200', 'type': 'argument_list', 'children': ['201', '209']},{'id': '201', 'type': 'call', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '203', 'type': 'argument_list', 'children': ['204']},{'id': '204', 'type': 'subscript', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'keyphrase_texts'},{'id': '206', 'type': 'subscript', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'node1'},{'id': '208', 'type': 'string', 'children': [], 'value': '"label"'},{'id': '209', 'type': 'integer', 'children': [], 'value': '1'},{'id': '210', 'type': 'if_statement', 'children': ['211', '214']},{'id': '211', 'type': 'comparison_operator', 'children': ['212', '213'], 'value': '>='},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'confidence'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'referral_confidence'},{'id': '214', 'type': 'block', 'children': ['215']},{'id': '215', 'type': 'expression_statement', 'children': ['216']},{'id': '216', 'type': 'call', 'children': ['217', '222']},{'id': '217', 'type': 'attribute', 'children': ['218', '221']},{'id': '218', 'type': 'subscript', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '220', 'type': 'string', 'children': [], 'value': '"edges"'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '222', 'type': 'argument_list', 'children': ['223']},{'id': '223', 'type': 'dictionary', 'children': ['224', '229', '234']},{'id': '224', 'type': 'pair', 'children': ['225', '226']},{'id': '225', 'type': 'string', 'children': [], 'value': '"source"'},{'id': '226', 'type': 'subscript', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'node1'},{'id': '228', 'type': 'string', 'children': [], 'value': '"id"'},{'id': '229', 'type': 'pair', 'children': ['230', '231']},{'id': '230', 'type': 'string', 'children': [], 'value': '"target"'},{'id': '231', 'type': 'subscript', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'node2'},{'id': '233', 'type': 'string', 'children': [], 'value': '"id"'},{'id': '234', 'type': 'pair', 'children': ['235', '236']},{'id': '235', 'type': 'string', 'children': [], 'value': '"confidence"'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'confidence'},{'id': '237', 'type': 'return_statement', 'children': ['238']},{'id': '238', 'type': 'identifier', 'children': [], 'value': '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): similarity_measure = similarity_measure or relevance.ASTRelevanceMeasure() table = keyphrases_table(keyphrases, texts, similarity_measure, synonimizer, language) keyphrase_texts = {keyphrase: set([text for text in texts if table[keyphrase][text] >= relevance_threshold]) for keyphrase in keyphrases} 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 } graph["nodes"] = [n for n in graph["nodes"] if len(keyphrase_texts[n["label"]]) >= support_threshold] 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
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_hm_verify_message_crc_uk'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '10']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'thermostat_id'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'protocol'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'expectedFunction'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'expectedLength'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'datal'},{'id': '11', 'type': 'block', 'children': ['12', '16']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'badresponse'},{'id': '15', 'type': 'integer', 'children': [], 'value': '0'},{'id': '16', 'type': 'if_statement', 'children': ['17', '22', '442']},{'id': '17', 'type': 'comparison_operator', 'children': ['18', '19'], 'value': '=='},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'protocol'},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'constants'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'HMV3_ID'},{'id': '22', 'type': 'block', 'children': ['23', '36', '49', '55', '64', '102', '108', '114', '120', '129', '135', '141', '178', '210', '247', '279', '320', '352', '391', '430']},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'checksum'},{'id': '26', 'type': 'subscript', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'datal'},{'id': '28', 'type': 'slice', 'children': ['29', '35']},{'id': '29', 'type': 'binary_operator', 'children': ['30', '34'], 'value': '-'},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'datal'},{'id': '34', 'type': 'integer', 'children': [], 'value': '2'},{'id': '35', 'type': 'colon', 'children': []},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'rxmsg'},{'id': '39', 'type': 'subscript', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'datal'},{'id': '41', 'type': 'slice', 'children': ['42', '43']},{'id': '42', 'type': 'colon', 'children': []},{'id': '43', 'type': 'binary_operator', 'children': ['44', '48'], 'value': '-'},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'datal'},{'id': '48', 'type': 'integer', 'children': [], 'value': '2'},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'crc'},{'id': '52', 'type': 'call', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'CRC16'},{'id': '54', 'type': 'argument_list', 'children': []},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'expectedchecksum'},{'id': '58', 'type': 'call', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'crc'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'run'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'rxmsg'},{'id': '64', 'type': 'if_statement', 'children': ['65', '68', '76']},{'id': '65', 'type': 'comparison_operator', 'children': ['66', '67'], 'value': '=='},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'expectedchecksum'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'checksum'},{'id': '68', 'type': 'block', 'children': ['69']},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'call', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'string', 'children': [], 'value': '"CRC is correct"'},{'id': '76', 'type': 'else_clause', 'children': ['77']},{'id': '77', 'type': 'block', 'children': ['78', '85', '89', '98']},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'call', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'string', 'children': [], 'value': '"CRC is INCORRECT"'},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'assignment', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'serror'},{'id': '88', 'type': 'string', 'children': [], 'value': '"Incorrect CRC"'},{'id': '89', 'type': 'expression_statement', 'children': ['90']},{'id': '90', 'type': 'call', 'children': ['91', '96']},{'id': '91', 'type': 'attribute', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'serror'},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'augmented_assignment', 'children': ['100', '101'], 'value': '+='},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'badresponse'},{'id': '101', 'type': 'integer', 'children': [], 'value': '1'},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'assignment', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'dest_addr'},{'id': '105', 'type': 'subscript', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'datal'},{'id': '107', 'type': 'integer', 'children': [], 'value': '0'},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'assignment', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'frame_len_l'},{'id': '111', 'type': 'subscript', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'datal'},{'id': '113', 'type': 'integer', 'children': [], 'value': '1'},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'assignment', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'frame_len_h'},{'id': '117', 'type': 'subscript', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'datal'},{'id': '119', 'type': 'integer', 'children': [], 'value': '2'},{'id': '120', 'type': 'expression_statement', 'children': ['121']},{'id': '121', 'type': 'assignment', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'frame_len'},{'id': '123', 'type': 'binary_operator', 'children': ['124', '128'], 'value': '|'},{'id': '124', 'type': '()', 'children': ['125']},{'id': '125', 'type': 'binary_operator', 'children': ['126', '127'], 'value': '<<'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'frame_len_h'},{'id': '127', 'type': 'integer', 'children': [], 'value': '8'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'frame_len_l'},{'id': '129', 'type': 'expression_statement', 'children': ['130']},{'id': '130', 'type': 'assignment', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'source_addr'},{'id': '132', 'type': 'subscript', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'datal'},{'id': '134', 'type': 'integer', 'children': [], 'value': '3'},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'assignment', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'func_code'},{'id': '138', 'type': 'subscript', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'datal'},{'id': '140', 'type': 'integer', 'children': [], 'value': '4'},{'id': '141', 'type': 'if_statement', 'children': ['142', '150']},{'id': '142', 'type': '()', 'children': ['143']},{'id': '143', 'type': 'boolean_operator', 'children': ['144', '147'], 'value': 'and'},{'id': '144', 'type': 'comparison_operator', 'children': ['145', '146'], 'value': '!='},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'dest_addr'},{'id': '146', 'type': 'integer', 'children': [], 'value': '129'},{'id': '147', 'type': 'comparison_operator', 'children': ['148', '149'], 'value': '!='},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'dest_addr'},{'id': '149', 'type': 'integer', 'children': [], 'value': '160'},{'id': '150', 'type': 'block', 'children': ['151', '158', '165', '174']},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'call', 'children': ['153', '156']},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '156', 'type': 'argument_list', 'children': ['157']},{'id': '157', 'type': 'string', 'children': [], 'value': '"dest_addr is ILLEGAL"'},{'id': '158', 'type': 'expression_statement', 'children': ['159']},{'id': '159', 'type': 'assignment', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'serror'},{'id': '161', 'type': 'binary_operator', 'children': ['162', '163'], 'value': '%'},{'id': '162', 'type': 'string', 'children': [], 'value': '"Illegal Dest Addr: %s\\n"'},{'id': '163', 'type': '()', 'children': ['164']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'dest_addr'},{'id': '165', 'type': 'expression_statement', 'children': ['166']},{'id': '166', 'type': 'call', 'children': ['167', '172']},{'id': '167', 'type': 'attribute', 'children': ['168', '171']},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '172', 'type': 'argument_list', 'children': ['173']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'serror'},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'id': '175', 'type': 'augmented_assignment', 'children': ['176', '177'], 'value': '+='},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'badresponse'},{'id': '177', 'type': 'integer', 'children': [], 'value': '1'},{'id': '178', 'type': 'if_statement', 'children': ['179', '182']},{'id': '179', 'type': 'comparison_operator', 'children': ['180', '181'], 'value': '!='},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'dest_addr'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'thermostat_id'},{'id': '182', 'type': 'block', 'children': ['183', '190', '197', '206']},{'id': '183', 'type': 'expression_statement', 'children': ['184']},{'id': '184', 'type': 'call', 'children': ['185', '188']},{'id': '185', 'type': 'attribute', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '188', 'type': 'argument_list', 'children': ['189']},{'id': '189', 'type': 'string', 'children': [], 'value': '"dest_addr is INCORRECT"'},{'id': '190', 'type': 'expression_statement', 'children': ['191']},{'id': '191', 'type': 'assignment', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'serror'},{'id': '193', 'type': 'binary_operator', 'children': ['194', '195'], 'value': '%'},{'id': '194', 'type': 'string', 'children': [], 'value': '"Incorrect Dest Addr: %s\\n"'},{'id': '195', 'type': '()', 'children': ['196']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'dest_addr'},{'id': '197', 'type': 'expression_statement', 'children': ['198']},{'id': '198', 'type': 'call', 'children': ['199', '204']},{'id': '199', 'type': 'attribute', 'children': ['200', '203']},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '204', 'type': 'argument_list', 'children': ['205']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'serror'},{'id': '206', 'type': 'expression_statement', 'children': ['207']},{'id': '207', 'type': 'augmented_assignment', 'children': ['208', '209'], 'value': '+='},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'badresponse'},{'id': '209', 'type': 'integer', 'children': [], 'value': '1'},{'id': '210', 'type': 'if_statement', 'children': ['211', '219']},{'id': '211', 'type': '()', 'children': ['212']},{'id': '212', 'type': 'boolean_operator', 'children': ['213', '216'], 'value': 'or'},{'id': '213', 'type': 'comparison_operator', 'children': ['214', '215'], 'value': '<'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'source_addr'},{'id': '215', 'type': 'integer', 'children': [], 'value': '1'},{'id': '216', 'type': 'comparison_operator', 'children': ['217', '218'], 'value': '>'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'source_addr'},{'id': '218', 'type': 'integer', 'children': [], 'value': '32'},{'id': '219', 'type': 'block', 'children': ['220', '227', '234', '243']},{'id': '220', 'type': 'expression_statement', 'children': ['221']},{'id': '221', 'type': 'call', 'children': ['222', '225']},{'id': '222', 'type': 'attribute', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '225', 'type': 'argument_list', 'children': ['226']},{'id': '226', 'type': 'string', 'children': [], 'value': '"source_addr is ILLEGAL"'},{'id': '227', 'type': 'expression_statement', 'children': ['228']},{'id': '228', 'type': 'assignment', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'serror'},{'id': '230', 'type': 'binary_operator', 'children': ['231', '232'], 'value': '%'},{'id': '231', 'type': 'string', 'children': [], 'value': '"Illegal Src Addr: %s\\n"'},{'id': '232', 'type': '()', 'children': ['233']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'source_addr'},{'id': '234', 'type': 'expression_statement', 'children': ['235']},{'id': '235', 'type': 'call', 'children': ['236', '241']},{'id': '236', 'type': 'attribute', 'children': ['237', '240']},{'id': '237', 'type': 'attribute', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '241', 'type': 'argument_list', 'children': ['242']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'serror'},{'id': '243', 'type': 'expression_statement', 'children': ['244']},{'id': '244', 'type': 'augmented_assignment', 'children': ['245', '246'], 'value': '+='},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'badresponse'},{'id': '246', 'type': 'integer', 'children': [], 'value': '1'},{'id': '247', 'type': 'if_statement', 'children': ['248', '251']},{'id': '248', 'type': 'comparison_operator', 'children': ['249', '250'], 'value': '!='},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'source_addr'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '251', 'type': 'block', 'children': ['252', '259', '266', '275']},{'id': '252', 'type': 'expression_statement', 'children': ['253']},{'id': '253', 'type': 'call', 'children': ['254', '257']},{'id': '254', 'type': 'attribute', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '257', 'type': 'argument_list', 'children': ['258']},{'id': '258', 'type': 'string', 'children': [], 'value': '"source addr is INCORRECT"'},{'id': '259', 'type': 'expression_statement', 'children': ['260']},{'id': '260', 'type': 'assignment', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'serror'},{'id': '262', 'type': 'binary_operator', 'children': ['263', '264'], 'value': '%'},{'id': '263', 'type': 'string', 'children': [], 'value': '"Incorrect Src Addr: %s\\n"'},{'id': '264', 'type': '()', 'children': ['265']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'source_addr'},{'id': '266', 'type': 'expression_statement', 'children': ['267']},{'id': '267', 'type': 'call', 'children': ['268', '273']},{'id': '268', 'type': 'attribute', 'children': ['269', '272']},{'id': '269', 'type': 'attribute', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '273', 'type': 'argument_list', 'children': ['274']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'serror'},{'id': '275', 'type': 'expression_statement', 'children': ['276']},{'id': '276', 'type': 'augmented_assignment', 'children': ['277', '278'], 'value': '+='},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'badresponse'},{'id': '278', 'type': 'integer', 'children': [], 'value': '1'},{'id': '279', 'type': 'if_statement', 'children': ['280', '292']},{'id': '280', 'type': '()', 'children': ['281']},{'id': '281', 'type': 'boolean_operator', 'children': ['282', '287'], 'value': 'and'},{'id': '282', 'type': 'comparison_operator', 'children': ['283', '284'], 'value': '!='},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'func_code'},{'id': '284', 'type': 'attribute', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'constants'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'FUNC_WRITE'},{'id': '287', 'type': 'comparison_operator', 'children': ['288', '289'], 'value': '!='},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'func_code'},{'id': '289', 'type': 'attribute', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'constants'},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'FUNC_READ'},{'id': '292', 'type': 'block', 'children': ['293', '300', '307', '316']},{'id': '293', 'type': 'expression_statement', 'children': ['294']},{'id': '294', 'type': 'call', 'children': ['295', '298']},{'id': '295', 'type': 'attribute', 'children': ['296', '297']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '298', 'type': 'argument_list', 'children': ['299']},{'id': '299', 'type': 'string', 'children': [], 'value': '"Func Code is UNKNWON"'},{'id': '300', 'type': 'expression_statement', 'children': ['301']},{'id': '301', 'type': 'assignment', 'children': ['302', '303']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'serror'},{'id': '303', 'type': 'binary_operator', 'children': ['304', '305'], 'value': '%'},{'id': '304', 'type': 'string', 'children': [], 'value': '"Unknown Func Code: %s\\n"'},{'id': '305', 'type': '()', 'children': ['306']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'func_code'},{'id': '307', 'type': 'expression_statement', 'children': ['308']},{'id': '308', 'type': 'call', 'children': ['309', '314']},{'id': '309', 'type': 'attribute', 'children': ['310', '313']},{'id': '310', 'type': 'attribute', 'children': ['311', '312']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '314', 'type': 'argument_list', 'children': ['315']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'serror'},{'id': '316', 'type': 'expression_statement', 'children': ['317']},{'id': '317', 'type': 'augmented_assignment', 'children': ['318', '319'], 'value': '+='},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'badresponse'},{'id': '319', 'type': 'integer', 'children': [], 'value': '1'},{'id': '320', 'type': 'if_statement', 'children': ['321', '324']},{'id': '321', 'type': 'comparison_operator', 'children': ['322', '323'], 'value': '!='},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'func_code'},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'expectedFunction'},{'id': '324', 'type': 'block', 'children': ['325', '332', '339', '348']},{'id': '325', 'type': 'expression_statement', 'children': ['326']},{'id': '326', 'type': 'call', 'children': ['327', '330']},{'id': '327', 'type': 'attribute', 'children': ['328', '329']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '330', 'type': 'argument_list', 'children': ['331']},{'id': '331', 'type': 'string', 'children': [], 'value': '"Func Code is UNEXPECTED"'},{'id': '332', 'type': 'expression_statement', 'children': ['333']},{'id': '333', 'type': 'assignment', 'children': ['334', '335']},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'serror'},{'id': '335', 'type': 'binary_operator', 'children': ['336', '337'], 'value': '%'},{'id': '336', 'type': 'string', 'children': [], 'value': '"Unexpected Func Code: %s\\n"'},{'id': '337', 'type': '()', 'children': ['338']},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'func_code'},{'id': '339', 'type': 'expression_statement', 'children': ['340']},{'id': '340', 'type': 'call', 'children': ['341', '346']},{'id': '341', 'type': 'attribute', 'children': ['342', '345']},{'id': '342', 'type': 'attribute', 'children': ['343', '344']},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '346', 'type': 'argument_list', 'children': ['347']},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'serror'},{'id': '348', 'type': 'expression_statement', 'children': ['349']},{'id': '349', 'type': 'augmented_assignment', 'children': ['350', '351'], 'value': '+='},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'badresponse'},{'id': '351', 'type': 'integer', 'children': [], 'value': '1'},{'id': '352', 'type': 'if_statement', 'children': ['353', '363']},{'id': '353', 'type': '()', 'children': ['354']},{'id': '354', 'type': 'boolean_operator', 'children': ['355', '360'], 'value': 'and'},{'id': '355', 'type': 'comparison_operator', 'children': ['356', '357'], 'value': '=='},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'func_code'},{'id': '357', 'type': 'attribute', 'children': ['358', '359']},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'constants'},{'id': '359', 'type': 'identifier', 'children': [], 'value': 'FUNC_WRITE'},{'id': '360', 'type': 'comparison_operator', 'children': ['361', '362'], 'value': '!='},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'frame_len'},{'id': '362', 'type': 'integer', 'children': [], 'value': '7'},{'id': '363', 'type': 'block', 'children': ['364', '371', '378', '387']},{'id': '364', 'type': 'expression_statement', 'children': ['365']},{'id': '365', 'type': 'call', 'children': ['366', '369']},{'id': '366', 'type': 'attribute', 'children': ['367', '368']},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '369', 'type': 'argument_list', 'children': ['370']},{'id': '370', 'type': 'string', 'children': [], 'value': '"response length is INCORRECT"'},{'id': '371', 'type': 'expression_statement', 'children': ['372']},{'id': '372', 'type': 'assignment', 'children': ['373', '374']},{'id': '373', 'type': 'identifier', 'children': [], 'value': 'serror'},{'id': '374', 'type': 'binary_operator', 'children': ['375', '376'], 'value': '%'},{'id': '375', 'type': 'string', 'children': [], 'value': '"Incorrect length: %s\\n"'},{'id': '376', 'type': '()', 'children': ['377']},{'id': '377', 'type': 'identifier', 'children': [], 'value': 'frame_len'},{'id': '378', 'type': 'expression_statement', 'children': ['379']},{'id': '379', 'type': 'call', 'children': ['380', '385']},{'id': '380', 'type': 'attribute', 'children': ['381', '384']},{'id': '381', 'type': 'attribute', 'children': ['382', '383']},{'id': '382', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '383', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '384', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '385', 'type': 'argument_list', 'children': ['386']},{'id': '386', 'type': 'identifier', 'children': [], 'value': 'serror'},{'id': '387', 'type': 'expression_statement', 'children': ['388']},{'id': '388', 'type': 'augmented_assignment', 'children': ['389', '390'], 'value': '+='},{'id': '389', 'type': 'identifier', 'children': [], 'value': 'badresponse'},{'id': '390', 'type': 'integer', 'children': [], 'value': '1'},{'id': '391', 'type': 'if_statement', 'children': ['392', '398']},{'id': '392', 'type': 'comparison_operator', 'children': ['393', '397'], 'value': '!='},{'id': '393', 'type': 'call', 'children': ['394', '395']},{'id': '394', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '395', 'type': 'argument_list', 'children': ['396']},{'id': '396', 'type': 'identifier', 'children': [], 'value': 'datal'},{'id': '397', 'type': 'identifier', 'children': [], 'value': 'frame_len'},{'id': '398', 'type': 'block', 'children': ['399', '406', '417', '426']},{'id': '399', 'type': 'expression_statement', 'children': ['400']},{'id': '400', 'type': 'call', 'children': ['401', '404']},{'id': '401', 'type': 'attribute', 'children': ['402', '403']},{'id': '402', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '403', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '404', 'type': 'argument_list', 'children': ['405']},{'id': '405', 'type': 'string', 'children': [], 'value': '"response length MISMATCHES header"'},{'id': '406', 'type': 'expression_statement', 'children': ['407']},{'id': '407', 'type': 'assignment', 'children': ['408', '409']},{'id': '408', 'type': 'identifier', 'children': [], 'value': 'serror'},{'id': '409', 'type': 'binary_operator', 'children': ['410', '411'], 'value': '%'},{'id': '410', 'type': 'string', 'children': [], 'value': '"Mismatch length: %s %s\\n"'},{'id': '411', 'type': 'tuple', 'children': ['412', '416']},{'id': '412', 'type': 'call', 'children': ['413', '414']},{'id': '413', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '414', 'type': 'argument_list', 'children': ['415']},{'id': '415', 'type': 'identifier', 'children': [], 'value': 'datal'},{'id': '416', 'type': 'identifier', 'children': [], 'value': 'frame_len'},{'id': '417', 'type': 'expression_statement', 'children': ['418']},{'id': '418', 'type': 'call', 'children': ['419', '424']},{'id': '419', 'type': 'attribute', 'children': ['420', '423']},{'id': '420', 'type': 'attribute', 'children': ['421', '422']},{'id': '421', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '422', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '423', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '424', 'type': 'argument_list', 'children': ['425']},{'id': '425', 'type': 'identifier', 'children': [], 'value': 'serror'},{'id': '426', 'type': 'expression_statement', 'children': ['427']},{'id': '427', 'type': 'augmented_assignment', 'children': ['428', '429'], 'value': '+='},{'id': '428', 'type': 'identifier', 'children': [], 'value': 'badresponse'},{'id': '429', 'type': 'integer', 'children': [], 'value': '1'},{'id': '430', 'type': 'if_statement', 'children': ['431', '435', '438']},{'id': '431', 'type': '()', 'children': ['432']},{'id': '432', 'type': 'comparison_operator', 'children': ['433', '434'], 'value': '=='},{'id': '433', 'type': 'identifier', 'children': [], 'value': 'badresponse'},{'id': '434', 'type': 'integer', 'children': [], 'value': '0'},{'id': '435', 'type': 'block', 'children': ['436']},{'id': '436', 'type': 'return_statement', 'children': ['437']},{'id': '437', 'type': 'True', 'children': []},{'id': '438', 'type': 'else_clause', 'children': ['439']},{'id': '439', 'type': 'block', 'children': ['440']},{'id': '440', 'type': 'return_statement', 'children': ['441']},{'id': '441', 'type': 'False', 'children': []},{'id': '442', 'type': 'else_clause', 'children': ['443']},{'id': '443', 'type': 'block', 'children': ['444']},{'id': '444', 'type': 'assert_statement', 'children': ['445', '446']},{'id': '445', 'type': 'integer', 'children': [], 'value': '0'},{'id': '446', 'type': 'binary_operator', 'children': ['447', '448'], 'value': '%'},{'id': '447', 'type': 'string', 'children': [], 'value': '"Un-supported protocol found %s"'},{'id': '448', 'type': 'identifier', 'children': [], 'value': 'protocol'}
def _hm_verify_message_crc_uk( self, thermostat_id, protocol, source, expectedFunction, expectedLength, datal ): badresponse = 0 if protocol == constants.HMV3_ID: checksum = datal[len(datal) - 2:] rxmsg = datal[:len(datal) - 2] crc = CRC16() 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 ): 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 (badresponse == 0): return True else: return False else: assert 0, "Un-supported protocol found %s" % protocol
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '19']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'checks'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13', '16']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'service'},{'id': '6', 'type': 'keyword_separator', 'children': []},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'dc'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'near'},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'default_parameter', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'watch'},{'id': '15', 'type': 'None', 'children': []},{'id': '16', 'type': 'default_parameter', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'consistency'},{'id': '18', 'type': 'None', 'children': []},{'id': '19', 'type': 'block', 'children': ['20', '32', '42', '64']},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'service_id'},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'extract_attr'},{'id': '25', 'type': 'argument_list', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'service'},{'id': '27', 'type': 'keyword_argument', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '29', 'type': 'list', 'children': ['30', '31'], 'value': '["ServiceID", "ID"]'},{'id': '30', 'type': 'string', 'children': [], 'value': '"ServiceID"'},{'id': '31', 'type': 'string', 'children': [], 'value': '"ID"'},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '35', 'type': 'dictionary', 'children': ['36', '39']},{'id': '36', 'type': 'pair', 'children': ['37', '38']},{'id': '37', 'type': 'string', 'children': [], 'value': '"dc"'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'dc'},{'id': '39', 'type': 'pair', 'children': ['40', '41']},{'id': '40', 'type': 'string', 'children': [], 'value': '"near"'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'near'},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '45', 'type': 'await', 'children': ['46']},{'id': '46', 'type': 'call', 'children': ['47', '52']},{'id': '47', 'type': 'attribute', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '50', 'type': 'identifier', 'children': [], 'value': '_api'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '52', 'type': 'argument_list', 'children': ['53', '54', '55', '58', '61']},{'id': '53', 'type': 'string', 'children': [], 'value': '"/v1/health/checks"'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'service_id'},{'id': '55', 'type': 'keyword_argument', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '58', 'type': 'keyword_argument', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'watch'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'watch'},{'id': '61', 'type': 'keyword_argument', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'consistency'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'consistency'},{'id': '64', 'type': 'return_statement', 'children': ['65']},{'id': '65', 'type': 'call', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'consul'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'response'}
async def checks(self, service, *, dc=None, near=None, watch=None, consistency=None): 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)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cap'},{'id': '5', 'type': 'list_splat_pattern', 'children': ['6']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '7', 'type': 'dictionary_splat_pattern', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '9', 'type': 'block', 'children': ['10', '19', '37', '53', '62', '129']},{'id': '10', 'type': 'if_statement', 'children': ['11', '16']},{'id': '11', 'type': 'comparison_operator', 'children': ['12', '13'], 'value': 'in'},{'id': '12', 'type': 'string', 'children': [], 'value': "'READTHEDOCS'"},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'environ'},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'return_statement', 'children': ['18']},{'id': '18', 'type': 'string', 'children': [], 'value': "''"},{'id': '19', 'type': 'if_statement', 'children': ['20', '23']},{'id': '20', 'type': 'comparison_operator', 'children': ['21', '22'], 'value': '!='},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '22', 'type': 'dictionary', 'children': []},{'id': '23', 'type': 'block', 'children': ['24']},{'id': '24', 'type': 'raise_statement', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'binary_operator', 'children': ['29', '30'], 'value': '%'},{'id': '29', 'type': 'string', 'children': [], 'value': '"get(): No such argument %r"'},{'id': '30', 'type': 'subscript', 'children': ['31', '36']},{'id': '31', 'type': 'call', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'popitem'},{'id': '35', 'type': 'argument_list', 'children': []},{'id': '36', 'type': 'integer', 'children': [], 'value': '0'},{'id': '37', 'type': 'if_statement', 'children': ['38', '41']},{'id': '38', 'type': 'comparison_operator', 'children': ['39', '40'], 'value': '=='},{'id': '39', 'type': 'identifier', 'children': [], 'value': '_cache'},{'id': '40', 'type': 'dictionary', 'children': []},{'id': '41', 'type': 'block', 'children': ['42']},{'id': '42', 'type': 'try_statement', 'children': ['43', '50']},{'id': '43', 'type': 'block', 'children': ['44']},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'call', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'curses'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'setupterm'},{'id': '49', 'type': 'argument_list', 'children': []},{'id': '50', 'type': 'except_clause', 'children': ['51']},{'id': '51', 'type': 'block', 'children': ['52']},{'id': '52', 'type': 'pass_statement', 'children': []},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '56', 'type': 'call', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': '_cache'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'cap'},{'id': '62', 'type': 'if_statement', 'children': ['63', '65']},{'id': '63', 'type': 'not_operator', 'children': ['64']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '65', 'type': 'block', 'children': ['66', '75', '123']},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'assignment', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '69', 'type': 'call', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'curses'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'tigetstr'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'cap'},{'id': '75', 'type': 'if_statement', 'children': ['76', '79']},{'id': '76', 'type': 'comparison_operator', 'children': ['77', '78'], 'value': '=='},{'id': '77', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '78', 'type': 'None', 'children': []},{'id': '79', 'type': 'block', 'children': ['80', '89']},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '83', 'type': 'call', 'children': ['84', '87']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'curses'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'tigetnum'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'cap'},{'id': '89', 'type': 'if_statement', 'children': ['90', '94']},{'id': '90', 'type': 'comparison_operator', 'children': ['91', '92'], 'value': '=='},{'id': '91', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '92', 'type': 'unary_operator', 'children': ['93'], 'value': '-'},{'id': '93', 'type': 'integer', 'children': [], 'value': '2'},{'id': '94', 'type': 'block', 'children': ['95', '104']},{'id': '95', 'type': 'expression_statement', 'children': ['96']},{'id': '96', 'type': 'assignment', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '98', 'type': 'call', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'curses'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'tigetflag'},{'id': '102', 'type': 'argument_list', 'children': ['103']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'cap'},{'id': '104', 'type': 'if_statement', 'children': ['105', '109', '114']},{'id': '105', 'type': 'comparison_operator', 'children': ['106', '107'], 'value': '=='},{'id': '106', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '107', 'type': 'unary_operator', 'children': ['108'], 'value': '-'},{'id': '108', 'type': 'integer', 'children': [], 'value': '1'},{'id': '109', 'type': 'block', 'children': ['110']},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'assignment', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '113', 'type': 'string', 'children': [], 'value': "''"},{'id': '114', 'type': 'else_clause', 'children': ['115']},{'id': '115', 'type': 'block', 'children': ['116']},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'assignment', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '119', 'type': 'call', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'bool'},{'id': '121', 'type': 'argument_list', 'children': ['122']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '123', 'type': 'expression_statement', 'children': ['124']},{'id': '124', 'type': 'assignment', 'children': ['125', '128']},{'id': '125', 'type': 'subscript', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': '_cache'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'cap'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '129', 'type': 'if_statement', 'children': ['130', '133', '152']},{'id': '130', 'type': 'boolean_operator', 'children': ['131', '132'], 'value': 'and'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '133', 'type': 'block', 'children': ['134', '145']},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'assignment', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '137', 'type': 'call', 'children': ['138', '141']},{'id': '138', 'type': 'attribute', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'curses'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'tparm'},{'id': '141', 'type': 'argument_list', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '143', 'type': 'list_splat', 'children': ['144']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '145', 'type': 'return_statement', 'children': ['146']},{'id': '146', 'type': 'call', 'children': ['147', '150']},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'decode'},{'id': '150', 'type': 'argument_list', 'children': ['151']},{'id': '151', 'type': 'string', 'children': [], 'value': "'utf-8'"},{'id': '152', 'type': 'else_clause', 'children': ['153']},{'id': '153', 'type': 'block', 'children': ['154']},{'id': '154', 'type': 'if_statement', 'children': ['155', '160', '168']},{'id': '155', 'type': 'call', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '157', 'type': 'argument_list', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'bytes'},{'id': '160', 'type': 'block', 'children': ['161']},{'id': '161', 'type': 'return_statement', 'children': ['162']},{'id': '162', 'type': 'call', 'children': ['163', '166']},{'id': '163', 'type': 'attribute', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'decode'},{'id': '166', 'type': 'argument_list', 'children': ['167']},{'id': '167', 'type': 'string', 'children': [], 'value': "'utf-8'"},{'id': '168', 'type': 'else_clause', 'children': ['169']},{'id': '169', 'type': 'block', 'children': ['170']},{'id': '170', 'type': 'return_statement', 'children': ['171']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 's'}
def get(cap, *args, **kwargs): if 'READTHEDOCS' in os.environ: return '' if kwargs != {}: raise TypeError("get(): No such argument %r" % kwargs.popitem()[0]) if _cache == {}: 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: s = '' else: s = bool(s) _cache[cap] = s 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
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'draw'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'canvas'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '6', 'type': 'block', 'children': ['7', '14', '22', '31', '71', '233']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'call', 'children': ['9', '12']},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'require'},{'id': '12', 'type': 'argument_list', 'children': ['13']},{'id': '13', 'type': 'string', 'children': [], 'value': '"ScaleAndCenter"'},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'mlb'},{'id': '17', 'type': 'subscript', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'size2d'},{'id': '21', 'type': 'integer', 'children': [], 'value': '2'},{'id': '22', 'type': 'if_statement', 'children': ['23', '29']},{'id': '23', 'type': 'not_operator', 'children': ['24']},{'id': '24', 'type': 'call', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'atom_count'},{'id': '28', 'type': 'argument_list', 'children': []},{'id': '29', 'type': 'block', 'children': ['30']},{'id': '30', 'type': 'return_statement', 'children': []},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'bond_type_fn'},{'id': '34', 'type': 'dictionary', 'children': ['35', '50', '65']},{'id': '35', 'type': 'pair', 'children': ['36', '37']},{'id': '36', 'type': 'integer', 'children': [], 'value': '1'},{'id': '37', 'type': 'dictionary', 'children': ['38', '41', '44', '47']},{'id': '38', 'type': 'pair', 'children': ['39', '40']},{'id': '39', 'type': 'integer', 'children': [], 'value': '0'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'single_bond'},{'id': '41', 'type': 'pair', 'children': ['42', '43']},{'id': '42', 'type': 'integer', 'children': [], 'value': '1'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'wedged_single'},{'id': '44', 'type': 'pair', 'children': ['45', '46']},{'id': '45', 'type': 'integer', 'children': [], 'value': '2'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'dashed_wedged_single'},{'id': '47', 'type': 'pair', 'children': ['48', '49']},{'id': '48', 'type': 'integer', 'children': [], 'value': '3'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'wave_single'},{'id': '50', 'type': 'pair', 'children': ['51', '52']},{'id': '51', 'type': 'integer', 'children': [], 'value': '2'},{'id': '52', 'type': 'dictionary', 'children': ['53', '56', '59', '62']},{'id': '53', 'type': 'pair', 'children': ['54', '55']},{'id': '54', 'type': 'integer', 'children': [], 'value': '0'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'cw_double'},{'id': '56', 'type': 'pair', 'children': ['57', '58']},{'id': '57', 'type': 'integer', 'children': [], 'value': '1'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'counter_cw_double'},{'id': '59', 'type': 'pair', 'children': ['60', '61']},{'id': '60', 'type': 'integer', 'children': [], 'value': '2'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'double_bond'},{'id': '62', 'type': 'pair', 'children': ['63', '64']},{'id': '63', 'type': 'integer', 'children': [], 'value': '3'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'cross_double'},{'id': '65', 'type': 'pair', 'children': ['66', '67']},{'id': '66', 'type': 'integer', 'children': [], 'value': '3'},{'id': '67', 'type': 'dictionary', 'children': ['68']},{'id': '68', 'type': 'pair', 'children': ['69', '70']},{'id': '69', 'type': 'integer', 'children': [], 'value': '0'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'triple_bond'},{'id': '71', 'type': 'for_statement', 'children': ['72', '76', '81']},{'id': '72', 'type': 'pattern_list', 'children': ['73', '74', '75']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'bond'},{'id': '76', 'type': 'call', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'bonds_iter'},{'id': '80', 'type': 'argument_list', 'children': []},{'id': '81', 'type': 'block', 'children': ['82', '89', '117', '128', '139', '145', '169', '193', '204', '215']},{'id': '82', 'type': 'if_statement', 'children': ['83', '87']},{'id': '83', 'type': 'not_operator', 'children': ['84']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'bond'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'visible'},{'id': '87', 'type': 'block', 'children': ['88']},{'id': '88', 'type': 'continue_statement', 'children': []},{'id': '89', 'type': 'if_statement', 'children': ['90', '98', '107']},{'id': '90', 'type': 'comparison_operator', 'children': ['91', '95'], 'value': '=='},{'id': '91', 'type': '()', 'children': ['92']},{'id': '92', 'type': 'comparison_operator', 'children': ['93', '94'], 'value': '<'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'bond'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'is_lower_first'},{'id': '98', 'type': 'block', 'children': ['99']},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'assignment', 'children': ['101', '104']},{'id': '101', 'type': 'pattern_list', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '104', 'type': 'tuple', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '107', 'type': 'else_clause', 'children': ['108']},{'id': '108', 'type': 'block', 'children': ['109']},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '114']},{'id': '111', 'type': 'pattern_list', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '114', 'type': 'tuple', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'p1'},{'id': '120', 'type': 'attribute', 'children': ['121', '127']},{'id': '121', 'type': 'call', 'children': ['122', '125']},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '125', 'type': 'argument_list', 'children': ['126']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'coords'},{'id': '128', 'type': 'expression_statement', 'children': ['129']},{'id': '129', 'type': 'assignment', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'p2'},{'id': '131', 'type': 'attribute', 'children': ['132', '138']},{'id': '132', 'type': 'call', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'coords'},{'id': '139', 'type': 'if_statement', 'children': ['140', '143']},{'id': '140', 'type': 'comparison_operator', 'children': ['141', '142'], 'value': '=='},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'p1'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'p2'},{'id': '143', 'type': 'block', 'children': ['144']},{'id': '144', 'type': 'continue_statement', 'children': []},{'id': '145', 'type': 'if_statement', 'children': ['146', '154']},{'id': '146', 'type': 'attribute', 'children': ['147', '153']},{'id': '147', 'type': 'call', 'children': ['148', '151']},{'id': '148', 'type': 'attribute', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '151', 'type': 'argument_list', 'children': ['152']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'visible'},{'id': '154', 'type': 'block', 'children': ['155']},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'assignment', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'p1'},{'id': '158', 'type': 'subscript', 'children': ['159', '168']},{'id': '159', 'type': 'call', 'children': ['160', '163']},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'gm'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 't_seg'},{'id': '163', 'type': 'argument_list', 'children': ['164', '165', '166', '167']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'p1'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'p2'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'F_AOVL'},{'id': '167', 'type': 'integer', 'children': [], 'value': '2'},{'id': '168', 'type': 'integer', 'children': [], 'value': '0'},{'id': '169', 'type': 'if_statement', 'children': ['170', '178']},{'id': '170', 'type': 'attribute', 'children': ['171', '177']},{'id': '171', 'type': 'call', 'children': ['172', '175']},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '175', 'type': 'argument_list', 'children': ['176']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'visible'},{'id': '178', 'type': 'block', 'children': ['179']},{'id': '179', 'type': 'expression_statement', 'children': ['180']},{'id': '180', 'type': 'assignment', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'p2'},{'id': '182', 'type': 'subscript', 'children': ['183', '192']},{'id': '183', 'type': 'call', 'children': ['184', '187']},{'id': '184', 'type': 'attribute', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'gm'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 't_seg'},{'id': '187', 'type': 'argument_list', 'children': ['188', '189', '190', '191']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'p1'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'p2'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'F_AOVL'},{'id': '191', 'type': 'integer', 'children': [], 'value': '1'},{'id': '192', 'type': 'integer', 'children': [], 'value': '1'},{'id': '193', 'type': 'expression_statement', 'children': ['194']},{'id': '194', 'type': 'assignment', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'color1'},{'id': '196', 'type': 'attribute', 'children': ['197', '203']},{'id': '197', 'type': 'call', 'children': ['198', '201']},{'id': '198', 'type': 'attribute', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '201', 'type': 'argument_list', 'children': ['202']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'color'},{'id': '204', 'type': 'expression_statement', 'children': ['205']},{'id': '205', 'type': 'assignment', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'color2'},{'id': '207', 'type': 'attribute', 'children': ['208', '214']},{'id': '208', 'type': 'call', 'children': ['209', '212']},{'id': '209', 'type': 'attribute', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '212', 'type': 'argument_list', 'children': ['213']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'color'},{'id': '215', 'type': 'expression_statement', 'children': ['216']},{'id': '216', 'type': 'call', 'children': ['217', '226']},{'id': '217', 'type': 'subscript', 'children': ['218', '223']},{'id': '218', 'type': 'subscript', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'bond_type_fn'},{'id': '220', 'type': 'attribute', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'bond'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '223', 'type': 'attribute', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'bond'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '226', 'type': 'argument_list', 'children': ['227', '228', '229', '230', '231', '232']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'canvas'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'p1'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'p2'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'color1'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'color2'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'mlb'},{'id': '233', 'type': 'for_statement', 'children': ['234', '237', '242']},{'id': '234', 'type': 'pattern_list', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '237', 'type': 'call', 'children': ['238', '241']},{'id': '238', 'type': 'attribute', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'atoms_iter'},{'id': '241', 'type': 'argument_list', 'children': []},{'id': '242', 'type': 'block', 'children': ['243', '250', '256', '262', '391', '399']},{'id': '243', 'type': 'if_statement', 'children': ['244', '248']},{'id': '244', 'type': 'not_operator', 'children': ['245']},{'id': '245', 'type': 'attribute', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'visible'},{'id': '248', 'type': 'block', 'children': ['249']},{'id': '249', 'type': 'continue_statement', 'children': []},{'id': '250', 'type': 'expression_statement', 'children': ['251']},{'id': '251', 'type': 'assignment', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '253', 'type': 'attribute', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'coords'},{'id': '256', 'type': 'expression_statement', 'children': ['257']},{'id': '257', 'type': 'assignment', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'color'},{'id': '259', 'type': 'attribute', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'color'},{'id': '262', 'type': 'if_statement', 'children': ['263', '266']},{'id': '263', 'type': 'attribute', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'H_count'},{'id': '266', 'type': 'block', 'children': ['267', '271', '283', '333']},{'id': '267', 'type': 'expression_statement', 'children': ['268']},{'id': '268', 'type': 'assignment', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'cosnbrs'},{'id': '270', 'type': 'list', 'children': [], 'value': '[]'},{'id': '271', 'type': 'expression_statement', 'children': ['272']},{'id': '272', 'type': 'assignment', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'hrzn'},{'id': '274', 'type': 'tuple', 'children': ['275', '280']},{'id': '275', 'type': 'binary_operator', 'children': ['276', '279'], 'value': '+'},{'id': '276', 'type': 'subscript', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '278', 'type': 'integer', 'children': [], 'value': '0'},{'id': '279', 'type': 'integer', 'children': [], 'value': '1'},{'id': '280', 'type': 'subscript', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '282', 'type': 'integer', 'children': [], 'value': '1'},{'id': '283', 'type': 'for_statement', 'children': ['284', '285', '293']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'nbr'},{'id': '285', 'type': 'call', 'children': ['286', '291']},{'id': '286', 'type': 'attribute', 'children': ['287', '290']},{'id': '287', 'type': 'attribute', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'neighbors'},{'id': '291', 'type': 'argument_list', 'children': ['292']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '293', 'type': 'block', 'children': ['294', '305']},{'id': '294', 'type': 'expression_statement', 'children': ['295']},{'id': '295', 'type': 'assignment', 'children': ['296', '297']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'pnbr'},{'id': '297', 'type': 'attribute', 'children': ['298', '304']},{'id': '298', 'type': 'call', 'children': ['299', '302']},{'id': '299', 'type': 'attribute', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '302', 'type': 'argument_list', 'children': ['303']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'nbr'},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'coords'},{'id': '305', 'type': 'try_statement', 'children': ['306', '329']},{'id': '306', 'type': 'block', 'children': ['307']},{'id': '307', 'type': 'expression_statement', 'children': ['308']},{'id': '308', 'type': 'call', 'children': ['309', '312']},{'id': '309', 'type': 'attribute', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'cosnbrs'},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '312', 'type': 'argument_list', 'children': ['313']},{'id': '313', 'type': 'binary_operator', 'children': ['314', '322'], 'value': '/'},{'id': '314', 'type': 'call', 'children': ['315', '318']},{'id': '315', 'type': 'attribute', 'children': ['316', '317']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'gm'},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'dot_product'},{'id': '318', 'type': 'argument_list', 'children': ['319', '320', '321']},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'hrzn'},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'pnbr'},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '322', 'type': 'call', 'children': ['323', '326']},{'id': '323', 'type': 'attribute', 'children': ['324', '325']},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'gm'},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'distance'},{'id': '326', 'type': 'argument_list', 'children': ['327', '328']},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'pnbr'},{'id': '329', 'type': 'except_clause', 'children': ['330', '331']},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'ZeroDivisionError'},{'id': '331', 'type': 'block', 'children': ['332']},{'id': '332', 'type': 'pass_statement', 'children': []},{'id': '333', 'type': 'if_statement', 'children': ['334', '343', '364']},{'id': '334', 'type': 'boolean_operator', 'children': ['335', '337'], 'value': 'or'},{'id': '335', 'type': 'not_operator', 'children': ['336']},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'cosnbrs'},{'id': '337', 'type': 'comparison_operator', 'children': ['338', '342'], 'value': '>'},{'id': '338', 'type': 'call', 'children': ['339', '340']},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '340', 'type': 'argument_list', 'children': ['341']},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'cosnbrs'},{'id': '342', 'type': 'integer', 'children': [], 'value': '0'},{'id': '343', 'type': 'block', 'children': ['344', '353', '363']},{'id': '344', 'type': 'expression_statement', 'children': ['345']},{'id': '345', 'type': 'assignment', 'children': ['346', '347']},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '347', 'type': 'call', 'children': ['348', '351']},{'id': '348', 'type': 'attribute', 'children': ['349', '350']},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'formula_html'},{'id': '351', 'type': 'argument_list', 'children': ['352']},{'id': '352', 'type': 'True', 'children': []},{'id': '353', 'type': 'expression_statement', 'children': ['354']},{'id': '354', 'type': 'call', 'children': ['355', '358']},{'id': '355', 'type': 'attribute', 'children': ['356', '357']},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'canvas'},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'draw_text'},{'id': '358', 'type': 'argument_list', 'children': ['359', '360', '361', '362']},{'id': '359', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'color'},{'id': '362', 'type': 'string', 'children': [], 'value': '"right"'},{'id': '363', 'type': 'continue_statement', 'children': []},{'id': '364', 'type': 'elif_clause', 'children': ['365', '371']},{'id': '365', 'type': 'comparison_operator', 'children': ['366', '370'], 'value': '<'},{'id': '366', 'type': 'call', 'children': ['367', '368']},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '368', 'type': 'argument_list', 'children': ['369']},{'id': '369', 'type': 'identifier', 'children': [], 'value': 'cosnbrs'},{'id': '370', 'type': 'integer', 'children': [], 'value': '0'},{'id': '371', 'type': 'block', 'children': ['372', '380', '390']},{'id': '372', 'type': 'expression_statement', 'children': ['373']},{'id': '373', 'type': 'assignment', 'children': ['374', '375']},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '375', 'type': 'call', 'children': ['376', '379']},{'id': '376', 'type': 'attribute', 'children': ['377', '378']},{'id': '377', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '378', 'type': 'identifier', 'children': [], 'value': 'formula_html'},{'id': '379', 'type': 'argument_list', 'children': []},{'id': '380', 'type': 'expression_statement', 'children': ['381']},{'id': '381', 'type': 'call', 'children': ['382', '385']},{'id': '382', 'type': 'attribute', 'children': ['383', '384']},{'id': '383', 'type': 'identifier', 'children': [], 'value': 'canvas'},{'id': '384', 'type': 'identifier', 'children': [], 'value': 'draw_text'},{'id': '385', 'type': 'argument_list', 'children': ['386', '387', '388', '389']},{'id': '386', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '387', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '388', 'type': 'identifier', 'children': [], 'value': 'color'},{'id': '389', 'type': 'string', 'children': [], 'value': '"left"'},{'id': '390', 'type': 'continue_statement', 'children': []},{'id': '391', 'type': 'expression_statement', 'children': ['392']},{'id': '392', 'type': 'assignment', 'children': ['393', '394']},{'id': '393', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '394', 'type': 'call', 'children': ['395', '398']},{'id': '395', 'type': 'attribute', 'children': ['396', '397']},{'id': '396', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '397', 'type': 'identifier', 'children': [], 'value': 'formula_html'},{'id': '398', 'type': 'argument_list', 'children': []},{'id': '399', 'type': 'expression_statement', 'children': ['400']},{'id': '400', 'type': 'call', 'children': ['401', '404']},{'id': '401', 'type': 'attribute', 'children': ['402', '403']},{'id': '402', 'type': 'identifier', 'children': [], 'value': 'canvas'},{'id': '403', 'type': 'identifier', 'children': [], 'value': 'draw_text'},{'id': '404', 'type': 'argument_list', 'children': ['405', '406', '407', '408']},{'id': '405', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '406', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '407', 'type': 'identifier', 'children': [], 'value': 'color'},{'id': '408', 'type': 'string', 'children': [], 'value': '"center"'}
def draw(canvas, mol): 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 } } 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 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) for n, atom in mol.atoms_iter(): if not atom.visible: continue p = atom.coords color = atom.color 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: text = atom.formula_html(True) canvas.draw_text(p, text, color, "right") continue elif max(cosnbrs) < 0: text = atom.formula_html() canvas.draw_text(p, text, color, "left") continue text = atom.formula_html() canvas.draw_text(p, text, color, "center")
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'salm2map'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'salm'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'lmax'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'Ntheta'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'Nphi'},{'id': '9', 'type': 'block', 'children': ['10', '32', '59', '64', '78', '106', '131', '231']},{'id': '10', 'type': 'if_statement', 'children': ['11', '18']},{'id': '11', 'type': 'boolean_operator', 'children': ['12', '15'], 'value': 'or'},{'id': '12', 'type': 'comparison_operator', 'children': ['13', '14'], 'value': '<'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'Ntheta'},{'id': '14', 'type': 'integer', 'children': [], 'value': '2'},{'id': '15', 'type': 'comparison_operator', 'children': ['16', '17'], 'value': '<'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'Nphi'},{'id': '17', 'type': 'integer', 'children': [], 'value': '1'},{'id': '18', 'type': 'block', 'children': ['19']},{'id': '19', 'type': 'raise_statement', 'children': ['20']},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'binary_operator', 'children': ['24', '31'], 'value': '+'},{'id': '24', 'type': 'call', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'string', 'children': [], 'value': '"Input values of Ntheta={0} and Nphi={1} "'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '28', 'type': 'argument_list', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'Ntheta'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'Nphi'},{'id': '31', 'type': 'string', 'children': [], 'value': '"are not allowed; they must be greater than 1 and 0, respectively."'},{'id': '32', 'type': 'if_statement', 'children': ['33', '36']},{'id': '33', 'type': 'comparison_operator', 'children': ['34', '35'], 'value': '<'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'lmax'},{'id': '35', 'type': 'integer', 'children': [], 'value': '1'},{'id': '36', 'type': 'block', 'children': ['37']},{'id': '37', 'type': 'raise_statement', 'children': ['38']},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'binary_operator', 'children': ['42', '50'], 'value': '+'},{'id': '42', 'type': 'binary_operator', 'children': ['43', '49'], 'value': '+'},{'id': '43', 'type': 'call', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'string', 'children': [], 'value': '"Input value of lmax={0} "'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'lmax'},{'id': '49', 'type': 'string', 'children': [], 'value': '"is not allowed; it must be greater than 0 and should be greater "'},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'string', 'children': [], 'value': '"than |s|={0}."'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'call', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'abs'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '59', 'type': 'import_statement', 'children': ['60']},{'id': '60', 'type': 'aliased_import', 'children': ['61', '63']},{'id': '61', 'type': 'dotted_name', 'children': ['62']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'numpy'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'salm'},{'id': '67', 'type': 'call', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'ascontiguousarray'},{'id': '71', 'type': 'argument_list', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'salm'},{'id': '73', 'type': 'keyword_argument', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'complex128'},{'id': '78', 'type': 'if_statement', 'children': ['79', '90']},{'id': '79', 'type': 'comparison_operator', 'children': ['80', '86'], 'value': '<'},{'id': '80', 'type': 'subscript', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'salm'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '84', 'type': 'unary_operator', 'children': ['85'], 'value': '-'},{'id': '85', 'type': 'integer', 'children': [], 'value': '1'},{'id': '86', 'type': 'call', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'N_lm'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'lmax'},{'id': '90', 'type': 'block', 'children': ['91']},{'id': '91', 'type': 'raise_statement', 'children': ['92']},{'id': '92', 'type': 'call', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'binary_operator', 'children': ['96', '105'], 'value': '+'},{'id': '96', 'type': 'call', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'string', 'children': [], 'value': '"The input `salm` array of shape {0} is too small for the stated `lmax` of {1}. "'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '100', 'type': 'argument_list', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'salm'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'lmax'},{'id': '105', 'type': 'string', 'children': [], 'value': '"Perhaps you forgot to include the (zero) modes with ell<|s|."'},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'assignment', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '109', 'type': 'call', 'children': ['110', '113']},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'empty'},{'id': '113', 'type': 'argument_list', 'children': ['114', '126']},{'id': '114', 'type': 'binary_operator', 'children': ['115', '123'], 'value': '+'},{'id': '115', 'type': 'subscript', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'salm'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '119', 'type': 'slice', 'children': ['120', '121']},{'id': '120', 'type': 'colon', 'children': []},{'id': '121', 'type': 'unary_operator', 'children': ['122'], 'value': '-'},{'id': '122', 'type': 'integer', 'children': [], 'value': '1'},{'id': '123', 'type': 'tuple', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'Ntheta'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'Nphi'},{'id': '126', 'type': 'keyword_argument', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'complex128'},{'id': '131', 'type': 'if_statement', 'children': ['132', '137', '219']},{'id': '132', 'type': 'comparison_operator', 'children': ['133', '136'], 'value': '>'},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'salm'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'ndim'},{'id': '136', 'type': 'integer', 'children': [], 'value': '1'},{'id': '137', 'type': 'block', 'children': ['138', '152', '209']},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'assignment', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '141', 'type': 'call', 'children': ['142', '145']},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'ascontiguousarray'},{'id': '145', 'type': 'argument_list', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '147', 'type': 'keyword_argument', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'intc'},{'id': '152', 'type': 'if_statement', 'children': ['153', '185']},{'id': '153', 'type': 'boolean_operator', 'children': ['154', '163'], 'value': 'or'},{'id': '154', 'type': 'comparison_operator', 'children': ['155', '158'], 'value': '!='},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'ndim'},{'id': '158', 'type': 'binary_operator', 'children': ['159', '162'], 'value': '-'},{'id': '159', 'type': 'attribute', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'salm'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'ndim'},{'id': '162', 'type': 'integer', 'children': [], 'value': '1'},{'id': '163', 'type': 'comparison_operator', 'children': ['164', '172'], 'value': '!='},{'id': '164', 'type': 'call', 'children': ['165', '168']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'product'},{'id': '168', 'type': 'argument_list', 'children': ['169']},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '172', 'type': 'call', 'children': ['173', '176']},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'product'},{'id': '176', 'type': 'argument_list', 'children': ['177']},{'id': '177', 'type': 'subscript', 'children': ['178', '181']},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'salm'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '181', 'type': 'slice', 'children': ['182', '183']},{'id': '182', 'type': 'colon', 'children': []},{'id': '183', 'type': 'unary_operator', 'children': ['184'], 'value': '-'},{'id': '184', 'type': 'integer', 'children': [], 'value': '1'},{'id': '185', 'type': 'block', 'children': ['186']},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'assignment', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '189', 'type': 'binary_operator', 'children': ['190', '191'], 'value': '*'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '191', 'type': 'call', 'children': ['192', '195']},{'id': '192', 'type': 'attribute', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'ones'},{'id': '195', 'type': 'argument_list', 'children': ['196', '204']},{'id': '196', 'type': 'subscript', 'children': ['197', '200']},{'id': '197', 'type': 'attribute', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'salm'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '200', 'type': 'slice', 'children': ['201', '202']},{'id': '201', 'type': 'colon', 'children': []},{'id': '202', 'type': 'unary_operator', 'children': ['203'], 'value': '-'},{'id': '203', 'type': 'integer', 'children': [], 'value': '1'},{'id': '204', 'type': 'keyword_argument', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '206', 'type': 'attribute', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'intc'},{'id': '209', 'type': 'expression_statement', 'children': ['210']},{'id': '210', 'type': 'call', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': '_multi_salm2map'},{'id': '212', 'type': 'argument_list', 'children': ['213', '214', '215', '216', '217', '218']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'salm'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'lmax'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'Ntheta'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'Nphi'},{'id': '219', 'type': 'else_clause', 'children': ['220']},{'id': '220', 'type': 'block', 'children': ['221']},{'id': '221', 'type': 'expression_statement', 'children': ['222']},{'id': '222', 'type': 'call', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': '_salm2map'},{'id': '224', 'type': 'argument_list', 'children': ['225', '226', '227', '228', '229', '230']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'salm'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'lmax'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'Ntheta'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'Nphi'},{'id': '231', 'type': 'return_statement', 'children': ['232']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'map'}
def salm2map(salm, 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
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'map2salm'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'lmax'},{'id': '7', 'type': 'block', 'children': ['8', '13', '27', '54', '150']},{'id': '8', 'type': 'import_statement', 'children': ['9']},{'id': '9', 'type': 'aliased_import', 'children': ['10', '12']},{'id': '10', 'type': 'dotted_name', 'children': ['11']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'numpy'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '16', 'type': 'call', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'ascontiguousarray'},{'id': '20', 'type': 'argument_list', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '22', 'type': 'keyword_argument', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'complex128'},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'salm'},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'empty'},{'id': '34', 'type': 'argument_list', 'children': ['35', '49']},{'id': '35', 'type': 'binary_operator', 'children': ['36', '44'], 'value': '+'},{'id': '36', 'type': 'subscript', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '40', 'type': 'slice', 'children': ['41', '42']},{'id': '41', 'type': 'colon', 'children': []},{'id': '42', 'type': 'unary_operator', 'children': ['43'], 'value': '-'},{'id': '43', 'type': 'integer', 'children': [], 'value': '2'},{'id': '44', 'type': 'tuple', 'children': ['45']},{'id': '45', 'type': 'call', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'N_lm'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'lmax'},{'id': '49', 'type': 'keyword_argument', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'complex128'},{'id': '54', 'type': 'if_statement', 'children': ['55', '60', '140']},{'id': '55', 'type': 'comparison_operator', 'children': ['56', '59'], 'value': '>'},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'ndim'},{'id': '59', 'type': 'integer', 'children': [], 'value': '2'},{'id': '60', 'type': 'block', 'children': ['61', '75', '132']},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '64', 'type': 'call', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'ascontiguousarray'},{'id': '68', 'type': 'argument_list', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '70', 'type': 'keyword_argument', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'intc'},{'id': '75', 'type': 'if_statement', 'children': ['76', '108']},{'id': '76', 'type': 'boolean_operator', 'children': ['77', '86'], 'value': 'or'},{'id': '77', 'type': 'comparison_operator', 'children': ['78', '81'], 'value': '!='},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'ndim'},{'id': '81', 'type': 'binary_operator', 'children': ['82', '85'], 'value': '-'},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'ndim'},{'id': '85', 'type': 'integer', 'children': [], 'value': '2'},{'id': '86', 'type': 'comparison_operator', 'children': ['87', '95'], 'value': '!='},{'id': '87', 'type': 'call', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'product'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '95', 'type': 'call', 'children': ['96', '99']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'product'},{'id': '99', 'type': 'argument_list', 'children': ['100']},{'id': '100', 'type': 'subscript', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '104', 'type': 'slice', 'children': ['105', '106']},{'id': '105', 'type': 'colon', 'children': []},{'id': '106', 'type': 'unary_operator', 'children': ['107'], 'value': '-'},{'id': '107', 'type': 'integer', 'children': [], 'value': '2'},{'id': '108', 'type': 'block', 'children': ['109']},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '112', 'type': 'binary_operator', 'children': ['113', '114'], 'value': '*'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '114', 'type': 'call', 'children': ['115', '118']},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'ones'},{'id': '118', 'type': 'argument_list', 'children': ['119', '127']},{'id': '119', 'type': 'subscript', 'children': ['120', '123']},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '123', 'type': 'slice', 'children': ['124', '125']},{'id': '124', 'type': 'colon', 'children': []},{'id': '125', 'type': 'unary_operator', 'children': ['126'], 'value': '-'},{'id': '126', 'type': 'integer', 'children': [], 'value': '2'},{'id': '127', 'type': 'keyword_argument', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '129', 'type': 'attribute', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'intc'},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'call', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': '_multi_map2salm'},{'id': '135', 'type': 'argument_list', 'children': ['136', '137', '138', '139']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'salm'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'lmax'},{'id': '140', 'type': 'else_clause', 'children': ['141']},{'id': '141', 'type': 'block', 'children': ['142']},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'call', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': '_map2salm'},{'id': '145', 'type': 'argument_list', 'children': ['146', '147', '148', '149']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'salm'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'lmax'},{'id': '150', 'type': 'return_statement', 'children': ['151']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'salm'}
def 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
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '21']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'store_on_error'},{'id': '8', 'type': 'False', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'xpath'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'rate_limit'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'log_hits'},{'id': '17', 'type': 'True', 'children': []},{'id': '18', 'type': 'default_parameter', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'log_misses'},{'id': '20', 'type': 'True', 'children': []},{'id': '21', 'type': 'block', 'children': ['22', '334']},{'id': '22', 'type': 'try_statement', 'children': ['23', '75']},{'id': '23', 'type': 'block', 'children': ['24', '38', '52']},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'cached'},{'id': '27', 'type': 'call', 'children': ['28', '37']},{'id': '28', 'type': 'attribute', 'children': ['29', '36']},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '32', 'type': 'identifier', 'children': [], 'value': '_query'},{'id': '33', 'type': 'argument_list', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'xpath'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'one'},{'id': '37', 'type': 'argument_list', 'children': []},{'id': '38', 'type': 'if_statement', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'log_hits'},{'id': '40', 'type': 'block', 'children': ['41']},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'call', 'children': ['43', '48']},{'id': '43', 'type': 'attribute', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'binary_operator', 'children': ['50', '51'], 'value': '+'},{'id': '50', 'type': 'string', 'children': [], 'value': '"Request cache hit: "'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '52', 'type': 'if_statement', 'children': ['53', '62']},{'id': '53', 'type': 'comparison_operator', 'children': ['54', '57'], 'value': '!='},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'cached'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '57', 'type': 'attribute', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'requests'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'codes'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'ok'},{'id': '62', 'type': 'block', 'children': ['63']},{'id': '63', 'type': 'raise_statement', 'children': ['64']},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'binary_operator', 'children': ['68', '69'], 'value': '+'},{'id': '68', 'type': 'string', 'children': [], 'value': '"Cached request returned an error, code "'},{'id': '69', 'type': 'call', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'cached'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '75', 'type': 'except_clause', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'NoResultFound'},{'id': '77', 'type': 'block', 'children': ['78', '92', '253', '283', '311']},{'id': '78', 'type': 'if_statement', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'log_misses'},{'id': '80', 'type': 'block', 'children': ['81']},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'call', 'children': ['83', '88']},{'id': '83', 'type': 'attribute', 'children': ['84', '87']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'binary_operator', 'children': ['90', '91'], 'value': '+'},{'id': '90', 'type': 'string', 'children': [], 'value': '"Request cache miss: "'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '92', 'type': 'try_statement', 'children': ['93', '234']},{'id': '93', 'type': 'block', 'children': ['94', '138', '150', '159', '165', '171', '177']},{'id': '94', 'type': 'if_statement', 'children': ['95', '104']},{'id': '95', 'type': 'boolean_operator', 'children': ['96', '99'], 'value': 'and'},{'id': '96', 'type': 'comparison_operator', 'children': ['97', '98'], 'value': 'is'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'rate_limit'},{'id': '98', 'type': 'None', 'children': []},{'id': '99', 'type': 'comparison_operator', 'children': ['100', '103'], 'value': 'is'},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'last_query'},{'id': '103', 'type': 'None', 'children': []},{'id': '104', 'type': 'block', 'children': ['105', '126']},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'assignment', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'to_sleep'},{'id': '108', 'type': 'binary_operator', 'children': ['109', '110'], 'value': '-'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'rate_limit'},{'id': '110', 'type': 'call', 'children': ['111', '125']},{'id': '111', 'type': 'attribute', 'children': ['112', '124']},{'id': '112', 'type': '()', 'children': ['113']},{'id': '113', 'type': 'binary_operator', 'children': ['114', '121'], 'value': '-'},{'id': '114', 'type': 'call', 'children': ['115', '120']},{'id': '115', 'type': 'attribute', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '120', 'type': 'argument_list', 'children': []},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'last_query'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'total_seconds'},{'id': '125', 'type': 'argument_list', 'children': []},{'id': '126', 'type': 'if_statement', 'children': ['127', '130']},{'id': '127', 'type': 'comparison_operator', 'children': ['128', '129'], 'value': '>'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'to_sleep'},{'id': '129', 'type': 'integer', 'children': [], 'value': '0'},{'id': '130', 'type': 'block', 'children': ['131']},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'call', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'sleep'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'to_sleep'},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'assignment', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'last_query'},{'id': '143', 'type': 'call', 'children': ['144', '149']},{'id': '144', 'type': 'attribute', 'children': ['145', '148']},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '149', 'type': 'argument_list', 'children': []},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'assignment', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '153', 'type': 'call', 'children': ['154', '157']},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'requests'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '157', 'type': 'argument_list', 'children': ['158']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '159', 'type': 'expression_statement', 'children': ['160']},{'id': '160', 'type': 'assignment', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '165', 'type': 'expression_statement', 'children': ['166']},{'id': '166', 'type': 'assignment', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '171', 'type': 'expression_statement', 'children': ['172']},{'id': '172', 'type': 'call', 'children': ['173', '176']},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '176', 'type': 'argument_list', 'children': []},{'id': '177', 'type': 'if_statement', 'children': ['178', '181']},{'id': '178', 'type': 'comparison_operator', 'children': ['179', '180'], 'value': 'is'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'xpath'},{'id': '180', 'type': 'None', 'children': []},{'id': '181', 'type': 'block', 'children': ['182', '191', '200']},{'id': '182', 'type': 'expression_statement', 'children': ['183']},{'id': '183', 'type': 'assignment', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'doc'},{'id': '185', 'type': 'call', 'children': ['186', '189']},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'html'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'fromstring'},{'id': '189', 'type': 'argument_list', 'children': ['190']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '191', 'type': 'expression_statement', 'children': ['192']},{'id': '192', 'type': 'assignment', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '194', 'type': 'call', 'children': ['195', '198']},{'id': '195', 'type': 'attribute', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'doc'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'xpath'},{'id': '198', 'type': 'argument_list', 'children': ['199']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'xpath'},{'id': '200', 'type': 'if_statement', 'children': ['201', '207', '218']},{'id': '201', 'type': 'comparison_operator', 'children': ['202', '206'], 'value': '=='},{'id': '202', 'type': 'call', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '204', 'type': 'argument_list', 'children': ['205']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '206', 'type': 'integer', 'children': [], 'value': '0'},{'id': '207', 'type': 'block', 'children': ['208', '214']},{'id': '208', 'type': 'expression_statement', 'children': ['209']},{'id': '209', 'type': 'assignment', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '211', 'type': 'binary_operator', 'children': ['212', '213'], 'value': '+'},{'id': '212', 'type': 'string', 'children': [], 'value': '"xpath not found: "'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'xpath'},{'id': '214', 'type': 'expression_statement', 'children': ['215']},{'id': '215', 'type': 'assignment', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'ERROR_XPATH_NOT_FOUND'},{'id': '218', 'type': 'else_clause', 'children': ['219']},{'id': '219', 'type': 'block', 'children': ['220']},{'id': '220', 'type': 'expression_statement', 'children': ['221']},{'id': '221', 'type': 'assignment', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '223', 'type': 'call', 'children': ['224', '227']},{'id': '224', 'type': 'attribute', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'html'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'tostring'},{'id': '227', 'type': 'argument_list', 'children': ['228', '231']},{'id': '228', 'type': 'subscript', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '230', 'type': 'integer', 'children': [], 'value': '0'},{'id': '231', 'type': 'keyword_argument', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '233', 'type': 'string', 'children': [], 'value': "'unicode'"},{'id': '234', 'type': 'except_clause', 'children': ['235', '241']},{'id': '235', 'type': 'as_pattern', 'children': ['236', '239']},{'id': '236', 'type': 'attribute', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'requests'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'ConnectionError'},{'id': '239', 'type': 'as_pattern_target', 'children': ['240']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '241', 'type': 'block', 'children': ['242', '246']},{'id': '242', 'type': 'expression_statement', 'children': ['243']},{'id': '243', 'type': 'assignment', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'ERROR_CONNECTION_ERROR'},{'id': '246', 'type': 'expression_statement', 'children': ['247']},{'id': '247', 'type': 'assignment', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '249', 'type': 'call', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '251', 'type': 'argument_list', 'children': ['252']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '253', 'type': 'expression_statement', 'children': ['254']},{'id': '254', 'type': 'assignment', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'cached'},{'id': '256', 'type': 'call', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'CachedRequest'},{'id': '258', 'type': 'argument_list', 'children': ['259', '265', '268', '271', '274']},{'id': '259', 'type': 'keyword_argument', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '261', 'type': 'call', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '263', 'type': 'argument_list', 'children': ['264']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '265', 'type': 'keyword_argument', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '268', 'type': 'keyword_argument', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '271', 'type': 'keyword_argument', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'xpath'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'xpath'},{'id': '274', 'type': 'keyword_argument', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'queried_on'},{'id': '276', 'type': 'call', 'children': ['277', '282']},{'id': '277', 'type': 'attribute', 'children': ['278', '281']},{'id': '278', 'type': 'attribute', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '282', 'type': 'argument_list', 'children': []},{'id': '283', 'type': 'if_statement', 'children': ['284', '293']},{'id': '284', 'type': 'boolean_operator', 'children': ['285', '292'], 'value': 'or'},{'id': '285', 'type': 'comparison_operator', 'children': ['286', '287'], 'value': '=='},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '287', 'type': 'attribute', 'children': ['288', '291']},{'id': '288', 'type': 'attribute', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'requests'},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'codes'},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'ok'},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'store_on_error'},{'id': '293', 'type': 'block', 'children': ['294', '303']},{'id': '294', 'type': 'expression_statement', 'children': ['295']},{'id': '295', 'type': 'call', 'children': ['296', '301']},{'id': '296', 'type': 'attribute', 'children': ['297', '300']},{'id': '297', 'type': 'attribute', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '301', 'type': 'argument_list', 'children': ['302']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'cached'},{'id': '303', 'type': 'expression_statement', 'children': ['304']},{'id': '304', 'type': 'call', 'children': ['305', '310']},{'id': '305', 'type': 'attribute', 'children': ['306', '309']},{'id': '306', 'type': 'attribute', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'commit'},{'id': '310', 'type': 'argument_list', 'children': []},{'id': '311', 'type': 'if_statement', 'children': ['312', '319']},{'id': '312', 'type': 'comparison_operator', 'children': ['313', '314'], 'value': '!='},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '314', 'type': 'attribute', 'children': ['315', '318']},{'id': '315', 'type': 'attribute', 'children': ['316', '317']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'requests'},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'codes'},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'ok'},{'id': '319', 'type': 'block', 'children': ['320']},{'id': '320', 'type': 'raise_statement', 'children': ['321']},{'id': '321', 'type': 'call', 'children': ['322', '323']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'},{'id': '323', 'type': 'argument_list', 'children': ['324']},{'id': '324', 'type': 'binary_operator', 'children': ['325', '333'], 'value': '+'},{'id': '325', 'type': 'binary_operator', 'children': ['326', '332'], 'value': '+'},{'id': '326', 'type': 'binary_operator', 'children': ['327', '328'], 'value': '+'},{'id': '327', 'type': 'string', 'children': [], 'value': '"Error processing the request, "'},{'id': '328', 'type': 'call', 'children': ['329', '330']},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '330', 'type': 'argument_list', 'children': ['331']},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '332', 'type': 'string', 'children': [], 'value': '": "'},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '334', 'type': 'return_statement', 'children': ['335']},{'id': '335', 'type': 'attribute', 'children': ['336', '337']},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'cached'},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'content'}
def get(self, url, store_on_error=False, xpath=None, rate_limit=None, log_hits=True, log_misses=True): try: cached = self._query(url, xpath).one() if log_hits: config.logger.info("Request cache hit: " + url) 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) try: 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 content = response.text response.close() if xpath is not None: doc = html.fromstring(content) nodes = doc.xpath(xpath) if len(nodes) == 0: content = "xpath not found: " + xpath status_code = ERROR_XPATH_NOT_FOUND else: content = html.tostring(nodes[0], encoding='unicode') except requests.ConnectionError as e: status_code = ERROR_CONNECTION_ERROR content = str(e) cached = CachedRequest(url=str(url), content=content, status_code=status_code, xpath=xpath, queried_on=datetime.datetime.now()) 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
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'event'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'event_data'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'priority'},{'id': '8', 'type': 'string', 'children': [], 'value': '"normal"'},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'event_method'},{'id': '11', 'type': 'string', 'children': [], 'value': '"EVENT"'},{'id': '12', 'type': 'block', 'children': ['13', '25', '33', '60', '75', '104', '144', '168', '187', '198', '219', '234']},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'call', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'binary_operator', 'children': ['20', '21'], 'value': '+'},{'id': '20', 'type': 'string', 'children': [], 'value': '"event: "'},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'event_data'},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'euuid'},{'id': '28', 'type': 'call', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'uuid1'},{'id': '32', 'type': 'argument_list', 'children': []},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'call', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'binary_operator', 'children': ['40', '43'], 'value': '%'},{'id': '40', 'type': 'concatenated_string', 'children': ['41', '42']},{'id': '41', 'type': 'string', 'children': [], 'value': '"<%s> <euuid:%s> Sending event data to server: "'},{'id': '42', 'type': 'string', 'children': [], 'value': '"%s"'},{'id': '43', 'type': 'tuple', 'children': ['44', '50', '54']},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'cuuid'},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'euuid'},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'server'},{'id': '60', 'type': 'if_statement', 'children': ['61', '67']},{'id': '61', 'type': 'not_operator', 'children': ['62']},{'id': '62', 'type': 'attribute', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'listener'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'listening'},{'id': '67', 'type': 'block', 'children': ['68']},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'call', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'string', 'children': [], 'value': '"Neteria client is not listening."'},{'id': '75', 'type': 'if_statement', 'children': ['76', '80']},{'id': '76', 'type': 'not_operator', 'children': ['77']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'registered'},{'id': '80', 'type': 'block', 'children': ['81', '102']},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'call', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'binary_operator', 'children': ['88', '91'], 'value': '%'},{'id': '88', 'type': 'concatenated_string', 'children': ['89', '90']},{'id': '89', 'type': 'string', 'children': [], 'value': '"<%s> <euuid:%s> Client is currently not registered. "'},{'id': '90', 'type': 'string', 'children': [], 'value': '"Event not sent."'},{'id': '91', 'type': 'tuple', 'children': ['92', '98']},{'id': '92', 'type': 'call', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'cuuid'},{'id': '98', 'type': 'call', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'euuid'},{'id': '102', 'type': 'return_statement', 'children': ['103']},{'id': '103', 'type': 'False', 'children': []},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'assignment', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'packet'},{'id': '107', 'type': 'dictionary', 'children': ['108', '111', '119', '125', '128', '138', '141']},{'id': '108', 'type': 'pair', 'children': ['109', '110']},{'id': '109', 'type': 'string', 'children': [], 'value': '"method"'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'event_method'},{'id': '111', 'type': 'pair', 'children': ['112', '113']},{'id': '112', 'type': 'string', 'children': [], 'value': '"cuuid"'},{'id': '113', 'type': 'call', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '115', 'type': 'argument_list', 'children': ['116']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'cuuid'},{'id': '119', 'type': 'pair', 'children': ['120', '121']},{'id': '120', 'type': 'string', 'children': [], 'value': '"euuid"'},{'id': '121', 'type': 'call', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '123', 'type': 'argument_list', 'children': ['124']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'euuid'},{'id': '125', 'type': 'pair', 'children': ['126', '127']},{'id': '126', 'type': 'string', 'children': [], 'value': '"event_data"'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'event_data'},{'id': '128', 'type': 'pair', 'children': ['129', '130']},{'id': '129', 'type': 'string', 'children': [], 'value': '"timestamp"'},{'id': '130', 'type': 'call', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'call', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '137', 'type': 'argument_list', 'children': []},{'id': '138', 'type': 'pair', 'children': ['139', '140']},{'id': '139', 'type': 'string', 'children': [], 'value': '"retry"'},{'id': '140', 'type': 'integer', 'children': [], 'value': '0'},{'id': '141', 'type': 'pair', 'children': ['142', '143']},{'id': '142', 'type': 'string', 'children': [], 'value': '"priority"'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'priority'},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'call', 'children': ['146', '151']},{'id': '146', 'type': 'attribute', 'children': ['147', '150']},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'listener'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'send_datagram'},{'id': '151', 'type': 'argument_list', 'children': ['152', '165']},{'id': '152', 'type': 'call', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'serialize_data'},{'id': '154', 'type': 'argument_list', 'children': ['155', '156', '159', '162']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'packet'},{'id': '156', 'type': 'attribute', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'compression'},{'id': '159', 'type': 'attribute', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'encryption'},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'server_key'},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'server'},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'id': '169', 'type': 'call', 'children': ['170', '173']},{'id': '170', 'type': 'attribute', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '173', 'type': 'argument_list', 'children': ['174']},{'id': '174', 'type': 'binary_operator', 'children': ['175', '176'], 'value': '%'},{'id': '175', 'type': 'string', 'children': [], 'value': '"<%s> Sending EVENT Packet: %s"'},{'id': '176', 'type': 'tuple', 'children': ['177', '183']},{'id': '177', 'type': 'call', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '179', 'type': 'argument_list', 'children': ['180']},{'id': '180', 'type': 'attribute', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'cuuid'},{'id': '183', 'type': 'call', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'pformat'},{'id': '185', 'type': 'argument_list', 'children': ['186']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'packet'},{'id': '187', 'type': 'expression_statement', 'children': ['188']},{'id': '188', 'type': 'assignment', 'children': ['189', '197']},{'id': '189', 'type': 'subscript', 'children': ['190', '193']},{'id': '190', 'type': 'attribute', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'event_uuids'},{'id': '193', 'type': 'call', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '195', 'type': 'argument_list', 'children': ['196']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'euuid'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'packet'},{'id': '198', 'type': 'expression_statement', 'children': ['199']},{'id': '199', 'type': 'call', 'children': ['200', '203']},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '203', 'type': 'argument_list', 'children': ['204']},{'id': '204', 'type': 'binary_operator', 'children': ['205', '206'], 'value': '%'},{'id': '205', 'type': 'string', 'children': [], 'value': '"<%s> Scheduling retry in %s seconds"'},{'id': '206', 'type': 'tuple', 'children': ['207', '213']},{'id': '207', 'type': 'call', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '209', 'type': 'argument_list', 'children': ['210']},{'id': '210', 'type': 'attribute', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'cuuid'},{'id': '213', 'type': 'call', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '215', 'type': 'argument_list', 'children': ['216']},{'id': '216', 'type': 'attribute', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '219', 'type': 'expression_statement', 'children': ['220']},{'id': '220', 'type': 'call', 'children': ['221', '226']},{'id': '221', 'type': 'attribute', 'children': ['222', '225']},{'id': '222', 'type': 'attribute', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'listener'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'call_later'},{'id': '226', 'type': 'argument_list', 'children': ['227', '230', '233']},{'id': '227', 'type': 'attribute', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '230', 'type': 'attribute', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'retransmit'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'packet'},{'id': '234', 'type': 'return_statement', 'children': ['235']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'euuid'}
def event(self, event_data, priority="normal", event_method="EVENT"): logger.debug("event: " + str(event_data)) 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 not self.registered: logger.warning("<%s> <euuid:%s> Client is currently not registered. " "Event not sent." % (str(self.cuuid), str(euuid))) return False 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))) self.event_uuids[str(euuid)] = packet 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
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'run'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '11', '31', '53', '68', '78', '84', '90', '217', '221', '234', '346', '355', '363']},{'id': '6', 'type': 'import_statement', 'children': ['7']},{'id': '7', 'type': 'aliased_import', 'children': ['8', '10']},{'id': '8', 'type': 'dotted_name', 'children': ['9']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'numpy'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '14', 'type': 'call', 'children': ['15', '20']},{'id': '15', 'type': 'attribute', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '20', 'type': 'argument_list', 'children': ['21', '26']},{'id': '21', 'type': 'attribute', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'NUTS2Region'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '26', 'type': 'attribute', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'NUTS2Region'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'region_ids'},{'id': '34', 'type': 'call', 'children': ['35', '52']},{'id': '35', 'type': 'attribute', 'children': ['36', '51']},{'id': '36', 'type': 'subscript', 'children': ['37', '50']},{'id': '37', 'type': 'call', 'children': ['38', '48']},{'id': '38', 'type': 'attribute', 'children': ['39', '47']},{'id': '39', 'type': 'call', 'children': ['40', '45']},{'id': '40', 'type': 'attribute', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'client'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'df_query'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'set_index'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'string', 'children': [], 'value': "'key'"},{'id': '50', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'to_dict'},{'id': '52', 'type': 'argument_list', 'children': []},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '56', 'type': 'call', 'children': ['57', '67']},{'id': '57', 'type': 'attribute', 'children': ['58', '66']},{'id': '58', 'type': 'call', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'next'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'call', 'children': ['62', '65']},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'requires'},{'id': '65', 'type': 'argument_list', 'children': []},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'load'},{'id': '67', 'type': 'argument_list', 'children': []},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'nuts'},{'id': '71', 'type': 'call', 'children': ['72', '77']},{'id': '72', 'type': 'attribute', 'children': ['73', '76']},{'id': '73', 'type': 'call', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'NUTS2GeoJSONInputFile'},{'id': '75', 'type': 'argument_list', 'children': []},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'load'},{'id': '77', 'type': 'argument_list', 'children': []},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'indicator_ids'},{'id': '81', 'type': 'call', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '83', 'type': 'argument_list', 'children': []},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 't_data'},{'id': '87', 'type': 'call', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '89', 'type': 'argument_list', 'children': []},{'id': '90', 'type': 'for_statement', 'children': ['91', '94', '99']},{'id': '91', 'type': 'pattern_list', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'season'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'suffix'},{'id': '94', 'type': 'call', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'CLIMATE_SEASON_SUFFIXES'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '98', 'type': 'argument_list', 'children': []},{'id': '99', 'type': 'block', 'children': ['100', '115', '124', '132', '140']},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'indicator'},{'id': '103', 'type': 'call', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'ClimateIndicator'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'keyword_argument', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '110', 'type': 'binary_operator', 'children': ['111', '114'], 'value': '+'},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'suffix'},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'call', 'children': ['117', '122']},{'id': '117', 'type': 'attribute', 'children': ['118', '121']},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'indicator'},{'id': '124', 'type': 'expression_statement', 'children': ['125']},{'id': '125', 'type': 'call', 'children': ['126', '131']},{'id': '126', 'type': 'attribute', 'children': ['127', '130']},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'commit'},{'id': '131', 'type': 'argument_list', 'children': []},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'assignment', 'children': ['134', '137']},{'id': '134', 'type': 'subscript', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'indicator_ids'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'season'},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'indicator'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '140', 'type': 'if_statement', 'children': ['141', '144', '172']},{'id': '141', 'type': 'comparison_operator', 'children': ['142', '143'], 'value': '=='},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'season'},{'id': '143', 'type': 'string', 'children': [], 'value': "'summer'"},{'id': '144', 'type': 'block', 'children': ['145']},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'assignment', 'children': ['147', '150']},{'id': '147', 'type': 'subscript', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 't_data'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'season'},{'id': '150', 'type': 'call', 'children': ['151', '156']},{'id': '151', 'type': 'attribute', 'children': ['152', '155']},{'id': '152', 'type': 'attribute', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'ma'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'average'},{'id': '156', 'type': 'argument_list', 'children': ['157', '169']},{'id': '157', 'type': 'subscript', 'children': ['158', '161', '165', '167']},{'id': '158', 'type': 'subscript', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '160', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '161', 'type': 'slice', 'children': ['162', '163', '164']},{'id': '162', 'type': 'integer', 'children': [], 'value': '3'},{'id': '163', 'type': 'colon', 'children': []},{'id': '164', 'type': 'integer', 'children': [], 'value': '9'},{'id': '165', 'type': 'slice', 'children': ['166']},{'id': '166', 'type': 'colon', 'children': []},{'id': '167', 'type': 'slice', 'children': ['168']},{'id': '168', 'type': 'colon', 'children': []},{'id': '169', 'type': 'keyword_argument', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '171', 'type': 'integer', 'children': [], 'value': '0'},{'id': '172', 'type': 'else_clause', 'children': ['173']},{'id': '173', 'type': 'block', 'children': ['174']},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'id': '175', 'type': 'assignment', 'children': ['176', '179']},{'id': '176', 'type': 'subscript', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 't_data'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'season'},{'id': '179', 'type': 'call', 'children': ['180', '185']},{'id': '180', 'type': 'attribute', 'children': ['181', '184']},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'ma'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'average'},{'id': '185', 'type': 'argument_list', 'children': ['186', '214']},{'id': '186', 'type': 'binary_operator', 'children': ['187', '188'], 'value': '*'},{'id': '187', 'type': 'float', 'children': [], 'value': '0.5'},{'id': '188', 'type': '()', 'children': ['189']},{'id': '189', 'type': 'binary_operator', 'children': ['190', '202'], 'value': '+'},{'id': '190', 'type': 'subscript', 'children': ['191', '194', '198', '200']},{'id': '191', 'type': 'subscript', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '193', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '194', 'type': 'slice', 'children': ['195', '196', '197']},{'id': '195', 'type': 'integer', 'children': [], 'value': '0'},{'id': '196', 'type': 'colon', 'children': []},{'id': '197', 'type': 'integer', 'children': [], 'value': '3'},{'id': '198', 'type': 'slice', 'children': ['199']},{'id': '199', 'type': 'colon', 'children': []},{'id': '200', 'type': 'slice', 'children': ['201']},{'id': '201', 'type': 'colon', 'children': []},{'id': '202', 'type': 'subscript', 'children': ['203', '206', '210', '212']},{'id': '203', 'type': 'subscript', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '205', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '206', 'type': 'slice', 'children': ['207', '208', '209']},{'id': '207', 'type': 'integer', 'children': [], 'value': '9'},{'id': '208', 'type': 'colon', 'children': []},{'id': '209', 'type': 'integer', 'children': [], 'value': '12'},{'id': '210', 'type': 'slice', 'children': ['211']},{'id': '211', 'type': 'colon', 'children': []},{'id': '212', 'type': 'slice', 'children': ['213']},{'id': '213', 'type': 'colon', 'children': []},{'id': '214', 'type': 'keyword_argument', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '216', 'type': 'integer', 'children': [], 'value': '0'},{'id': '217', 'type': 'expression_statement', 'children': ['218']},{'id': '218', 'type': 'assignment', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '220', 'type': 'list', 'children': [], 'value': '[]'},{'id': '221', 'type': 'expression_statement', 'children': ['222']},{'id': '222', 'type': 'assignment', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'current_value_id'},{'id': '224', 'type': 'call', 'children': ['225', '230']},{'id': '225', 'type': 'attribute', 'children': ['226', '229']},{'id': '226', 'type': 'attribute', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'ClimateValue'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'get_max_id'},{'id': '230', 'type': 'argument_list', 'children': ['231']},{'id': '231', 'type': 'attribute', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '234', 'type': 'for_statement', 'children': ['235', '236', '237']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'feature'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'nuts'},{'id': '237', 'type': 'block', 'children': ['238', '264']},{'id': '238', 'type': 'expression_statement', 'children': ['239']},{'id': '239', 'type': 'assignment', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'mask'},{'id': '241', 'type': 'call', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'geojson_polygon_to_mask'},{'id': '243', 'type': 'argument_list', 'children': ['244', '247', '254', '259']},{'id': '244', 'type': 'keyword_argument', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'feature'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'feature'},{'id': '247', 'type': 'keyword_argument', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '249', 'type': 'attribute', 'children': ['250', '253']},{'id': '250', 'type': 'subscript', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 't_data'},{'id': '252', 'type': 'string', 'children': [], 'value': "'summer'"},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '254', 'type': 'keyword_argument', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'lat_idx'},{'id': '256', 'type': 'subscript', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '258', 'type': 'string', 'children': [], 'value': "'lat_idx'"},{'id': '259', 'type': 'keyword_argument', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'lon_idx'},{'id': '261', 'type': 'subscript', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '263', 'type': 'string', 'children': [], 'value': "'lon_idx'"},{'id': '264', 'type': 'for_statement', 'children': ['265', '266', '274']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'season'},{'id': '266', 'type': 'call', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '268', 'type': 'argument_list', 'children': ['269']},{'id': '269', 'type': 'call', 'children': ['270', '273']},{'id': '270', 'type': 'attribute', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'CLIMATE_SEASON_SUFFIXES'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '273', 'type': 'argument_list', 'children': []},{'id': '274', 'type': 'block', 'children': ['275', '291', '305', '317', '321']},{'id': '275', 'type': 'expression_statement', 'children': ['276']},{'id': '276', 'type': 'assignment', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '278', 'type': 'call', 'children': ['279', '284']},{'id': '279', 'type': 'attribute', 'children': ['280', '283']},{'id': '280', 'type': 'attribute', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'ma'},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'average'},{'id': '284', 'type': 'argument_list', 'children': ['285', '288']},{'id': '285', 'type': 'subscript', 'children': ['286', '287']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 't_data'},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'season'},{'id': '288', 'type': 'keyword_argument', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'weights'},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'mask'},{'id': '291', 'type': 'expression_statement', 'children': ['292']},{'id': '292', 'type': 'assignment', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'region_id'},{'id': '294', 'type': 'call', 'children': ['295', '298']},{'id': '295', 'type': 'attribute', 'children': ['296', '297']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'region_ids'},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '298', 'type': 'argument_list', 'children': ['299', '304']},{'id': '299', 'type': 'subscript', 'children': ['300', '303']},{'id': '300', 'type': 'attribute', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'feature'},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'properties'},{'id': '303', 'type': 'string', 'children': [], 'value': "'NUTS_ID'"},{'id': '304', 'type': 'None', 'children': []},{'id': '305', 'type': 'if_statement', 'children': ['306', '309']},{'id': '306', 'type': 'comparison_operator', 'children': ['307', '308'], 'value': 'is'},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'region_id'},{'id': '308', 'type': 'None', 'children': []},{'id': '309', 'type': 'block', 'children': ['310']},{'id': '310', 'type': 'expression_statement', 'children': ['311']},{'id': '311', 'type': 'assignment', 'children': ['312', '313']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'region_id'},{'id': '313', 'type': 'call', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '315', 'type': 'argument_list', 'children': ['316']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'region_id'},{'id': '317', 'type': 'expression_statement', 'children': ['318']},{'id': '318', 'type': 'augmented_assignment', 'children': ['319', '320'], 'value': '+='},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'current_value_id'},{'id': '320', 'type': 'integer', 'children': [], 'value': '1'},{'id': '321', 'type': 'expression_statement', 'children': ['322']},{'id': '322', 'type': 'call', 'children': ['323', '326']},{'id': '323', 'type': 'attribute', 'children': ['324', '325']},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '326', 'type': 'argument_list', 'children': ['327']},{'id': '327', 'type': 'call', 'children': ['328', '331']},{'id': '328', 'type': 'attribute', 'children': ['329', '330']},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'ClimateValue'},{'id': '331', 'type': 'argument_list', 'children': ['332', '335', '338', '341']},{'id': '332', 'type': 'keyword_argument', 'children': ['333', '334']},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'current_value_id'},{'id': '335', 'type': 'keyword_argument', 'children': ['336', '337']},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '338', 'type': 'keyword_argument', 'children': ['339', '340']},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'region_id'},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'region_id'},{'id': '341', 'type': 'keyword_argument', 'children': ['342', '343']},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'indicator_id'},{'id': '343', 'type': 'subscript', 'children': ['344', '345']},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'indicator_ids'},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'season'},{'id': '346', 'type': 'expression_statement', 'children': ['347']},{'id': '347', 'type': 'call', 'children': ['348', '353']},{'id': '348', 'type': 'attribute', 'children': ['349', '352']},{'id': '349', 'type': 'attribute', 'children': ['350', '351']},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'bulk_save_objects'},{'id': '353', 'type': 'argument_list', 'children': ['354']},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '355', 'type': 'expression_statement', 'children': ['356']},{'id': '356', 'type': 'call', 'children': ['357', '362']},{'id': '357', 'type': 'attribute', 'children': ['358', '361']},{'id': '358', 'type': 'attribute', 'children': ['359', '360']},{'id': '359', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'commit'},{'id': '362', 'type': 'argument_list', 'children': []},{'id': '363', 'type': 'expression_statement', 'children': ['364']},{'id': '364', 'type': 'call', 'children': ['365', '368']},{'id': '365', 'type': 'attribute', 'children': ['366', '367']},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'done'},{'id': '368', 'type': 'argument_list', 'children': []}
def run(self): import numpy as np query = self.session.query(models.NUTS2Region.key, models.NUTS2Region.id) region_ids = self.client.df_query(query).set_index('key')['id'].to_dict() data = next(self.requires()).load() nuts = NUTS2GeoJSONInputFile().load() indicator_ids = dict() t_data = dict() for season, suffix in CLIMATE_SEASON_SUFFIXES.items(): indicator = models.ClimateIndicator(description=self.description + suffix) self.session.add(indicator) self.session.commit() indicator_ids[season] = indicator.id if season == 'summer': t_data[season] = np.ma.average(data['data'][3:9, :, :], axis=0) else: t_data[season] = np.ma.average(0.5 * (data['data'][0:3, :, :] + data['data'][9:12, :, :]), axis=0) objects = [] current_value_id = models.ClimateValue.get_max_id(self.session) for feature in nuts: mask = geojson_polygon_to_mask(feature=feature, shape=t_data['summer'].shape, lat_idx=data['lat_idx'], lon_idx=data['lon_idx']) for season in list(CLIMATE_SEASON_SUFFIXES.keys()): value = np.ma.average(t_data[season], weights=mask) region_id = region_ids.get(feature.properties['NUTS_ID'], None) if region_id is not None: region_id = int(region_id) current_value_id += 1 objects.append(models.ClimateValue(id=current_value_id, value=value, region_id=region_id, indicator_id=indicator_ids[season])) self.session.bulk_save_objects(objects) self.session.commit() self.done()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'dapply'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'fn'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'pairwise'},{'id': '8', 'type': 'False', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'symmetric'},{'id': '11', 'type': 'True', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'diagonal'},{'id': '14', 'type': 'False', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'block'},{'id': '17', 'type': 'None', 'children': []},{'id': '18', 'type': 'dictionary_splat_pattern', 'children': ['19']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '20', 'type': 'block', 'children': ['21', '48', '57', '73', '77', '220']},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'search_keys'},{'id': '24', 'type': 'list_comprehension', 'children': ['25', '26', '35']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '26', 'type': 'for_in_clause', 'children': ['27', '30']},{'id': '27', 'type': 'pattern_list', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '34', 'type': 'argument_list', 'children': []},{'id': '35', 'type': 'if_clause', 'children': ['36']},{'id': '36', 'type': 'boolean_operator', 'children': ['37', '42'], 'value': 'and'},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '39', 'type': 'argument_list', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '42', 'type': 'comparison_operator', 'children': ['43', '47'], 'value': '>'},{'id': '43', 'type': 'call', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '47', 'type': 'integer', 'children': [], 'value': '1'},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'functions'},{'id': '51', 'type': 'call', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'util'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'make_list'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'fn'},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'product'},{'id': '65', 'type': 'argument_list', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'functions'},{'id': '67', 'type': 'call', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'util'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'dict_product'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '76', 'type': 'list', 'children': [], 'value': '[]'},{'id': '77', 'type': 'for_statement', 'children': ['78', '81', '82']},{'id': '78', 'type': 'pattern_list', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'fn'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'kw'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '82', 'type': 'block', 'children': ['83', '131', '146', '160', '213']},{'id': '83', 'type': 'if_statement', 'children': ['84', '86', '110']},{'id': '84', 'type': 'not_operator', 'children': ['85']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'pairwise'},{'id': '86', 'type': 'block', 'children': ['87']},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '90', 'type': 'call', 'children': ['91', '100']},{'id': '91', 'type': 'attribute', 'children': ['92', '99']},{'id': '92', 'type': 'call', 'children': ['93', '98']},{'id': '93', 'type': 'attribute', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'to_series'},{'id': '98', 'type': 'argument_list', 'children': []},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'apply'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'lambda', 'children': ['102', '104']},{'id': '102', 'type': 'lambda_parameters', 'children': ['103']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'step'},{'id': '104', 'type': 'call', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'fn'},{'id': '106', 'type': 'argument_list', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'step'},{'id': '108', 'type': 'dictionary_splat', 'children': ['109']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'kw'},{'id': '110', 'type': 'else_clause', 'children': ['111']},{'id': '111', 'type': 'block', 'children': ['112']},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'assignment', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '115', 'type': 'call', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'apply_pairwise'},{'id': '117', 'type': 'argument_list', 'children': ['118', '119', '120', '123', '126', '129']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'fn'},{'id': '120', 'type': 'keyword_argument', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'symmetric'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'symmetric'},{'id': '123', 'type': 'keyword_argument', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'diagonal'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'diagonal'},{'id': '126', 'type': 'keyword_argument', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'block'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'block'},{'id': '129', 'type': 'dictionary_splat', 'children': ['130']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'kw'},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'assignment', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '134', 'type': 'conditional_expression', 'children': ['135', '136', '142'], 'value': 'if'},{'id': '135', 'type': 'list', 'children': [], 'value': '[]'},{'id': '136', 'type': 'comparison_operator', 'children': ['137', '141'], 'value': '=='},{'id': '137', 'type': 'call', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '139', 'type': 'argument_list', 'children': ['140']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'functions'},{'id': '141', 'type': 'integer', 'children': [], 'value': '1'},{'id': '142', 'type': 'list', 'children': ['143'], 'value': '[fn.__name__]'},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'fn'},{'id': '145', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '146', 'type': 'expression_statement', 'children': ['147']},{'id': '147', 'type': 'augmented_assignment', 'children': ['148', '149'], 'value': '+='},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '149', 'type': 'call', 'children': ['150', '159']},{'id': '150', 'type': 'attribute', 'children': ['151', '158']},{'id': '151', 'type': 'call', 'children': ['152', '155']},{'id': '152', 'type': 'attribute', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'util'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'dict_subset'},{'id': '155', 'type': 'argument_list', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'kw'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'search_keys'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '159', 'type': 'argument_list', 'children': []},{'id': '160', 'type': 'if_statement', 'children': ['161', '168', '202']},{'id': '161', 'type': 'call', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '163', 'type': 'argument_list', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'DataFrame'},{'id': '168', 'type': 'block', 'children': ['169', '196']},{'id': '169', 'type': 'expression_statement', 'children': ['170']},{'id': '170', 'type': 'assignment', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '172', 'type': 'call', 'children': ['173', '178']},{'id': '173', 'type': 'attribute', 'children': ['174', '177']},{'id': '174', 'type': 'attribute', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'MultiIndex'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'from_tuples'},{'id': '178', 'type': 'argument_list', 'children': ['179']},{'id': '179', 'type': 'list_comprehension', 'children': ['180', '191']},{'id': '180', 'type': 'call', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '182', 'type': 'argument_list', 'children': ['183']},{'id': '183', 'type': 'binary_operator', 'children': ['184', '185'], 'value': '+'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '185', 'type': 'call', 'children': ['186', '189']},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'util'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'make_list'},{'id': '189', 'type': 'argument_list', 'children': ['190']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '191', 'type': 'for_in_clause', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '193', 'type': 'attribute', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '196', 'type': 'expression_statement', 'children': ['197']},{'id': '197', 'type': 'assignment', 'children': ['198', '201']},{'id': '198', 'type': 'attribute', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '202', 'type': 'else_clause', 'children': ['203']},{'id': '203', 'type': 'block', 'children': ['204']},{'id': '204', 'type': 'expression_statement', 'children': ['205']},{'id': '205', 'type': 'assignment', 'children': ['206', '209']},{'id': '206', 'type': 'attribute', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '209', 'type': 'call', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '211', 'type': 'argument_list', 'children': ['212']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '213', 'type': 'expression_statement', 'children': ['214']},{'id': '214', 'type': 'call', 'children': ['215', '218']},{'id': '215', 'type': 'attribute', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '218', 'type': 'argument_list', 'children': ['219']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '220', 'type': 'if_statement', 'children': ['221', '227', '290']},{'id': '221', 'type': 'comparison_operator', 'children': ['222', '226'], 'value': '>'},{'id': '222', 'type': 'call', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '224', 'type': 'argument_list', 'children': ['225']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '226', 'type': 'integer', 'children': [], 'value': '1'},{'id': '227', 'type': 'block', 'children': ['228', '240', '253', '257', '277', '285']},{'id': '228', 'type': 'expression_statement', 'children': ['229']},{'id': '229', 'type': 'assignment', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '231', 'type': 'call', 'children': ['232', '235']},{'id': '232', 'type': 'attribute', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'concat'},{'id': '235', 'type': 'argument_list', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '237', 'type': 'keyword_argument', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '239', 'type': 'integer', 'children': [], 'value': '1'},{'id': '240', 'type': 'expression_statement', 'children': ['241']},{'id': '241', 'type': 'assignment', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'column_names'},{'id': '243', 'type': 'conditional_expression', 'children': ['244', '245', '251'], 'value': 'if'},{'id': '244', 'type': 'list', 'children': [], 'value': '[]'},{'id': '245', 'type': 'comparison_operator', 'children': ['246', '250'], 'value': '=='},{'id': '246', 'type': 'call', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '248', 'type': 'argument_list', 'children': ['249']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'functions'},{'id': '250', 'type': 'integer', 'children': [], 'value': '1'},{'id': '251', 'type': 'list', 'children': ['252'], 'value': '[None]'},{'id': '252', 'type': 'None', 'children': []},{'id': '253', 'type': 'expression_statement', 'children': ['254']},{'id': '254', 'type': 'augmented_assignment', 'children': ['255', '256'], 'value': '+='},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'column_names'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'search_keys'},{'id': '257', 'type': 'expression_statement', 'children': ['258']},{'id': '258', 'type': 'augmented_assignment', 'children': ['259', '260'], 'value': '+='},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'column_names'},{'id': '260', 'type': 'binary_operator', 'children': ['261', '263'], 'value': '*'},{'id': '261', 'type': 'list', 'children': ['262'], 'value': '[None]'},{'id': '262', 'type': 'None', 'children': []},{'id': '263', 'type': '()', 'children': ['264']},{'id': '264', 'type': 'binary_operator', 'children': ['265', '273'], 'value': '-'},{'id': '265', 'type': 'call', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '267', 'type': 'argument_list', 'children': ['268']},{'id': '268', 'type': 'attribute', 'children': ['269', '272']},{'id': '269', 'type': 'attribute', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '273', 'type': 'call', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '275', 'type': 'argument_list', 'children': ['276']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'column_names'},{'id': '277', 'type': 'expression_statement', 'children': ['278']},{'id': '278', 'type': 'assignment', 'children': ['279', '284']},{'id': '279', 'type': 'attribute', 'children': ['280', '283']},{'id': '280', 'type': 'attribute', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'column_names'},{'id': '285', 'type': 'return_statement', 'children': ['286']},{'id': '286', 'type': 'call', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'StepFrame'},{'id': '288', 'type': 'argument_list', 'children': ['289']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '290', 'type': 'else_clause', 'children': ['291']},{'id': '291', 'type': 'block', 'children': ['292', '298']},{'id': '292', 'type': 'expression_statement', 'children': ['293']},{'id': '293', 'type': 'assignment', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '295', 'type': 'subscript', 'children': ['296', '297']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '297', 'type': 'integer', 'children': [], 'value': '0'},{'id': '298', 'type': 'if_statement', 'children': ['299', '306', '312']},{'id': '299', 'type': 'call', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '301', 'type': 'argument_list', 'children': ['302', '303']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '303', 'type': 'attribute', 'children': ['304', '305']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'DataFrame'},{'id': '306', 'type': 'block', 'children': ['307']},{'id': '307', 'type': 'return_statement', 'children': ['308']},{'id': '308', 'type': 'call', 'children': ['309', '310']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'StepFrame'},{'id': '310', 'type': 'argument_list', 'children': ['311']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '312', 'type': 'else_clause', 'children': ['313']},{'id': '313', 'type': 'block', 'children': ['314', '324']},{'id': '314', 'type': 'expression_statement', 'children': ['315']},{'id': '315', 'type': 'assignment', 'children': ['316', '319']},{'id': '316', 'type': 'attribute', 'children': ['317', '318']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '319', 'type': 'attribute', 'children': ['320', '323']},{'id': '320', 'type': 'subscript', 'children': ['321', '322']},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'functions'},{'id': '322', 'type': 'integer', 'children': [], 'value': '0'},{'id': '323', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '324', 'type': 'return_statement', 'children': ['325']},{'id': '325', 'type': 'call', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'StepSeries'},{'id': '327', 'type': 'argument_list', 'children': ['328']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'result'}
def dapply(self, fn, pairwise=False, symmetric=True, diagonal=False, block=None, **kwargs): 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) 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)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_identifySuperGraph'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '28', '36', '45', '71', '77', '86', '95', '331', '341', '351']},{'id': '6', 'type': 'if_statement', 'children': ['7', '10']},{'id': '7', 'type': 'attribute', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '10', 'type': 'block', 'children': ['11', '20']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'call', 'children': ['13', '18']},{'id': '13', 'type': 'attribute', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'string', 'children': [], 'value': '"Condensing Graph: "'},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '23', 'type': 'call', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'clock'},{'id': '27', 'type': 'argument_list', 'children': []},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'G'},{'id': '31', 'type': 'call', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'nx'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'DiGraph'},{'id': '35', 'type': 'argument_list', 'children': []},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'call', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'G'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'add_edges_from'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'edges'},{'id': '45', 'type': 'if_statement', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'short_circuit'},{'id': '49', 'type': 'block', 'children': ['50', '60', '70']},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'superNodes'},{'id': '55', 'type': 'call', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'G'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '59', 'type': 'argument_list', 'children': []},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '65']},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'superArcs'},{'id': '65', 'type': 'call', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'G'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'edges'},{'id': '69', 'type': 'argument_list', 'children': []},{'id': '70', 'type': 'return_statement', 'children': []},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'assignment', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'augmentedEdges'},{'id': '76', 'type': 'dictionary', 'children': []},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '80', 'type': 'call', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'Y'},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'assignment', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'processed'},{'id': '89', 'type': 'call', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'zeros'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '95', 'type': 'for_statement', 'children': ['96', '97', '101']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '97', 'type': 'call', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '99', 'type': 'argument_list', 'children': ['100']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '101', 'type': 'block', 'children': ['102', '108']},{'id': '102', 'type': 'if_statement', 'children': ['103', '106']},{'id': '103', 'type': 'subscript', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'processed'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '106', 'type': 'block', 'children': ['107']},{'id': '107', 'type': 'continue_statement', 'children': []},{'id': '108', 'type': 'if_statement', 'children': ['109', '126']},{'id': '109', 'type': 'boolean_operator', 'children': ['110', '118'], 'value': 'and'},{'id': '110', 'type': 'comparison_operator', 'children': ['111', '117'], 'value': '=='},{'id': '111', 'type': 'call', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'G'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'in_degree'},{'id': '115', 'type': 'argument_list', 'children': ['116']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '117', 'type': 'integer', 'children': [], 'value': '1'},{'id': '118', 'type': 'comparison_operator', 'children': ['119', '125'], 'value': '=='},{'id': '119', 'type': 'call', 'children': ['120', '123']},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'G'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'out_degree'},{'id': '123', 'type': 'argument_list', 'children': ['124']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '125', 'type': 'integer', 'children': [], 'value': '1'},{'id': '126', 'type': 'block', 'children': ['127', '131', '147', '209', '215', '222', '238', '300', '308', '315', '325']},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'assignment', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'removedNodes'},{'id': '130', 'type': 'list', 'children': [], 'value': '[]'},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'assignment', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'lower_link'},{'id': '134', 'type': 'subscript', 'children': ['135', '146']},{'id': '135', 'type': 'subscript', 'children': ['136', '145']},{'id': '136', 'type': 'call', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'call', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'G'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'in_edges'},{'id': '143', 'type': 'argument_list', 'children': ['144']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '145', 'type': 'integer', 'children': [], 'value': '0'},{'id': '146', 'type': 'integer', 'children': [], 'value': '0'},{'id': '147', 'type': 'while_statement', 'children': ['148', '166']},{'id': '148', 'type': '()', 'children': ['149']},{'id': '149', 'type': 'boolean_operator', 'children': ['150', '158'], 'value': 'and'},{'id': '150', 'type': 'comparison_operator', 'children': ['151', '157'], 'value': '=='},{'id': '151', 'type': 'call', 'children': ['152', '155']},{'id': '152', 'type': 'attribute', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'G'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'in_degree'},{'id': '155', 'type': 'argument_list', 'children': ['156']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'lower_link'},{'id': '157', 'type': 'integer', 'children': [], 'value': '1'},{'id': '158', 'type': 'comparison_operator', 'children': ['159', '165'], 'value': '=='},{'id': '159', 'type': 'call', 'children': ['160', '163']},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'G'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'out_degree'},{'id': '163', 'type': 'argument_list', 'children': ['164']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'lower_link'},{'id': '165', 'type': 'integer', 'children': [], 'value': '1'},{'id': '166', 'type': 'block', 'children': ['167', '183', '191', '198', '205']},{'id': '167', 'type': 'expression_statement', 'children': ['168']},{'id': '168', 'type': 'assignment', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'new_lower_link'},{'id': '170', 'type': 'subscript', 'children': ['171', '182']},{'id': '171', 'type': 'subscript', 'children': ['172', '181']},{'id': '172', 'type': 'call', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '174', 'type': 'argument_list', 'children': ['175']},{'id': '175', 'type': 'call', 'children': ['176', '179']},{'id': '176', 'type': 'attribute', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'G'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'in_edges'},{'id': '179', 'type': 'argument_list', 'children': ['180']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'lower_link'},{'id': '181', 'type': 'integer', 'children': [], 'value': '0'},{'id': '182', 'type': 'integer', 'children': [], 'value': '0'},{'id': '183', 'type': 'expression_statement', 'children': ['184']},{'id': '184', 'type': 'call', 'children': ['185', '188']},{'id': '185', 'type': 'attribute', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'G'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'add_edge'},{'id': '188', 'type': 'argument_list', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'new_lower_link'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '191', 'type': 'expression_statement', 'children': ['192']},{'id': '192', 'type': 'call', 'children': ['193', '196']},{'id': '193', 'type': 'attribute', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'G'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'remove_node'},{'id': '196', 'type': 'argument_list', 'children': ['197']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'lower_link'},{'id': '198', 'type': 'expression_statement', 'children': ['199']},{'id': '199', 'type': 'call', 'children': ['200', '203']},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'removedNodes'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '203', 'type': 'argument_list', 'children': ['204']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'lower_link'},{'id': '205', 'type': 'expression_statement', 'children': ['206']},{'id': '206', 'type': 'assignment', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'lower_link'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'new_lower_link'},{'id': '209', 'type': 'expression_statement', 'children': ['210']},{'id': '210', 'type': 'call', 'children': ['211', '214']},{'id': '211', 'type': 'attribute', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'removedNodes'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '214', 'type': 'argument_list', 'children': []},{'id': '215', 'type': 'expression_statement', 'children': ['216']},{'id': '216', 'type': 'call', 'children': ['217', '220']},{'id': '217', 'type': 'attribute', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'removedNodes'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '220', 'type': 'argument_list', 'children': ['221']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '222', 'type': 'expression_statement', 'children': ['223']},{'id': '223', 'type': 'assignment', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'upper_link'},{'id': '225', 'type': 'subscript', 'children': ['226', '237']},{'id': '226', 'type': 'subscript', 'children': ['227', '236']},{'id': '227', 'type': 'call', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '229', 'type': 'argument_list', 'children': ['230']},{'id': '230', 'type': 'call', 'children': ['231', '234']},{'id': '231', 'type': 'attribute', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'G'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'out_edges'},{'id': '234', 'type': 'argument_list', 'children': ['235']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '236', 'type': 'integer', 'children': [], 'value': '0'},{'id': '237', 'type': 'integer', 'children': [], 'value': '1'},{'id': '238', 'type': 'while_statement', 'children': ['239', '257']},{'id': '239', 'type': '()', 'children': ['240']},{'id': '240', 'type': 'boolean_operator', 'children': ['241', '249'], 'value': 'and'},{'id': '241', 'type': 'comparison_operator', 'children': ['242', '248'], 'value': '=='},{'id': '242', 'type': 'call', 'children': ['243', '246']},{'id': '243', 'type': 'attribute', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'G'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'in_degree'},{'id': '246', 'type': 'argument_list', 'children': ['247']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'upper_link'},{'id': '248', 'type': 'integer', 'children': [], 'value': '1'},{'id': '249', 'type': 'comparison_operator', 'children': ['250', '256'], 'value': '=='},{'id': '250', 'type': 'call', 'children': ['251', '254']},{'id': '251', 'type': 'attribute', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'G'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'out_degree'},{'id': '254', 'type': 'argument_list', 'children': ['255']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'upper_link'},{'id': '256', 'type': 'integer', 'children': [], 'value': '1'},{'id': '257', 'type': 'block', 'children': ['258', '274', '282', '289', '296']},{'id': '258', 'type': 'expression_statement', 'children': ['259']},{'id': '259', 'type': 'assignment', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'new_upper_link'},{'id': '261', 'type': 'subscript', 'children': ['262', '273']},{'id': '262', 'type': 'subscript', 'children': ['263', '272']},{'id': '263', 'type': 'call', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '265', 'type': 'argument_list', 'children': ['266']},{'id': '266', 'type': 'call', 'children': ['267', '270']},{'id': '267', 'type': 'attribute', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'G'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'out_edges'},{'id': '270', 'type': 'argument_list', 'children': ['271']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'upper_link'},{'id': '272', 'type': 'integer', 'children': [], 'value': '0'},{'id': '273', 'type': 'integer', 'children': [], 'value': '1'},{'id': '274', 'type': 'expression_statement', 'children': ['275']},{'id': '275', 'type': 'call', 'children': ['276', '279']},{'id': '276', 'type': 'attribute', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'G'},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'add_edge'},{'id': '279', 'type': 'argument_list', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'new_upper_link'},{'id': '282', 'type': 'expression_statement', 'children': ['283']},{'id': '283', 'type': 'call', 'children': ['284', '287']},{'id': '284', 'type': 'attribute', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'G'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'remove_node'},{'id': '287', 'type': 'argument_list', 'children': ['288']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'upper_link'},{'id': '289', 'type': 'expression_statement', 'children': ['290']},{'id': '290', 'type': 'call', 'children': ['291', '294']},{'id': '291', 'type': 'attribute', 'children': ['292', '293']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'removedNodes'},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '294', 'type': 'argument_list', 'children': ['295']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'upper_link'},{'id': '296', 'type': 'expression_statement', 'children': ['297']},{'id': '297', 'type': 'assignment', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'upper_link'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'new_upper_link'},{'id': '300', 'type': 'expression_statement', 'children': ['301']},{'id': '301', 'type': 'call', 'children': ['302', '305']},{'id': '302', 'type': 'attribute', 'children': ['303', '304']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'G'},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'add_edge'},{'id': '305', 'type': 'argument_list', 'children': ['306', '307']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'lower_link'},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'upper_link'},{'id': '308', 'type': 'expression_statement', 'children': ['309']},{'id': '309', 'type': 'call', 'children': ['310', '313']},{'id': '310', 'type': 'attribute', 'children': ['311', '312']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'G'},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'remove_node'},{'id': '313', 'type': 'argument_list', 'children': ['314']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '315', 'type': 'expression_statement', 'children': ['316']},{'id': '316', 'type': 'assignment', 'children': ['317', '324']},{'id': '317', 'type': 'subscript', 'children': ['318', '321']},{'id': '318', 'type': 'attribute', 'children': ['319', '320']},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'augmentedEdges'},{'id': '321', 'type': 'tuple', 'children': ['322', '323']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'lower_link'},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'upper_link'},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'removedNodes'},{'id': '325', 'type': 'expression_statement', 'children': ['326']},{'id': '326', 'type': 'assignment', 'children': ['327', '330']},{'id': '327', 'type': 'subscript', 'children': ['328', '329']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'processed'},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'removedNodes'},{'id': '330', 'type': 'integer', 'children': [], 'value': '1'},{'id': '331', 'type': 'expression_statement', 'children': ['332']},{'id': '332', 'type': 'assignment', 'children': ['333', '336']},{'id': '333', 'type': 'attribute', 'children': ['334', '335']},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'superNodes'},{'id': '336', 'type': 'call', 'children': ['337', '340']},{'id': '337', 'type': 'attribute', 'children': ['338', '339']},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'G'},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '340', 'type': 'argument_list', 'children': []},{'id': '341', 'type': 'expression_statement', 'children': ['342']},{'id': '342', 'type': 'assignment', 'children': ['343', '346']},{'id': '343', 'type': 'attribute', 'children': ['344', '345']},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'superArcs'},{'id': '346', 'type': 'call', 'children': ['347', '350']},{'id': '347', 'type': 'attribute', 'children': ['348', '349']},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'G'},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'edges'},{'id': '350', 'type': 'argument_list', 'children': []},{'id': '351', 'type': 'if_statement', 'children': ['352', '355']},{'id': '352', 'type': 'attribute', 'children': ['353', '354']},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '355', 'type': 'block', 'children': ['356', '364']},{'id': '356', 'type': 'expression_statement', 'children': ['357']},{'id': '357', 'type': 'assignment', 'children': ['358', '359']},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '359', 'type': 'call', 'children': ['360', '363']},{'id': '360', 'type': 'attribute', 'children': ['361', '362']},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '362', 'type': 'identifier', 'children': [], 'value': 'clock'},{'id': '363', 'type': 'argument_list', 'children': []},{'id': '364', 'type': 'expression_statement', 'children': ['365']},{'id': '365', 'type': 'call', 'children': ['366', '371']},{'id': '366', 'type': 'attribute', 'children': ['367', '370']},{'id': '367', 'type': 'attribute', 'children': ['368', '369']},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '369', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '370', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '371', 'type': 'argument_list', 'children': ['372']},{'id': '372', 'type': 'binary_operator', 'children': ['373', '374'], 'value': '%'},{'id': '373', 'type': 'string', 'children': [], 'value': '"%f s\\n"'},{'id': '374', 'type': '()', 'children': ['375']},{'id': '375', 'type': 'binary_operator', 'children': ['376', '377'], 'value': '-'},{'id': '376', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '377', 'type': 'identifier', 'children': [], 'value': 'start'}
def _identifySuperGraph(self): 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() return self.augmentedEdges = {} N = len(self.Y) processed = np.zeros(N) for node in range(N): if processed[node]: continue if G.in_degree(node) == 1 and G.out_degree(node) == 1: removedNodes = [] 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) 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 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))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_construct_nx_tree'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'thisTree'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'thatTree'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '32', '40', '49', '53', '68', '175', '202']},{'id': '10', 'type': 'if_statement', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '14', 'type': 'block', 'children': ['15', '24']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'call', 'children': ['17', '22']},{'id': '17', 'type': 'attribute', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'string', 'children': [], 'value': '"Networkx Tree construction: "'},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'clock'},{'id': '31', 'type': 'argument_list', 'children': []},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'nxTree'},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'nx'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'DiGraph'},{'id': '39', 'type': 'argument_list', 'children': []},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'nxTree'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'add_edges_from'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'thisTree'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'edges'},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'nodesOfThatTree'},{'id': '52', 'type': 'list', 'children': [], 'value': '[]'},{'id': '53', 'type': 'if_statement', 'children': ['54', '57']},{'id': '54', 'type': 'comparison_operator', 'children': ['55', '56'], 'value': 'is'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'thatTree'},{'id': '56', 'type': 'None', 'children': []},{'id': '57', 'type': 'block', 'children': ['58']},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'nodesOfThatTree'},{'id': '61', 'type': 'call', 'children': ['62', '67']},{'id': '62', 'type': 'attribute', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'thatTree'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '67', 'type': 'argument_list', 'children': []},{'id': '68', 'type': 'for_statement', 'children': ['69', '74', '81']},{'id': '69', 'type': 'pattern_list', 'children': ['70', '73']},{'id': '70', 'type': 'tuple_pattern', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'superNode'},{'id': '72', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '74', 'type': 'call', 'children': ['75', '80']},{'id': '75', 'type': 'attribute', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'thisTree'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'augmentedEdges'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '80', 'type': 'argument_list', 'children': []},{'id': '81', 'type': 'block', 'children': ['82', '94', '117', '125', '129', '137', '162']},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'assignment', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'superNodeEdge'},{'id': '85', 'type': 'call', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'call', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'nxTree'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'out_edges'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'superNode'},{'id': '94', 'type': 'if_statement', 'children': ['95', '101']},{'id': '95', 'type': 'comparison_operator', 'children': ['96', '100'], 'value': '>'},{'id': '96', 'type': 'call', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'superNodeEdge'},{'id': '100', 'type': 'integer', 'children': [], 'value': '1'},{'id': '101', 'type': 'block', 'children': ['102']},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'call', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'warnings'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'warn'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'call', 'children': ['109', '115']},{'id': '109', 'type': 'attribute', 'children': ['110', '114']},{'id': '110', 'type': 'concatenated_string', 'children': ['111', '112', '113']},{'id': '111', 'type': 'string', 'children': [], 'value': '"The supernode {} should have only a single "'},{'id': '112', 'type': 'string', 'children': [], 'value': '"emanating edge. Merge tree is invalidly "'},{'id': '113', 'type': 'string', 'children': [], 'value': '"structured"'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '115', 'type': 'argument_list', 'children': ['116']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'superNode'},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'endNode'},{'id': '120', 'type': 'subscript', 'children': ['121', '124']},{'id': '121', 'type': 'subscript', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'superNodeEdge'},{'id': '123', 'type': 'integer', 'children': [], 'value': '0'},{'id': '124', 'type': 'integer', 'children': [], 'value': '1'},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'assignment', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'startNode'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'superNode'},{'id': '129', 'type': 'expression_statement', 'children': ['130']},{'id': '130', 'type': 'call', 'children': ['131', '134']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'nxTree'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'remove_edge'},{'id': '134', 'type': 'argument_list', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'startNode'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'endNode'},{'id': '137', 'type': 'for_statement', 'children': ['138', '139', '140']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '140', 'type': 'block', 'children': ['141']},{'id': '141', 'type': 'if_statement', 'children': ['142', '149']},{'id': '142', 'type': 'boolean_operator', 'children': ['143', '146'], 'value': 'or'},{'id': '143', 'type': 'comparison_operator', 'children': ['144', '145'], 'value': 'is'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'thatTree'},{'id': '145', 'type': 'None', 'children': []},{'id': '146', 'type': 'comparison_operator', 'children': ['147', '148'], 'value': 'in'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'nodesOfThatTree'},{'id': '149', 'type': 'block', 'children': ['150', '158']},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'call', 'children': ['152', '155']},{'id': '152', 'type': 'attribute', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'nxTree'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'add_edge'},{'id': '155', 'type': 'argument_list', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'startNode'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '158', 'type': 'expression_statement', 'children': ['159']},{'id': '159', 'type': 'assignment', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'startNode'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '162', 'type': 'if_statement', 'children': ['163', '166']},{'id': '163', 'type': 'comparison_operator', 'children': ['164', '165'], 'value': '!='},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'startNode'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'endNode'},{'id': '166', 'type': 'block', 'children': ['167']},{'id': '167', 'type': 'expression_statement', 'children': ['168']},{'id': '168', 'type': 'call', 'children': ['169', '172']},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'nxTree'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'add_edge'},{'id': '172', 'type': 'argument_list', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'startNode'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'endNode'},{'id': '175', 'type': 'if_statement', 'children': ['176', '179']},{'id': '176', 'type': 'attribute', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '179', 'type': 'block', 'children': ['180', '188']},{'id': '180', 'type': 'expression_statement', 'children': ['181']},{'id': '181', 'type': 'assignment', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '183', 'type': 'call', 'children': ['184', '187']},{'id': '184', 'type': 'attribute', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'clock'},{'id': '187', 'type': 'argument_list', 'children': []},{'id': '188', 'type': 'expression_statement', 'children': ['189']},{'id': '189', 'type': 'call', 'children': ['190', '195']},{'id': '190', 'type': 'attribute', 'children': ['191', '194']},{'id': '191', 'type': 'attribute', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '195', 'type': 'argument_list', 'children': ['196']},{'id': '196', 'type': 'binary_operator', 'children': ['197', '198'], 'value': '%'},{'id': '197', 'type': 'string', 'children': [], 'value': '"%f s\\n"'},{'id': '198', 'type': '()', 'children': ['199']},{'id': '199', 'type': 'binary_operator', 'children': ['200', '201'], 'value': '-'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '202', 'type': 'return_statement', 'children': ['203']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'nxTree'}
def _construct_nx_tree(self, thisTree, thatTree=None): 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() 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 if startNode != endNode: nxTree.add_edge(startNode, endNode) if self.debug: end = time.clock() sys.stdout.write("%f s\n" % (end - start)) return nxTree
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_process_tree'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'thisTree'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'thatTree'},{'id': '7', 'type': 'block', 'children': ['8', '30', '83', '359']},{'id': '8', 'type': 'if_statement', 'children': ['9', '12']},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '12', 'type': 'block', 'children': ['13', '22']},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'call', 'children': ['15', '20']},{'id': '15', 'type': 'attribute', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'string', 'children': [], 'value': '"Processing Tree: "'},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '25', 'type': 'call', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'clock'},{'id': '29', 'type': 'argument_list', 'children': []},{'id': '30', 'type': 'if_statement', 'children': ['31', '41', '75']},{'id': '31', 'type': 'comparison_operator', 'children': ['32', '40'], 'value': '>'},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'thisTree'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '39', 'type': 'argument_list', 'children': []},{'id': '40', 'type': 'integer', 'children': [], 'value': '1'},{'id': '41', 'type': 'block', 'children': ['42']},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'leaves'},{'id': '45', 'type': 'call', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'list_comprehension', 'children': ['49', '50', '57']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '50', 'type': 'for_in_clause', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '52', 'type': 'call', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'thisTree'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '56', 'type': 'argument_list', 'children': []},{'id': '57', 'type': 'if_clause', 'children': ['58']},{'id': '58', 'type': 'boolean_operator', 'children': ['59', '67'], 'value': 'and'},{'id': '59', 'type': 'comparison_operator', 'children': ['60', '66'], 'value': '=='},{'id': '60', 'type': 'call', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'thisTree'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'in_degree'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '66', 'type': 'integer', 'children': [], 'value': '0'},{'id': '67', 'type': 'comparison_operator', 'children': ['68', '74'], 'value': '<'},{'id': '68', 'type': 'call', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'thatTree'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'in_degree'},{'id': '72', 'type': 'argument_list', 'children': ['73']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '74', 'type': 'integer', 'children': [], 'value': '2'},{'id': '75', 'type': 'else_clause', 'children': ['76']},{'id': '76', 'type': 'block', 'children': ['77']},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'leaves'},{'id': '80', 'type': 'call', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '82', 'type': 'argument_list', 'children': []},{'id': '83', 'type': 'while_statement', 'children': ['84', '90']},{'id': '84', 'type': 'comparison_operator', 'children': ['85', '89'], 'value': '>'},{'id': '85', 'type': 'call', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'leaves'},{'id': '89', 'type': 'integer', 'children': [], 'value': '0'},{'id': '90', 'type': 'block', 'children': ['91', '99', '111', '133', '141', '149', '186', '193', '306']},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '94', 'type': 'call', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'leaves'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '98', 'type': 'argument_list', 'children': []},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'assignment', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'edges'},{'id': '102', 'type': 'call', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '104', 'type': 'argument_list', 'children': ['105']},{'id': '105', 'type': 'call', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'thisTree'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'out_edges'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '111', 'type': 'if_statement', 'children': ['112', '118']},{'id': '112', 'type': 'comparison_operator', 'children': ['113', '117'], 'value': '!='},{'id': '113', 'type': 'call', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '115', 'type': 'argument_list', 'children': ['116']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'edges'},{'id': '117', 'type': 'integer', 'children': [], 'value': '1'},{'id': '118', 'type': 'block', 'children': ['119']},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'call', 'children': ['121', '124']},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'warnings'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'warn'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'call', 'children': ['126', '131']},{'id': '126', 'type': 'attribute', 'children': ['127', '130']},{'id': '127', 'type': 'concatenated_string', 'children': ['128', '129']},{'id': '128', 'type': 'string', 'children': [], 'value': '"The node {} should have a single emanating "'},{'id': '129', 'type': 'string', 'children': [], 'value': '"edge.\\n"'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '131', 'type': 'argument_list', 'children': ['132']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'assignment', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'e1'},{'id': '136', 'type': 'subscript', 'children': ['137', '140']},{'id': '137', 'type': 'subscript', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'edges'},{'id': '139', 'type': 'integer', 'children': [], 'value': '0'},{'id': '140', 'type': 'integer', 'children': [], 'value': '0'},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'assignment', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'e2'},{'id': '144', 'type': 'subscript', 'children': ['145', '148']},{'id': '145', 'type': 'subscript', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'edges'},{'id': '147', 'type': 'integer', 'children': [], 'value': '0'},{'id': '148', 'type': 'integer', 'children': [], 'value': '1'},{'id': '149', 'type': 'if_statement', 'children': ['150', '161', '173']},{'id': '150', 'type': 'comparison_operator', 'children': ['151', '156'], 'value': '<'},{'id': '151', 'type': 'subscript', 'children': ['152', '155']},{'id': '152', 'type': 'attribute', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'Y'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'e1'},{'id': '156', 'type': 'subscript', 'children': ['157', '160']},{'id': '157', 'type': 'attribute', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'Y'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'e2'},{'id': '161', 'type': 'block', 'children': ['162']},{'id': '162', 'type': 'expression_statement', 'children': ['163']},{'id': '163', 'type': 'call', 'children': ['164', '169']},{'id': '164', 'type': 'attribute', 'children': ['165', '168']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'edges'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '169', 'type': 'argument_list', 'children': ['170']},{'id': '170', 'type': 'tuple', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'e1'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'e2'},{'id': '173', 'type': 'else_clause', 'children': ['174']},{'id': '174', 'type': 'block', 'children': ['175']},{'id': '175', 'type': 'expression_statement', 'children': ['176']},{'id': '176', 'type': 'call', 'children': ['177', '182']},{'id': '177', 'type': 'attribute', 'children': ['178', '181']},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'edges'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '182', 'type': 'argument_list', 'children': ['183']},{'id': '183', 'type': 'tuple', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'e2'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'e1'},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'call', 'children': ['188', '191']},{'id': '188', 'type': 'attribute', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'thisTree'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'remove_node'},{'id': '191', 'type': 'argument_list', 'children': ['192']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '193', 'type': 'if_statement', 'children': ['194', '202', '210']},{'id': '194', 'type': 'comparison_operator', 'children': ['195', '201'], 'value': '=='},{'id': '195', 'type': 'call', 'children': ['196', '199']},{'id': '196', 'type': 'attribute', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'thatTree'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'out_degree'},{'id': '199', 'type': 'argument_list', 'children': ['200']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '201', 'type': 'integer', 'children': [], 'value': '0'},{'id': '202', 'type': 'block', 'children': ['203']},{'id': '203', 'type': 'expression_statement', 'children': ['204']},{'id': '204', 'type': 'call', 'children': ['205', '208']},{'id': '205', 'type': 'attribute', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'thatTree'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'remove_node'},{'id': '208', 'type': 'argument_list', 'children': ['209']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '210', 'type': 'else_clause', 'children': ['211']},{'id': '211', 'type': 'block', 'children': ['212', '247', '282', '299']},{'id': '212', 'type': 'if_statement', 'children': ['213', '224', '241']},{'id': '213', 'type': 'comparison_operator', 'children': ['214', '223'], 'value': '>'},{'id': '214', 'type': 'call', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '216', 'type': 'argument_list', 'children': ['217']},{'id': '217', 'type': 'call', 'children': ['218', '221']},{'id': '218', 'type': 'attribute', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'thatTree'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'in_edges'},{'id': '221', 'type': 'argument_list', 'children': ['222']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '223', 'type': 'integer', 'children': [], 'value': '0'},{'id': '224', 'type': 'block', 'children': ['225']},{'id': '225', 'type': 'expression_statement', 'children': ['226']},{'id': '226', 'type': 'assignment', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'startNode'},{'id': '228', 'type': 'subscript', 'children': ['229', '240']},{'id': '229', 'type': 'subscript', 'children': ['230', '239']},{'id': '230', 'type': 'call', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '232', 'type': 'argument_list', 'children': ['233']},{'id': '233', 'type': 'call', 'children': ['234', '237']},{'id': '234', 'type': 'attribute', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'thatTree'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'in_edges'},{'id': '237', 'type': 'argument_list', 'children': ['238']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '239', 'type': 'integer', 'children': [], 'value': '0'},{'id': '240', 'type': 'integer', 'children': [], 'value': '0'},{'id': '241', 'type': 'else_clause', 'children': ['242']},{'id': '242', 'type': 'block', 'children': ['243']},{'id': '243', 'type': 'expression_statement', 'children': ['244']},{'id': '244', 'type': 'assignment', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'startNode'},{'id': '246', 'type': 'None', 'children': []},{'id': '247', 'type': 'if_statement', 'children': ['248', '259', '276']},{'id': '248', 'type': 'comparison_operator', 'children': ['249', '258'], 'value': '>'},{'id': '249', 'type': 'call', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '251', 'type': 'argument_list', 'children': ['252']},{'id': '252', 'type': 'call', 'children': ['253', '256']},{'id': '253', 'type': 'attribute', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'thatTree'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'out_edges'},{'id': '256', 'type': 'argument_list', 'children': ['257']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '258', 'type': 'integer', 'children': [], 'value': '0'},{'id': '259', 'type': 'block', 'children': ['260']},{'id': '260', 'type': 'expression_statement', 'children': ['261']},{'id': '261', 'type': 'assignment', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'endNode'},{'id': '263', 'type': 'subscript', 'children': ['264', '275']},{'id': '264', 'type': 'subscript', 'children': ['265', '274']},{'id': '265', 'type': 'call', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '267', 'type': 'argument_list', 'children': ['268']},{'id': '268', 'type': 'call', 'children': ['269', '272']},{'id': '269', 'type': 'attribute', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'thatTree'},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'out_edges'},{'id': '272', 'type': 'argument_list', 'children': ['273']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '274', 'type': 'integer', 'children': [], 'value': '0'},{'id': '275', 'type': 'integer', 'children': [], 'value': '1'},{'id': '276', 'type': 'else_clause', 'children': ['277']},{'id': '277', 'type': 'block', 'children': ['278']},{'id': '278', 'type': 'expression_statement', 'children': ['279']},{'id': '279', 'type': 'assignment', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'endNode'},{'id': '281', 'type': 'None', 'children': []},{'id': '282', 'type': 'if_statement', 'children': ['283', '290']},{'id': '283', 'type': 'boolean_operator', 'children': ['284', '287'], 'value': 'and'},{'id': '284', 'type': 'comparison_operator', 'children': ['285', '286'], 'value': 'is'},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'startNode'},{'id': '286', 'type': 'None', 'children': []},{'id': '287', 'type': 'comparison_operator', 'children': ['288', '289'], 'value': 'is'},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'endNode'},{'id': '289', 'type': 'None', 'children': []},{'id': '290', 'type': 'block', 'children': ['291']},{'id': '291', 'type': 'expression_statement', 'children': ['292']},{'id': '292', 'type': 'call', 'children': ['293', '296']},{'id': '293', 'type': 'attribute', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'thatTree'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'add_edge'},{'id': '296', 'type': 'argument_list', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'startNode'},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'endNode'},{'id': '299', 'type': 'expression_statement', 'children': ['300']},{'id': '300', 'type': 'call', 'children': ['301', '304']},{'id': '301', 'type': 'attribute', 'children': ['302', '303']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'thatTree'},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'remove_node'},{'id': '304', 'type': 'argument_list', 'children': ['305']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '306', 'type': 'if_statement', 'children': ['307', '317', '351']},{'id': '307', 'type': 'comparison_operator', 'children': ['308', '316'], 'value': '>'},{'id': '308', 'type': 'call', 'children': ['309', '310']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '310', 'type': 'argument_list', 'children': ['311']},{'id': '311', 'type': 'call', 'children': ['312', '315']},{'id': '312', 'type': 'attribute', 'children': ['313', '314']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'thisTree'},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '315', 'type': 'argument_list', 'children': []},{'id': '316', 'type': 'integer', 'children': [], 'value': '1'},{'id': '317', 'type': 'block', 'children': ['318']},{'id': '318', 'type': 'expression_statement', 'children': ['319']},{'id': '319', 'type': 'assignment', 'children': ['320', '321']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'leaves'},{'id': '321', 'type': 'call', 'children': ['322', '323']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '323', 'type': 'argument_list', 'children': ['324']},{'id': '324', 'type': 'list_comprehension', 'children': ['325', '326', '333']},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '326', 'type': 'for_in_clause', 'children': ['327', '328']},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '328', 'type': 'call', 'children': ['329', '332']},{'id': '329', 'type': 'attribute', 'children': ['330', '331']},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'thisTree'},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '332', 'type': 'argument_list', 'children': []},{'id': '333', 'type': 'if_clause', 'children': ['334']},{'id': '334', 'type': 'boolean_operator', 'children': ['335', '343'], 'value': 'and'},{'id': '335', 'type': 'comparison_operator', 'children': ['336', '342'], 'value': '=='},{'id': '336', 'type': 'call', 'children': ['337', '340']},{'id': '337', 'type': 'attribute', 'children': ['338', '339']},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'thisTree'},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'in_degree'},{'id': '340', 'type': 'argument_list', 'children': ['341']},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '342', 'type': 'integer', 'children': [], 'value': '0'},{'id': '343', 'type': 'comparison_operator', 'children': ['344', '350'], 'value': '<'},{'id': '344', 'type': 'call', 'children': ['345', '348']},{'id': '345', 'type': 'attribute', 'children': ['346', '347']},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'thatTree'},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'in_degree'},{'id': '348', 'type': 'argument_list', 'children': ['349']},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '350', 'type': 'integer', 'children': [], 'value': '2'},{'id': '351', 'type': 'else_clause', 'children': ['352']},{'id': '352', 'type': 'block', 'children': ['353']},{'id': '353', 'type': 'expression_statement', 'children': ['354']},{'id': '354', 'type': 'assignment', 'children': ['355', '356']},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'leaves'},{'id': '356', 'type': 'call', 'children': ['357', '358']},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '358', 'type': 'argument_list', 'children': []},{'id': '359', 'type': 'if_statement', 'children': ['360', '363']},{'id': '360', 'type': 'attribute', 'children': ['361', '362']},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '362', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '363', 'type': 'block', 'children': ['364', '372']},{'id': '364', 'type': 'expression_statement', 'children': ['365']},{'id': '365', 'type': 'assignment', 'children': ['366', '367']},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '367', 'type': 'call', 'children': ['368', '371']},{'id': '368', 'type': 'attribute', 'children': ['369', '370']},{'id': '369', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '370', 'type': 'identifier', 'children': [], 'value': 'clock'},{'id': '371', 'type': 'argument_list', 'children': []},{'id': '372', 'type': 'expression_statement', 'children': ['373']},{'id': '373', 'type': 'call', 'children': ['374', '379']},{'id': '374', 'type': 'attribute', 'children': ['375', '378']},{'id': '375', 'type': 'attribute', 'children': ['376', '377']},{'id': '376', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '377', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '378', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '379', 'type': 'argument_list', 'children': ['380']},{'id': '380', 'type': 'binary_operator', 'children': ['381', '382'], 'value': '%'},{'id': '381', 'type': 'string', 'children': [], 'value': '"%f s\\n"'},{'id': '382', 'type': '()', 'children': ['383']},{'id': '383', 'type': 'binary_operator', 'children': ['384', '385'], 'value': '-'},{'id': '384', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '385', 'type': 'identifier', 'children': [], 'value': 'start'}
def _process_tree(self, thisTree, thatTree): if self.debug: sys.stdout.write("Processing Tree: ") start = time.clock() 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() 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] if self.Y[e1] < self.Y[e2]: self.edges.append((e1, e2)) else: self.edges.append((e2, e1)) thisTree.remove_node(v) if thatTree.out_degree(v) == 0: thatTree.remove_node(v) else: if len(thatTree.in_edges(v)) > 0: startNode = list(thatTree.in_edges(v))[0][0] else: startNode = None if len(thatTree.out_edges(v)) > 0: endNode = list(thatTree.out_edges(v))[0][1] else: endNode = None if startNode is not None and endNode is not None: thatTree.add_edge(startNode, endNode) thatTree.remove_node(v) 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: end = time.clock() sys.stdout.write("%f s\n" % (end - start))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_project_content_commit_date'},{'id': '3', 'type': 'parameters', 'children': ['4', '7']},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'root_dir'},{'id': '6', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'exclusions'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'block', 'children': ['11', '20', '31', '35', '49', '61', '92', '109', '123', '127', '165', '174', '181']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '14', 'type': 'call', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'getLogger'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'extensions'},{'id': '23', 'type': 'tuple', 'children': ['24', '25', '26', '27', '28', '29', '30']},{'id': '24', 'type': 'string', 'children': [], 'value': "'rst'"},{'id': '25', 'type': 'string', 'children': [], 'value': "'ipynb'"},{'id': '26', 'type': 'string', 'children': [], 'value': "'png'"},{'id': '27', 'type': 'string', 'children': [], 'value': "'jpeg'"},{'id': '28', 'type': 'string', 'children': [], 'value': "'jpg'"},{'id': '29', 'type': 'string', 'children': [], 'value': "'svg'"},{'id': '30', 'type': 'string', 'children': [], 'value': "'gif'"},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'content_paths'},{'id': '34', 'type': 'list', 'children': [], 'value': '[]'},{'id': '35', 'type': 'for_statement', 'children': ['36', '37', '38']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'extname'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'extensions'},{'id': '38', 'type': 'block', 'children': ['39']},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'augmented_assignment', 'children': ['41', '42'], 'value': '+='},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'content_paths'},{'id': '42', 'type': 'call', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'get_filepaths_with_extension'},{'id': '44', 'type': 'argument_list', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'extname'},{'id': '46', 'type': 'keyword_argument', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'root_dir'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'root_dir'},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'exclude'},{'id': '52', 'type': 'call', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'Matcher'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'conditional_expression', 'children': ['56', '57', '58'], 'value': 'if'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'exclusions'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'exclusions'},{'id': '58', 'type': 'list', 'children': ['59', '60'], 'value': "['readme.rst', 'license.rst']"},{'id': '59', 'type': 'string', 'children': [], 'value': "'readme.rst'"},{'id': '60', 'type': 'string', 'children': [], 'value': "'license.rst'"},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'content_paths'},{'id': '64', 'type': 'list_comprehension', 'children': ['65', '66', '69']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '66', 'type': 'for_in_clause', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'content_paths'},{'id': '69', 'type': 'if_clause', 'children': ['70']},{'id': '70', 'type': 'not_operator', 'children': ['71']},{'id': '71', 'type': '()', 'children': ['72']},{'id': '72', 'type': 'boolean_operator', 'children': ['73', '77'], 'value': 'or'},{'id': '73', 'type': 'call', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'exclude'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '77', 'type': 'call', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'exclude'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'subscript', 'children': ['81', '91']},{'id': '81', 'type': 'call', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'attribute', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'sep'},{'id': '91', 'type': 'integer', 'children': [], 'value': '0'},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'call', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'call', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'string', 'children': [], 'value': "'Found content paths: {}'"},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '102', 'type': 'argument_list', 'children': ['103']},{'id': '103', 'type': 'call', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'string', 'children': [], 'value': "', '"},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'content_paths'},{'id': '109', 'type': 'if_statement', 'children': ['110', '112']},{'id': '110', 'type': 'not_operator', 'children': ['111']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'content_paths'},{'id': '112', 'type': 'block', 'children': ['113']},{'id': '113', 'type': 'raise_statement', 'children': ['114']},{'id': '114', 'type': 'call', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'},{'id': '116', 'type': 'argument_list', 'children': ['117']},{'id': '117', 'type': 'call', 'children': ['118', '121']},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'string', 'children': [], 'value': "'No content files found in {}'"},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '121', 'type': 'argument_list', 'children': ['122']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'root_dir'},{'id': '123', 'type': 'expression_statement', 'children': ['124']},{'id': '124', 'type': 'assignment', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'commit_datetimes'},{'id': '126', 'type': 'list', 'children': [], 'value': '[]'},{'id': '127', 'type': 'for_statement', 'children': ['128', '129', '130']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'filepath'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'content_paths'},{'id': '130', 'type': 'block', 'children': ['131']},{'id': '131', 'type': 'try_statement', 'children': ['132', '150']},{'id': '132', 'type': 'block', 'children': ['133', '143']},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'assignment', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '136', 'type': 'call', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'read_git_commit_timestamp_for_file'},{'id': '138', 'type': 'argument_list', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'filepath'},{'id': '140', 'type': 'keyword_argument', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'repo_path'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'root_dir'},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'call', 'children': ['145', '148']},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'commit_datetimes'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '148', 'type': 'argument_list', 'children': ['149']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '150', 'type': 'except_clause', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'IOError'},{'id': '152', 'type': 'block', 'children': ['153']},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'call', 'children': ['155', '158']},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '158', 'type': 'argument_list', 'children': ['159']},{'id': '159', 'type': 'call', 'children': ['160', '163']},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'string', 'children': [], 'value': "'Could not get commit for {}, skipping'"},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '163', 'type': 'argument_list', 'children': ['164']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'filepath'},{'id': '165', 'type': 'if_statement', 'children': ['166', '168']},{'id': '166', 'type': 'not_operator', 'children': ['167']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'commit_datetimes'},{'id': '168', 'type': 'block', 'children': ['169']},{'id': '169', 'type': 'raise_statement', 'children': ['170']},{'id': '170', 'type': 'call', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'},{'id': '172', 'type': 'argument_list', 'children': ['173']},{'id': '173', 'type': 'string', 'children': [], 'value': "'No content commits could be found'"},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'id': '175', 'type': 'assignment', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'latest_datetime'},{'id': '177', 'type': 'call', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '179', 'type': 'argument_list', 'children': ['180']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'commit_datetimes'},{'id': '181', 'type': 'return_statement', 'children': ['182']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'latest_datetime'}
def get_project_content_commit_date(root_dir='.', exclusions=None): logger = logging.getLogger(__name__) 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) exclude = Matcher(exclusions if exclusions else ['readme.rst', 'license.rst']) 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
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_table'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '6', 'type': 'block', 'children': ['7', '91', '151', '173', '198']},{'id': '7', 'type': 'if_statement', 'children': ['8', '11']},{'id': '8', 'type': 'comparison_operator', 'children': ['9', '10'], 'value': 'is'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'block', 'children': ['12', '17', '25', '54', '86']},{'id': '12', 'type': 'assert_statement', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'active_table'},{'id': '16', 'type': 'string', 'children': [], 'value': '"Can\'t get table without name unless an active table is set"'},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '20', 'type': 'attribute', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'active_table'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '25', 'type': 'if_statement', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'active_worksheet'},{'id': '29', 'type': 'block', 'children': ['30', '41', '48']},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '33', 'type': 'call', 'children': ['34', '39']},{'id': '34', 'type': 'attribute', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'active_worksheet'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'get_table'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '41', 'type': 'assert_statement', 'children': ['42', '47']},{'id': '42', 'type': 'comparison_operator', 'children': ['43', '44'], 'value': 'is'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'active_table'},{'id': '47', 'type': 'string', 'children': [], 'value': '"Active table is not from the active sheet"'},{'id': '48', 'type': 'return_statement', 'children': ['49']},{'id': '49', 'type': 'expression_list', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'active_worksheet'},{'id': '54', 'type': 'for_statement', 'children': ['55', '56', '59']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'ws'},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'worksheets'},{'id': '59', 'type': 'block', 'children': ['60']},{'id': '60', 'type': 'try_statement', 'children': ['61', '82']},{'id': '61', 'type': 'block', 'children': ['62', '71']},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '65', 'type': 'call', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'ws'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'get_table'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '71', 'type': 'if_statement', 'children': ['72', '77']},{'id': '72', 'type': 'comparison_operator', 'children': ['73', '74'], 'value': 'is'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'active_table'},{'id': '77', 'type': 'block', 'children': ['78']},{'id': '78', 'type': 'return_statement', 'children': ['79']},{'id': '79', 'type': 'expression_list', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'ws'},{'id': '82', 'type': 'except_clause', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '84', 'type': 'block', 'children': ['85']},{'id': '85', 'type': 'pass_statement', 'children': []},{'id': '86', 'type': 'raise_statement', 'children': ['87']},{'id': '87', 'type': 'call', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'string', 'children': [], 'value': '"Active table not found in any sheet"'},{'id': '91', 'type': 'if_statement', 'children': ['92', '95']},{'id': '92', 'type': 'comparison_operator', 'children': ['93', '94'], 'value': 'in'},{'id': '93', 'type': 'string', 'children': [], 'value': '"!"'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '95', 'type': 'block', 'children': ['96', '120', '146']},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'assignment', 'children': ['98', '101']},{'id': '98', 'type': 'pattern_list', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'ws_name'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'table_name'},{'id': '101', 'type': 'call', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '103', 'type': 'argument_list', 'children': ['104', '113']},{'id': '104', 'type': 'lambda', 'children': ['105', '107']},{'id': '105', 'type': 'lambda_parameters', 'children': ['106']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '107', 'type': 'call', 'children': ['108', '111']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '111', 'type': 'argument_list', 'children': ['112']},{'id': '112', 'type': 'string', 'children': [], 'value': '"\'"'},{'id': '113', 'type': 'call', 'children': ['114', '117']},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '117', 'type': 'argument_list', 'children': ['118', '119']},{'id': '118', 'type': 'string', 'children': [], 'value': '"!"'},{'id': '119', 'type': 'integer', 'children': [], 'value': '1'},{'id': '120', 'type': 'for_statement', 'children': ['121', '122', '125']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'ws'},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'worksheets'},{'id': '125', 'type': 'block', 'children': ['126']},{'id': '126', 'type': 'if_statement', 'children': ['127', '132']},{'id': '127', 'type': 'comparison_operator', 'children': ['128', '131'], 'value': '=='},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'ws'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'ws_name'},{'id': '132', 'type': 'block', 'children': ['133', '142']},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'assignment', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '136', 'type': 'call', 'children': ['137', '140']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'ws'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'get_table'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'table_name'},{'id': '142', 'type': 'return_statement', 'children': ['143']},{'id': '143', 'type': 'expression_list', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'ws'},{'id': '146', 'type': 'raise_statement', 'children': ['147']},{'id': '147', 'type': 'call', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '149', 'type': 'argument_list', 'children': ['150']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '151', 'type': 'if_statement', 'children': ['152', '155']},{'id': '152', 'type': 'attribute', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'active_worksheet'},{'id': '155', 'type': 'block', 'children': ['156', '167']},{'id': '156', 'type': 'expression_statement', 'children': ['157']},{'id': '157', 'type': 'assignment', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '159', 'type': 'call', 'children': ['160', '165']},{'id': '160', 'type': 'attribute', 'children': ['161', '164']},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'active_worksheet'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'get_table'},{'id': '165', 'type': 'argument_list', 'children': ['166']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '167', 'type': 'return_statement', 'children': ['168']},{'id': '168', 'type': 'expression_list', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '170', 'type': 'attribute', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'active_worksheet'},{'id': '173', 'type': 'for_statement', 'children': ['174', '175', '178']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'ws'},{'id': '175', 'type': 'attribute', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'worksheets'},{'id': '178', 'type': 'block', 'children': ['179']},{'id': '179', 'type': 'try_statement', 'children': ['180', '194']},{'id': '180', 'type': 'block', 'children': ['181', '190']},{'id': '181', 'type': 'expression_statement', 'children': ['182']},{'id': '182', 'type': 'assignment', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '184', 'type': 'call', 'children': ['185', '188']},{'id': '185', 'type': 'attribute', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'ws'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'get_table'},{'id': '188', 'type': 'argument_list', 'children': ['189']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '190', 'type': 'return_statement', 'children': ['191']},{'id': '191', 'type': 'expression_list', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'ws'},{'id': '194', 'type': 'except_clause', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '196', 'type': 'block', 'children': ['197']},{'id': '197', 'type': 'pass_statement', 'children': []},{'id': '198', 'type': 'raise_statement', 'children': ['199']},{'id': '199', 'type': 'call', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '201', 'type': 'argument_list', 'children': ['202']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'name'}
def get_table(self, name): 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 "!" 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) if self.active_worksheet: table = self.active_worksheet.get_table(name) return table, self.active_worksheet for ws in self.worksheets: try: table = ws.get_table(name) return table, ws except KeyError: pass raise KeyError(name)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'assign_valence'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '5', 'type': 'block', 'children': ['6', '139', '179', '273']},{'id': '6', 'type': 'for_statement', 'children': ['7', '11', '16']},{'id': '7', 'type': 'pattern_list', 'children': ['8', '9', '10']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'bond'},{'id': '11', 'type': 'call', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'bonds_iter'},{'id': '15', 'type': 'argument_list', 'children': []},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'if_statement', 'children': ['18', '23', '112']},{'id': '18', 'type': 'comparison_operator', 'children': ['19', '22'], 'value': '=='},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'bond'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '22', 'type': 'integer', 'children': [], 'value': '2'},{'id': '23', 'type': 'block', 'children': ['24', '35', '46', '79']},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '34']},{'id': '26', 'type': 'attribute', 'children': ['27', '33']},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'pi'},{'id': '34', 'type': 'integer', 'children': [], 'value': '1'},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '45']},{'id': '37', 'type': 'attribute', 'children': ['38', '44']},{'id': '38', 'type': 'call', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'pi'},{'id': '45', 'type': 'integer', 'children': [], 'value': '1'},{'id': '46', 'type': 'if_statement', 'children': ['47', '67']},{'id': '47', 'type': 'boolean_operator', 'children': ['48', '58'], 'value': 'and'},{'id': '48', 'type': 'comparison_operator', 'children': ['49', '57'], 'value': '=='},{'id': '49', 'type': 'attribute', 'children': ['50', '56']},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'symbol'},{'id': '57', 'type': 'string', 'children': [], 'value': '"O"'},{'id': '58', 'type': 'not_operator', 'children': ['59']},{'id': '59', 'type': 'attribute', 'children': ['60', '66']},{'id': '60', 'type': 'call', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'charge'},{'id': '67', 'type': 'block', 'children': ['68']},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '78']},{'id': '70', 'type': 'attribute', 'children': ['71', '77']},{'id': '71', 'type': 'call', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'carbonyl_C'},{'id': '78', 'type': 'integer', 'children': [], 'value': '1'},{'id': '79', 'type': 'if_statement', 'children': ['80', '100']},{'id': '80', 'type': 'boolean_operator', 'children': ['81', '91'], 'value': 'and'},{'id': '81', 'type': 'comparison_operator', 'children': ['82', '90'], 'value': '=='},{'id': '82', 'type': 'attribute', 'children': ['83', '89']},{'id': '83', 'type': 'call', 'children': ['84', '87']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'symbol'},{'id': '90', 'type': 'string', 'children': [], 'value': '"O"'},{'id': '91', 'type': 'not_operator', 'children': ['92']},{'id': '92', 'type': 'attribute', 'children': ['93', '99']},{'id': '93', 'type': 'call', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'charge'},{'id': '100', 'type': 'block', 'children': ['101']},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'assignment', 'children': ['103', '111']},{'id': '103', 'type': 'attribute', 'children': ['104', '110']},{'id': '104', 'type': 'call', 'children': ['105', '108']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '108', 'type': 'argument_list', 'children': ['109']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'carbonyl_C'},{'id': '111', 'type': 'integer', 'children': [], 'value': '1'},{'id': '112', 'type': 'elif_clause', 'children': ['113', '118']},{'id': '113', 'type': 'comparison_operator', 'children': ['114', '117'], 'value': '=='},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'bond'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '117', 'type': 'integer', 'children': [], 'value': '3'},{'id': '118', 'type': 'block', 'children': ['119']},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'assignment', 'children': ['121', '129']},{'id': '121', 'type': 'attribute', 'children': ['122', '128']},{'id': '122', 'type': 'call', 'children': ['123', '126']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '126', 'type': 'argument_list', 'children': ['127']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'pi'},{'id': '129', 'type': 'assignment', 'children': ['130', '138']},{'id': '130', 'type': 'attribute', 'children': ['131', '137']},{'id': '131', 'type': 'call', 'children': ['132', '135']},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '135', 'type': 'argument_list', 'children': ['136']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'pi'},{'id': '138', 'type': 'integer', 'children': [], 'value': '2'},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'id': '140', 'type': 'assignment', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'max_nbr'},{'id': '142', 'type': 'dictionary', 'children': ['143', '146', '149', '152', '155', '158', '161', '164', '167', '170', '173', '176']},{'id': '143', 'type': 'pair', 'children': ['144', '145']},{'id': '144', 'type': 'string', 'children': [], 'value': '"C"'},{'id': '145', 'type': 'integer', 'children': [], 'value': '4'},{'id': '146', 'type': 'pair', 'children': ['147', '148']},{'id': '147', 'type': 'string', 'children': [], 'value': '"Si"'},{'id': '148', 'type': 'integer', 'children': [], 'value': '4'},{'id': '149', 'type': 'pair', 'children': ['150', '151']},{'id': '150', 'type': 'string', 'children': [], 'value': '"N"'},{'id': '151', 'type': 'integer', 'children': [], 'value': '3'},{'id': '152', 'type': 'pair', 'children': ['153', '154']},{'id': '153', 'type': 'string', 'children': [], 'value': '"P"'},{'id': '154', 'type': 'integer', 'children': [], 'value': '3'},{'id': '155', 'type': 'pair', 'children': ['156', '157']},{'id': '156', 'type': 'string', 'children': [], 'value': '"As"'},{'id': '157', 'type': 'integer', 'children': [], 'value': '3'},{'id': '158', 'type': 'pair', 'children': ['159', '160']},{'id': '159', 'type': 'string', 'children': [], 'value': '"O"'},{'id': '160', 'type': 'integer', 'children': [], 'value': '2'},{'id': '161', 'type': 'pair', 'children': ['162', '163']},{'id': '162', 'type': 'string', 'children': [], 'value': '"S"'},{'id': '163', 'type': 'integer', 'children': [], 'value': '2'},{'id': '164', 'type': 'pair', 'children': ['165', '166']},{'id': '165', 'type': 'string', 'children': [], 'value': '"Se"'},{'id': '166', 'type': 'integer', 'children': [], 'value': '2'},{'id': '167', 'type': 'pair', 'children': ['168', '169']},{'id': '168', 'type': 'string', 'children': [], 'value': '"F"'},{'id': '169', 'type': 'integer', 'children': [], 'value': '1'},{'id': '170', 'type': 'pair', 'children': ['171', '172']},{'id': '171', 'type': 'string', 'children': [], 'value': '"Cl"'},{'id': '172', 'type': 'integer', 'children': [], 'value': '1'},{'id': '173', 'type': 'pair', 'children': ['174', '175']},{'id': '174', 'type': 'string', 'children': [], 'value': '"Br"'},{'id': '175', 'type': 'integer', 'children': [], 'value': '1'},{'id': '176', 'type': 'pair', 'children': ['177', '178']},{'id': '177', 'type': 'string', 'children': [], 'value': '"I"'},{'id': '178', 'type': 'integer', 'children': [], 'value': '1'},{'id': '179', 'type': 'for_statement', 'children': ['180', '183', '188']},{'id': '180', 'type': 'pattern_list', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'nbrs'},{'id': '183', 'type': 'call', 'children': ['184', '187']},{'id': '184', 'type': 'attribute', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'neighbors_iter'},{'id': '187', 'type': 'argument_list', 'children': []},{'id': '188', 'type': 'block', 'children': ['189', '198', '228']},{'id': '189', 'type': 'expression_statement', 'children': ['190']},{'id': '190', 'type': 'assignment', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '192', 'type': 'call', 'children': ['193', '196']},{'id': '193', 'type': 'attribute', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '196', 'type': 'argument_list', 'children': ['197']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '198', 'type': 'if_statement', 'children': ['199', '221']},{'id': '199', 'type': 'boolean_operator', 'children': ['200', '206'], 'value': 'and'},{'id': '200', 'type': 'comparison_operator', 'children': ['201', '205'], 'value': '=='},{'id': '201', 'type': 'call', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '203', 'type': 'argument_list', 'children': ['204']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'nbrs'},{'id': '205', 'type': 'integer', 'children': [], 'value': '2'},{'id': '206', 'type': 'call', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '208', 'type': 'generator_expression', 'children': ['209', '214']},{'id': '209', 'type': 'comparison_operator', 'children': ['210', '213'], 'value': '=='},{'id': '210', 'type': 'attribute', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'bond'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '213', 'type': 'integer', 'children': [], 'value': '2'},{'id': '214', 'type': 'for_in_clause', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'bond'},{'id': '216', 'type': 'call', 'children': ['217', '220']},{'id': '217', 'type': 'attribute', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'nbrs'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '220', 'type': 'argument_list', 'children': []},{'id': '221', 'type': 'block', 'children': ['222']},{'id': '222', 'type': 'expression_statement', 'children': ['223']},{'id': '223', 'type': 'assignment', 'children': ['224', '227']},{'id': '224', 'type': 'attribute', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'pi'},{'id': '227', 'type': 'integer', 'children': [], 'value': '2'},{'id': '228', 'type': 'if_statement', 'children': ['229', '234']},{'id': '229', 'type': 'comparison_operator', 'children': ['230', '233'], 'value': 'in'},{'id': '230', 'type': 'attribute', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'symbol'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'max_nbr'},{'id': '234', 'type': 'block', 'children': ['235', '256']},{'id': '235', 'type': 'expression_statement', 'children': ['236']},{'id': '236', 'type': 'assignment', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'h_cnt'},{'id': '238', 'type': 'binary_operator', 'children': ['239', '253'], 'value': '+'},{'id': '239', 'type': 'binary_operator', 'children': ['240', '250'], 'value': '-'},{'id': '240', 'type': 'binary_operator', 'children': ['241', '246'], 'value': '-'},{'id': '241', 'type': 'subscript', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'max_nbr'},{'id': '243', 'type': 'attribute', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'symbol'},{'id': '246', 'type': 'call', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '248', 'type': 'argument_list', 'children': ['249']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'nbrs'},{'id': '250', 'type': 'attribute', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'pi'},{'id': '253', 'type': 'attribute', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'charge'},{'id': '256', 'type': 'if_statement', 'children': ['257', '260']},{'id': '257', 'type': 'comparison_operator', 'children': ['258', '259'], 'value': '>'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'h_cnt'},{'id': '259', 'type': 'integer', 'children': [], 'value': '0'},{'id': '260', 'type': 'block', 'children': ['261']},{'id': '261', 'type': 'expression_statement', 'children': ['262']},{'id': '262', 'type': 'call', 'children': ['263', '271']},{'id': '263', 'type': 'attribute', 'children': ['264', '270']},{'id': '264', 'type': 'call', 'children': ['265', '268']},{'id': '265', 'type': 'attribute', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '268', 'type': 'argument_list', 'children': ['269']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'add_hydrogen'},{'id': '271', 'type': 'argument_list', 'children': ['272']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'h_cnt'},{'id': '273', 'type': 'expression_statement', 'children': ['274']},{'id': '274', 'type': 'call', 'children': ['275', '280']},{'id': '275', 'type': 'attribute', 'children': ['276', '279']},{'id': '276', 'type': 'attribute', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'descriptors'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '280', 'type': 'argument_list', 'children': ['281']},{'id': '281', 'type': 'string', 'children': [], 'value': '"Valence"'}
def assign_valence(mol): 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 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")
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'assign_charge'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'force_recalc'},{'id': '7', 'type': 'False', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '16', '398', '404']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'call', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'require'},{'id': '14', 'type': 'argument_list', 'children': ['15']},{'id': '15', 'type': 'string', 'children': [], 'value': '"Aromatic"'},{'id': '16', 'type': 'for_statement', 'children': ['17', '20', '25']},{'id': '17', 'type': 'pattern_list', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'nbrs'},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'neighbors_iter'},{'id': '24', 'type': 'argument_list', 'children': []},{'id': '25', 'type': 'block', 'children': ['26', '35', '42']},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'nbrcnt'},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'nbrs'},{'id': '42', 'type': 'if_statement', 'children': ['43', '48', '207', '352']},{'id': '43', 'type': 'comparison_operator', 'children': ['44', '47'], 'value': '=='},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'symbol'},{'id': '47', 'type': 'string', 'children': [], 'value': '"N"'},{'id': '48', 'type': 'block', 'children': ['49']},{'id': '49', 'type': 'if_statement', 'children': ['50', '54', '66']},{'id': '50', 'type': 'not_operator', 'children': ['51']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'pi'},{'id': '54', 'type': 'block', 'children': ['55']},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '65']},{'id': '57', 'type': 'attribute', 'children': ['58', '64']},{'id': '58', 'type': 'call', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'charge_phys'},{'id': '65', 'type': 'integer', 'children': [], 'value': '1'},{'id': '66', 'type': 'elif_clause', 'children': ['67', '76']},{'id': '67', 'type': 'boolean_operator', 'children': ['68', '71'], 'value': 'and'},{'id': '68', 'type': 'comparison_operator', 'children': ['69', '70'], 'value': '=='},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'nbrcnt'},{'id': '70', 'type': 'integer', 'children': [], 'value': '1'},{'id': '71', 'type': 'comparison_operator', 'children': ['72', '75'], 'value': '=='},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'pi'},{'id': '75', 'type': 'integer', 'children': [], 'value': '2'},{'id': '76', 'type': 'block', 'children': ['77', '90', '94', '98', '177']},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'ni'},{'id': '80', 'type': 'subscript', 'children': ['81', '89']},{'id': '81', 'type': 'call', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'call', 'children': ['85', '88']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'nbrs'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '88', 'type': 'argument_list', 'children': []},{'id': '89', 'type': 'integer', 'children': [], 'value': '0'},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'conj'},{'id': '93', 'type': 'False', 'children': []},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'assignment', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'sp2n'},{'id': '97', 'type': 'None', 'children': []},{'id': '98', 'type': 'for_statement', 'children': ['99', '102', '112']},{'id': '99', 'type': 'pattern_list', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'nni'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'nnb'},{'id': '102', 'type': 'call', 'children': ['103', '111']},{'id': '103', 'type': 'attribute', 'children': ['104', '110']},{'id': '104', 'type': 'call', 'children': ['105', '108']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'neighbors'},{'id': '108', 'type': 'argument_list', 'children': ['109']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'ni'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '111', 'type': 'argument_list', 'children': []},{'id': '112', 'type': 'block', 'children': ['113']},{'id': '113', 'type': 'if_statement', 'children': ['114', '141', '157']},{'id': '114', 'type': 'boolean_operator', 'children': ['115', '131', '132'], 'value': 'and'},{'id': '115', 'type': 'boolean_operator', 'children': ['116', '126'], 'value': 'and'},{'id': '116', 'type': 'comparison_operator', 'children': ['117', '125'], 'value': '=='},{'id': '117', 'type': 'attribute', 'children': ['118', '124']},{'id': '118', 'type': 'call', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'nni'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'symbol'},{'id': '125', 'type': 'string', 'children': [], 'value': '"N"'},{'id': '126', 'type': 'comparison_operator', 'children': ['127', '130'], 'value': '=='},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'nnb'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '130', 'type': 'integer', 'children': [], 'value': '2'},{'id': '131', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '132', 'type': 'not_operator', 'children': ['133']},{'id': '133', 'type': 'attribute', 'children': ['134', '140']},{'id': '134', 'type': 'call', 'children': ['135', '138']},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'nni'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'aromatic'},{'id': '141', 'type': 'block', 'children': ['142', '153']},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'assignment', 'children': ['144', '152']},{'id': '144', 'type': 'attribute', 'children': ['145', '151']},{'id': '145', 'type': 'call', 'children': ['146', '149']},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '149', 'type': 'argument_list', 'children': ['150']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'nni'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'charge_conj'},{'id': '152', 'type': 'integer', 'children': [], 'value': '1'},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'assignment', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'conj'},{'id': '156', 'type': 'True', 'children': []},{'id': '157', 'type': 'elif_clause', 'children': ['158', '172']},{'id': '158', 'type': 'boolean_operator', 'children': ['159', '169'], 'value': 'and'},{'id': '159', 'type': 'comparison_operator', 'children': ['160', '168'], 'value': '=='},{'id': '160', 'type': 'attribute', 'children': ['161', '167']},{'id': '161', 'type': 'call', 'children': ['162', '165']},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '165', 'type': 'argument_list', 'children': ['166']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'nni'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'symbol'},{'id': '168', 'type': 'string', 'children': [], 'value': '"N"'},{'id': '169', 'type': 'comparison_operator', 'children': ['170', '171'], 'value': '!='},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'nni'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '172', 'type': 'block', 'children': ['173']},{'id': '173', 'type': 'expression_statement', 'children': ['174']},{'id': '174', 'type': 'assignment', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'sp2n'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'nni'},{'id': '177', 'type': 'if_statement', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'conj'},{'id': '179', 'type': 'block', 'children': ['180', '191']},{'id': '180', 'type': 'expression_statement', 'children': ['181']},{'id': '181', 'type': 'assignment', 'children': ['182', '190']},{'id': '182', 'type': 'attribute', 'children': ['183', '189']},{'id': '183', 'type': 'call', 'children': ['184', '187']},{'id': '184', 'type': 'attribute', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '187', 'type': 'argument_list', 'children': ['188']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'charge_phys'},{'id': '190', 'type': 'integer', 'children': [], 'value': '1'},{'id': '191', 'type': 'if_statement', 'children': ['192', '195']},{'id': '192', 'type': 'comparison_operator', 'children': ['193', '194'], 'value': 'is'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'sp2n'},{'id': '194', 'type': 'None', 'children': []},{'id': '195', 'type': 'block', 'children': ['196']},{'id': '196', 'type': 'expression_statement', 'children': ['197']},{'id': '197', 'type': 'assignment', 'children': ['198', '206']},{'id': '198', 'type': 'attribute', 'children': ['199', '205']},{'id': '199', 'type': 'call', 'children': ['200', '203']},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '203', 'type': 'argument_list', 'children': ['204']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'sp2n'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'charge_conj'},{'id': '206', 'type': 'integer', 'children': [], 'value': '1'},{'id': '207', 'type': 'elif_clause', 'children': ['208', '223']},{'id': '208', 'type': 'boolean_operator', 'children': ['209', '218'], 'value': 'and'},{'id': '209', 'type': 'boolean_operator', 'children': ['210', '215'], 'value': 'and'},{'id': '210', 'type': 'comparison_operator', 'children': ['211', '214'], 'value': '=='},{'id': '211', 'type': 'attribute', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'symbol'},{'id': '214', 'type': 'string', 'children': [], 'value': '"O"'},{'id': '215', 'type': 'comparison_operator', 'children': ['216', '217'], 'value': '=='},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'nbrcnt'},{'id': '217', 'type': 'integer', 'children': [], 'value': '1'},{'id': '218', 'type': 'comparison_operator', 'children': ['219', '222'], 'value': '=='},{'id': '219', 'type': 'attribute', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'pi'},{'id': '222', 'type': 'integer', 'children': [], 'value': '2'},{'id': '223', 'type': 'block', 'children': ['224', '237', '241', '275', '337']},{'id': '224', 'type': 'expression_statement', 'children': ['225']},{'id': '225', 'type': 'assignment', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'ni'},{'id': '227', 'type': 'subscript', 'children': ['228', '236']},{'id': '228', 'type': 'call', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '230', 'type': 'argument_list', 'children': ['231']},{'id': '231', 'type': 'call', 'children': ['232', '235']},{'id': '232', 'type': 'attribute', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'nbrs'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '235', 'type': 'argument_list', 'children': []},{'id': '236', 'type': 'integer', 'children': [], 'value': '0'},{'id': '237', 'type': 'expression_statement', 'children': ['238']},{'id': '238', 'type': 'assignment', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'conj'},{'id': '240', 'type': 'False', 'children': []},{'id': '241', 'type': 'if_statement', 'children': ['242', '252']},{'id': '242', 'type': 'comparison_operator', 'children': ['243', '251'], 'value': '=='},{'id': '243', 'type': 'attribute', 'children': ['244', '250']},{'id': '244', 'type': 'call', 'children': ['245', '248']},{'id': '245', 'type': 'attribute', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '248', 'type': 'argument_list', 'children': ['249']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'ni'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'symbol'},{'id': '251', 'type': 'string', 'children': [], 'value': '"N"'},{'id': '252', 'type': 'block', 'children': ['253', '264']},{'id': '253', 'type': 'expression_statement', 'children': ['254']},{'id': '254', 'type': 'assignment', 'children': ['255', '263']},{'id': '255', 'type': 'attribute', 'children': ['256', '262']},{'id': '256', 'type': 'call', 'children': ['257', '260']},{'id': '257', 'type': 'attribute', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '260', 'type': 'argument_list', 'children': ['261']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'n_oxide'},{'id': '263', 'type': 'True', 'children': []},{'id': '264', 'type': 'expression_statement', 'children': ['265']},{'id': '265', 'type': 'assignment', 'children': ['266', '274']},{'id': '266', 'type': 'attribute', 'children': ['267', '273']},{'id': '267', 'type': 'call', 'children': ['268', '271']},{'id': '268', 'type': 'attribute', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '271', 'type': 'argument_list', 'children': ['272']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'ni'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'n_oxide'},{'id': '274', 'type': 'True', 'children': []},{'id': '275', 'type': 'for_statement', 'children': ['276', '279', '289']},{'id': '276', 'type': 'pattern_list', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'nni'},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'nnb'},{'id': '279', 'type': 'call', 'children': ['280', '288']},{'id': '280', 'type': 'attribute', 'children': ['281', '287']},{'id': '281', 'type': 'call', 'children': ['282', '285']},{'id': '282', 'type': 'attribute', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'neighbors'},{'id': '285', 'type': 'argument_list', 'children': ['286']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'ni'},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '288', 'type': 'argument_list', 'children': []},{'id': '289', 'type': 'block', 'children': ['290']},{'id': '290', 'type': 'if_statement', 'children': ['291', '320']},{'id': '291', 'type': 'boolean_operator', 'children': ['292', '311'], 'value': 'and'},{'id': '292', 'type': 'boolean_operator', 'children': ['293', '305', '306'], 'value': 'and'},{'id': '293', 'type': 'comparison_operator', 'children': ['294', '302'], 'value': 'in'},{'id': '294', 'type': 'attribute', 'children': ['295', '301']},{'id': '295', 'type': 'call', 'children': ['296', '299']},{'id': '296', 'type': 'attribute', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '299', 'type': 'argument_list', 'children': ['300']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'nni'},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'symbol'},{'id': '302', 'type': 'tuple', 'children': ['303', '304']},{'id': '303', 'type': 'string', 'children': [], 'value': '"O"'},{'id': '304', 'type': 'string', 'children': [], 'value': '"S"'},{'id': '305', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '306', 'type': 'comparison_operator', 'children': ['307', '310'], 'value': '=='},{'id': '307', 'type': 'attribute', 'children': ['308', '309']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'nnb'},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '310', 'type': 'integer', 'children': [], 'value': '2'},{'id': '311', 'type': 'not_operator', 'children': ['312']},{'id': '312', 'type': 'attribute', 'children': ['313', '319']},{'id': '313', 'type': 'call', 'children': ['314', '317']},{'id': '314', 'type': 'attribute', 'children': ['315', '316']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '317', 'type': 'argument_list', 'children': ['318']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'ni'},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'n_oxide'},{'id': '320', 'type': 'block', 'children': ['321', '333']},{'id': '321', 'type': 'expression_statement', 'children': ['322']},{'id': '322', 'type': 'assignment', 'children': ['323', '331']},{'id': '323', 'type': 'attribute', 'children': ['324', '330']},{'id': '324', 'type': 'call', 'children': ['325', '328']},{'id': '325', 'type': 'attribute', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '328', 'type': 'argument_list', 'children': ['329']},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'nni'},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'charge_conj'},{'id': '331', 'type': 'unary_operator', 'children': ['332'], 'value': '-'},{'id': '332', 'type': 'integer', 'children': [], 'value': '1'},{'id': '333', 'type': 'expression_statement', 'children': ['334']},{'id': '334', 'type': 'assignment', 'children': ['335', '336']},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'conj'},{'id': '336', 'type': 'True', 'children': []},{'id': '337', 'type': 'if_statement', 'children': ['338', '339']},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'conj'},{'id': '339', 'type': 'block', 'children': ['340']},{'id': '340', 'type': 'expression_statement', 'children': ['341']},{'id': '341', 'type': 'assignment', 'children': ['342', '350']},{'id': '342', 'type': 'attribute', 'children': ['343', '349']},{'id': '343', 'type': 'call', 'children': ['344', '347']},{'id': '344', 'type': 'attribute', 'children': ['345', '346']},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '347', 'type': 'argument_list', 'children': ['348']},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'charge_phys'},{'id': '350', 'type': 'unary_operator', 'children': ['351'], 'value': '-'},{'id': '351', 'type': 'integer', 'children': [], 'value': '1'},{'id': '352', 'type': 'elif_clause', 'children': ['353', '362']},{'id': '353', 'type': 'boolean_operator', 'children': ['354', '359'], 'value': 'and'},{'id': '354', 'type': 'comparison_operator', 'children': ['355', '358'], 'value': '=='},{'id': '355', 'type': 'attribute', 'children': ['356', '357']},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'symbol'},{'id': '358', 'type': 'string', 'children': [], 'value': '"S"'},{'id': '359', 'type': 'comparison_operator', 'children': ['360', '361'], 'value': '=='},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'nbrcnt'},{'id': '361', 'type': 'integer', 'children': [], 'value': '1'},{'id': '362', 'type': 'block', 'children': ['363', '376']},{'id': '363', 'type': 'expression_statement', 'children': ['364']},{'id': '364', 'type': 'assignment', 'children': ['365', '366']},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'ni'},{'id': '366', 'type': 'subscript', 'children': ['367', '375']},{'id': '367', 'type': 'call', 'children': ['368', '369']},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '369', 'type': 'argument_list', 'children': ['370']},{'id': '370', 'type': 'call', 'children': ['371', '374']},{'id': '371', 'type': 'attribute', 'children': ['372', '373']},{'id': '372', 'type': 'identifier', 'children': [], 'value': 'nbrs'},{'id': '373', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '374', 'type': 'argument_list', 'children': []},{'id': '375', 'type': 'integer', 'children': [], 'value': '0'},{'id': '376', 'type': 'if_statement', 'children': ['377', '385']},{'id': '377', 'type': 'attribute', 'children': ['378', '384']},{'id': '378', 'type': 'call', 'children': ['379', '382']},{'id': '379', 'type': 'attribute', 'children': ['380', '381']},{'id': '380', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '381', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '382', 'type': 'argument_list', 'children': ['383']},{'id': '383', 'type': 'identifier', 'children': [], 'value': 'ni'},{'id': '384', 'type': 'identifier', 'children': [], 'value': 'aromatic'},{'id': '385', 'type': 'block', 'children': ['386']},{'id': '386', 'type': 'expression_statement', 'children': ['387']},{'id': '387', 'type': 'assignment', 'children': ['388', '396']},{'id': '388', 'type': 'attribute', 'children': ['389', '395']},{'id': '389', 'type': 'call', 'children': ['390', '393']},{'id': '390', 'type': 'attribute', 'children': ['391', '392']},{'id': '391', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '393', 'type': 'argument_list', 'children': ['394']},{'id': '394', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '395', 'type': 'identifier', 'children': [], 'value': 'charge_phys'},{'id': '396', 'type': 'unary_operator', 'children': ['397'], 'value': '-'},{'id': '397', 'type': 'integer', 'children': [], 'value': '1'},{'id': '398', 'type': 'expression_statement', 'children': ['399']},{'id': '399', 'type': 'assignment', 'children': ['400', '403']},{'id': '400', 'type': 'attribute', 'children': ['401', '402']},{'id': '401', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '402', 'type': 'identifier', 'children': [], 'value': 'charge_assigned'},{'id': '403', 'type': 'True', 'children': []},{'id': '404', 'type': 'expression_statement', 'children': ['405']},{'id': '405', 'type': 'call', 'children': ['406', '411']},{'id': '406', 'type': 'attribute', 'children': ['407', '410']},{'id': '407', 'type': 'attribute', 'children': ['408', '409']},{'id': '408', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '409', 'type': 'identifier', 'children': [], 'value': 'descriptors'},{'id': '410', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '411', 'type': 'argument_list', 'children': ['412']},{'id': '412', 'type': 'string', 'children': [], 'value': '"Phys_charge"'}
def assign_charge(mol, force_recalc=False): 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: mol.atom(i).charge_phys = 1 elif nbrcnt == 1 and atom.pi == 2: 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: 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: 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")
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_alphabetical_members'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'predicate'},{'id': '6', 'type': 'block', 'children': ['7', '20', '31', '37']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '12', 'type': 'argument_list', 'children': ['13']},{'id': '13', 'type': 'call', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'inspect'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'getmembers'},{'id': '17', 'type': 'argument_list', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'predicate'},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '30', 'type': 'argument_list', 'children': []},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'call', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '36', 'type': 'argument_list', 'children': []},{'id': '37', 'type': 'return_statement', 'children': ['38']},{'id': '38', 'type': 'dictionary_comprehension', 'children': ['39', '44']},{'id': '39', 'type': 'pair', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '41', 'type': 'subscript', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '44', 'type': 'for_in_clause', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'keys'}
def _get_alphabetical_members(obj, predicate): fields = dict(inspect.getmembers(obj, predicate)) keys = list(fields.keys()) keys.sort() return {k: fields[k] for k in keys}
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'run'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '14', '26', '32', '36', '346', '351', '367', '373', '379']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'request_cache'},{'id': '9', 'type': 'call', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'cache'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'get_request_cache'},{'id': '13', 'type': 'argument_list', 'children': []},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '17', 'type': 'call', 'children': ['18', '25']},{'id': '18', 'type': 'attribute', 'children': ['19', '24']},{'id': '19', 'type': 'call', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'client'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'get_client'},{'id': '23', 'type': 'argument_list', 'children': []},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'create_session'},{'id': '25', 'type': 'argument_list', 'children': []},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'mark_incomplete'},{'id': '31', 'type': 'argument_list', 'children': []},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'universes'},{'id': '35', 'type': 'list', 'children': [], 'value': '[]'},{'id': '36', 'type': 'with_statement', 'children': ['37', '42']},{'id': '37', 'type': 'with_clause', 'children': ['38']},{'id': '38', 'type': 'with_item', 'children': ['39']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'no_autoflush'},{'id': '42', 'type': 'block', 'children': ['43', '58']},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'movies'},{'id': '46', 'type': 'call', 'children': ['47', '57']},{'id': '47', 'type': 'attribute', 'children': ['48', '56']},{'id': '48', 'type': 'call', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'Movie'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '57', 'type': 'argument_list', 'children': []},{'id': '58', 'type': 'for_statement', 'children': ['59', '60', '61']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'movie'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'movies'},{'id': '61', 'type': 'block', 'children': ['62', '81', '90', '101', '109', '113', '121']},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'article'},{'id': '65', 'type': 'call', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'request_cache'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '69', 'type': 'argument_list', 'children': ['70', '75', '78']},{'id': '70', 'type': 'binary_operator', 'children': ['71', '72'], 'value': '+'},{'id': '71', 'type': 'string', 'children': [], 'value': '"http://marvel.wikia.com"'},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'movie'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '75', 'type': 'keyword_argument', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'xpath'},{'id': '77', 'type': 'string', 'children': [], 'value': '"//article[@id=\'WikiaMainContent\']"'},{'id': '78', 'type': 'keyword_argument', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'rate_limit'},{'id': '80', 'type': 'float', 'children': [], 'value': '0.5'},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'doc'},{'id': '84', 'type': 'call', 'children': ['85', '88']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'html'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'fromstring'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'article'},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '93', 'type': 'subscript', 'children': ['94', '100']},{'id': '94', 'type': 'call', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'doc'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'xpath'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'string', 'children': [], 'value': '"//span[@id=\'Appearances\']"'},{'id': '100', 'type': 'integer', 'children': [], 'value': '0'},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'assignment', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '104', 'type': 'call', 'children': ['105', '108']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'getparent'},{'id': '108', 'type': 'argument_list', 'children': []},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'appearance_type'},{'id': '112', 'type': 'string', 'children': [], 'value': '"Featured Characters"'},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'assignment', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '116', 'type': 'call', 'children': ['117', '120']},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'getnext'},{'id': '120', 'type': 'argument_list', 'children': []},{'id': '121', 'type': 'while_statement', 'children': ['122', '131']},{'id': '122', 'type': 'boolean_operator', 'children': ['123', '126'], 'value': 'and'},{'id': '123', 'type': 'comparison_operator', 'children': ['124', '125'], 'value': 'is'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '125', 'type': 'None', 'children': []},{'id': '126', 'type': 'comparison_operator', 'children': ['127', '130'], 'value': '!='},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '130', 'type': 'string', 'children': [], 'value': "'h2'"},{'id': '131', 'type': 'block', 'children': ['132', '338']},{'id': '132', 'type': 'if_statement', 'children': ['133', '155', '305']},{'id': '133', 'type': 'boolean_operator', 'children': ['134', '139'], 'value': 'and'},{'id': '134', 'type': 'comparison_operator', 'children': ['135', '138'], 'value': '=='},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '138', 'type': 'string', 'children': [], 'value': "'ul'"},{'id': '139', 'type': '()', 'children': ['140']},{'id': '140', 'type': 'boolean_operator', 'children': ['141', '148'], 'value': 'or'},{'id': '141', 'type': 'comparison_operator', 'children': ['142', '143'], 'value': 'in'},{'id': '142', 'type': 'string', 'children': [], 'value': "'characters'"},{'id': '143', 'type': 'call', 'children': ['144', '147']},{'id': '144', 'type': 'attribute', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'appearance_type'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '147', 'type': 'argument_list', 'children': []},{'id': '148', 'type': 'comparison_operator', 'children': ['149', '150'], 'value': 'in'},{'id': '149', 'type': 'string', 'children': [], 'value': "'villains'"},{'id': '150', 'type': 'call', 'children': ['151', '154']},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'appearance_type'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '154', 'type': 'argument_list', 'children': []},{'id': '155', 'type': 'block', 'children': ['156']},{'id': '156', 'type': 'for_statement', 'children': ['157', '158', '164']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'li'},{'id': '158', 'type': 'call', 'children': ['159', '162']},{'id': '159', 'type': 'attribute', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'iter'},{'id': '162', 'type': 'argument_list', 'children': ['163']},{'id': '163', 'type': 'string', 'children': [], 'value': "'li'"},{'id': '164', 'type': 'block', 'children': ['165']},{'id': '165', 'type': 'for_statement', 'children': ['166', '167', '168']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'li'},{'id': '168', 'type': 'block', 'children': ['169', '177', '202', '217', '237', '304']},{'id': '169', 'type': 'if_statement', 'children': ['170', '175']},{'id': '170', 'type': 'comparison_operator', 'children': ['171', '174'], 'value': '!='},{'id': '171', 'type': 'attribute', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '174', 'type': 'string', 'children': [], 'value': "'a'"},{'id': '175', 'type': 'block', 'children': ['176']},{'id': '176', 'type': 'continue_statement', 'children': []},{'id': '177', 'type': 'if_statement', 'children': ['178', '200']},{'id': '178', 'type': 'boolean_operator', 'children': ['179', '188'], 'value': 'or'},{'id': '179', 'type': 'comparison_operator', 'children': ['180', '181'], 'value': 'in'},{'id': '180', 'type': 'string', 'children': [], 'value': '"image"'},{'id': '181', 'type': 'call', 'children': ['182', '185']},{'id': '182', 'type': 'attribute', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '185', 'type': 'argument_list', 'children': ['186', '187']},{'id': '186', 'type': 'string', 'children': [], 'value': '"class"'},{'id': '187', 'type': 'string', 'children': [], 'value': '""'},{'id': '188', 'type': 'not_operator', 'children': ['189']},{'id': '189', 'type': 'call', 'children': ['190', '198']},{'id': '190', 'type': 'attribute', 'children': ['191', '197']},{'id': '191', 'type': 'call', 'children': ['192', '195']},{'id': '192', 'type': 'attribute', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '195', 'type': 'argument_list', 'children': ['196']},{'id': '196', 'type': 'string', 'children': [], 'value': '"href"'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '198', 'type': 'argument_list', 'children': ['199']},{'id': '199', 'type': 'string', 'children': [], 'value': '"/wiki/"'},{'id': '200', 'type': 'block', 'children': ['201']},{'id': '201', 'type': 'continue_statement', 'children': []},{'id': '202', 'type': 'expression_statement', 'children': ['203']},{'id': '203', 'type': 'assignment', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '205', 'type': 'call', 'children': ['206', '209']},{'id': '206', 'type': 'attribute', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '209', 'type': 'argument_list', 'children': ['210', '211']},{'id': '210', 'type': 'string', 'children': [], 'value': "r'\\(.*?\\)'"},{'id': '211', 'type': 'call', 'children': ['212', '215']},{'id': '212', 'type': 'attribute', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '215', 'type': 'argument_list', 'children': ['216']},{'id': '216', 'type': 'string', 'children': [], 'value': "'href'"},{'id': '217', 'type': 'if_statement', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '219', 'type': 'block', 'children': ['220']},{'id': '220', 'type': 'expression_statement', 'children': ['221']},{'id': '221', 'type': 'call', 'children': ['222', '225']},{'id': '222', 'type': 'attribute', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'universes'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '225', 'type': 'argument_list', 'children': ['226']},{'id': '226', 'type': 'subscript', 'children': ['227', '232']},{'id': '227', 'type': 'call', 'children': ['228', '231']},{'id': '228', 'type': 'attribute', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '231', 'type': 'argument_list', 'children': []},{'id': '232', 'type': 'slice', 'children': ['233', '234', '235']},{'id': '233', 'type': 'integer', 'children': [], 'value': '1'},{'id': '234', 'type': 'colon', 'children': []},{'id': '235', 'type': 'unary_operator', 'children': ['236'], 'value': '-'},{'id': '236', 'type': 'integer', 'children': [], 'value': '1'},{'id': '237', 'type': 'try_statement', 'children': ['238', '300']},{'id': '238', 'type': 'block', 'children': ['239', '272', '293']},{'id': '239', 'type': 'expression_statement', 'children': ['240']},{'id': '240', 'type': 'assignment', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'character'},{'id': '242', 'type': 'call', 'children': ['243', '271']},{'id': '243', 'type': 'attribute', 'children': ['244', '269', '270']},{'id': '244', 'type': 'call', 'children': ['245', '256']},{'id': '245', 'type': 'attribute', 'children': ['246', '254', '255']},{'id': '246', 'type': 'call', 'children': ['247', '250']},{'id': '247', 'type': 'attribute', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '250', 'type': 'argument_list', 'children': ['251']},{'id': '251', 'type': 'attribute', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'Character'},{'id': '254', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '256', 'type': 'argument_list', 'children': ['257']},{'id': '257', 'type': 'comparison_operator', 'children': ['258', '263'], 'value': '=='},{'id': '258', 'type': 'attribute', 'children': ['259', '262']},{'id': '259', 'type': 'attribute', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'Character'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '263', 'type': 'call', 'children': ['264', '267']},{'id': '264', 'type': 'attribute', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '267', 'type': 'argument_list', 'children': ['268']},{'id': '268', 'type': 'string', 'children': [], 'value': '"href"'},{'id': '269', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'one'},{'id': '271', 'type': 'argument_list', 'children': []},{'id': '272', 'type': 'expression_statement', 'children': ['273']},{'id': '273', 'type': 'assignment', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'appearance'},{'id': '275', 'type': 'call', 'children': ['276', '279']},{'id': '276', 'type': 'attribute', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'MovieAppearance'},{'id': '279', 'type': 'argument_list', 'children': ['280', '285', '290']},{'id': '280', 'type': 'keyword_argument', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'movie_id'},{'id': '282', 'type': 'attribute', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'movie'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '285', 'type': 'keyword_argument', 'children': ['286', '287']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'character_id'},{'id': '287', 'type': 'attribute', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'character'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '290', 'type': 'keyword_argument', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'appearance_type'},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'appearance_type'},{'id': '293', 'type': 'expression_statement', 'children': ['294']},{'id': '294', 'type': 'call', 'children': ['295', '298']},{'id': '295', 'type': 'attribute', 'children': ['296', '297']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '298', 'type': 'argument_list', 'children': ['299']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'appearance'},{'id': '300', 'type': 'except_clause', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'NoResultFound'},{'id': '302', 'type': 'block', 'children': ['303']},{'id': '303', 'type': 'pass_statement', 'children': []},{'id': '304', 'type': 'break_statement', 'children': []},{'id': '305', 'type': 'elif_clause', 'children': ['306', '311']},{'id': '306', 'type': 'comparison_operator', 'children': ['307', '310'], 'value': '=='},{'id': '307', 'type': 'attribute', 'children': ['308', '309']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '310', 'type': 'string', 'children': [], 'value': "'p'"},{'id': '311', 'type': 'block', 'children': ['312']},{'id': '312', 'type': 'expression_statement', 'children': ['313']},{'id': '313', 'type': 'assignment', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'appearance_type'},{'id': '315', 'type': 'call', 'children': ['316', '337']},{'id': '316', 'type': 'attribute', 'children': ['317', '336']},{'id': '317', 'type': 'call', 'children': ['318', '334']},{'id': '318', 'type': 'attribute', 'children': ['319', '333']},{'id': '319', 'type': 'call', 'children': ['320', '332']},{'id': '320', 'type': 'attribute', 'children': ['321', '331']},{'id': '321', 'type': 'call', 'children': ['322', '325']},{'id': '322', 'type': 'attribute', 'children': ['323', '324']},{'id': '323', 'type': 'string', 'children': [], 'value': '" "'},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '325', 'type': 'argument_list', 'children': ['326']},{'id': '326', 'type': 'call', 'children': ['327', '330']},{'id': '327', 'type': 'attribute', 'children': ['328', '329']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'itertext'},{'id': '330', 'type': 'argument_list', 'children': []},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '332', 'type': 'argument_list', 'children': []},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '334', 'type': 'argument_list', 'children': ['335']},{'id': '335', 'type': 'string', 'children': [], 'value': "':'"},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '337', 'type': 'argument_list', 'children': []},{'id': '338', 'type': 'expression_statement', 'children': ['339']},{'id': '339', 'type': 'assignment', 'children': ['340', '341']},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '341', 'type': 'call', 'children': ['342', '345']},{'id': '342', 'type': 'attribute', 'children': ['343', '344']},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'getnext'},{'id': '345', 'type': 'argument_list', 'children': []},{'id': '346', 'type': 'expression_statement', 'children': ['347']},{'id': '347', 'type': 'call', 'children': ['348', '349']},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '349', 'type': 'argument_list', 'children': ['350']},{'id': '350', 'type': 'string', 'children': [], 'value': '"\\nNumber of character appearances per universe: "'},{'id': '351', 'type': 'expression_statement', 'children': ['352']},{'id': '352', 'type': 'call', 'children': ['353', '354']},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '354', 'type': 'argument_list', 'children': ['355']},{'id': '355', 'type': 'call', 'children': ['356', '366']},{'id': '356', 'type': 'attribute', 'children': ['357', '365']},{'id': '357', 'type': 'call', 'children': ['358', '361']},{'id': '358', 'type': 'attribute', 'children': ['359', '360']},{'id': '359', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'Series'},{'id': '361', 'type': 'argument_list', 'children': ['362']},{'id': '362', 'type': 'keyword_argument', 'children': ['363', '364']},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '364', 'type': 'identifier', 'children': [], 'value': 'universes'},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'value_counts'},{'id': '366', 'type': 'argument_list', 'children': []},{'id': '367', 'type': 'expression_statement', 'children': ['368']},{'id': '368', 'type': 'call', 'children': ['369', '372']},{'id': '369', 'type': 'attribute', 'children': ['370', '371']},{'id': '370', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'commit'},{'id': '372', 'type': 'argument_list', 'children': []},{'id': '373', 'type': 'expression_statement', 'children': ['374']},{'id': '374', 'type': 'call', 'children': ['375', '378']},{'id': '375', 'type': 'attribute', 'children': ['376', '377']},{'id': '376', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '377', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '378', 'type': 'argument_list', 'children': []},{'id': '379', 'type': 'expression_statement', 'children': ['380']},{'id': '380', 'type': 'call', 'children': ['381', '384']},{'id': '381', 'type': 'attribute', 'children': ['382', '383']},{'id': '382', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '383', 'type': 'identifier', 'children': [], 'value': 'mark_complete'},{'id': '384', 'type': 'argument_list', 'children': []}
def run(self): request_cache = cache.get_request_cache() session = client.get_client().create_session() self.mark_incomplete() universes = [] with session.no_autoflush: movies = session.query(models.Movie).all() for movie in movies: article = request_cache.get("http://marvel.wikia.com" + movie.url, xpath="//article[@id='WikiaMainContent']", rate_limit=0.5) doc = html.fromstring(article) node = doc.xpath("//span[@id='Appearances']")[0] node = node.getparent() appearance_type = "Featured Characters" 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()): for li in node.iter('li'): for a in li: if a.tag != 'a': continue 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]) try: character = session.query(models.Character) \ .filter(models.Character.url == a.get("href")) \ .one() appearance = models.MovieAppearance(movie_id=movie.id, character_id=character.id, appearance_type=appearance_type) session.add(appearance) except NoResultFound: pass break elif node.tag == 'p': 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()) session.commit() session.close() self.mark_complete()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_argsort'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'y_score'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '17', '27', '41']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'ranks'},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'y_score'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'argsort'},{'id': '16', 'type': 'argument_list', 'children': []},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'argsort'},{'id': '20', 'type': 'subscript', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'ranks'},{'id': '22', 'type': 'slice', 'children': ['23', '24', '25']},{'id': '23', 'type': 'colon', 'children': []},{'id': '24', 'type': 'colon', 'children': []},{'id': '25', 'type': 'unary_operator', 'children': ['26'], 'value': '-'},{'id': '26', 'type': 'integer', 'children': [], 'value': '1'},{'id': '27', 'type': 'if_statement', 'children': ['28', '31']},{'id': '28', 'type': 'comparison_operator', 'children': ['29', '30'], 'value': 'is'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '30', 'type': 'None', 'children': []},{'id': '31', 'type': 'block', 'children': ['32']},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'argsort'},{'id': '35', 'type': 'subscript', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'argsort'},{'id': '37', 'type': 'slice', 'children': ['38', '39', '40']},{'id': '38', 'type': 'integer', 'children': [], 'value': '0'},{'id': '39', 'type': 'colon', 'children': []},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '41', 'type': 'return_statement', 'children': ['42']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'argsort'}
def _argsort(y_score, k=None): ranks = y_score.argsort() argsort = ranks[::-1] if k is not None: argsort = argsort[0:k] return argsort
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'formula'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '5', 'type': 'block', 'children': ['6', '13', '20', '26', '200', '225', '229', '261']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'call', 'children': ['8', '11']},{'id': '8', 'type': 'attribute', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'require'},{'id': '11', 'type': 'argument_list', 'children': ['12']},{'id': '12', 'type': 'string', 'children': [], 'value': '"Valence"'},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'call', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'require'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'string', 'children': [], 'value': '"Topology"'},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'total_cntr'},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'Counter'},{'id': '25', 'type': 'argument_list', 'children': []},{'id': '26', 'type': 'for_statement', 'children': ['27', '28', '41']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '28', 'type': 'call', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '30', 'type': 'argument_list', 'children': ['31', '35', '38']},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'mols_iter'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '35', 'type': 'keyword_argument', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '38', 'type': 'keyword_argument', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '40', 'type': 'True', 'children': []},{'id': '41', 'type': 'block', 'children': ['42', '48', '65', '69', '79', '104', '114', '139', '161', '189']},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'cntr'},{'id': '45', 'type': 'call', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'Counter'},{'id': '47', 'type': 'argument_list', 'children': []},{'id': '48', 'type': 'for_statement', 'children': ['49', '50', '51']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '51', 'type': 'block', 'children': ['52']},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'augmented_assignment', 'children': ['54', '55'], 'value': '+='},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'cntr'},{'id': '55', 'type': 'call', 'children': ['56', '64']},{'id': '56', 'type': 'attribute', 'children': ['57', '63']},{'id': '57', 'type': 'call', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'composition'},{'id': '64', 'type': 'argument_list', 'children': []},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '68', 'type': 'list', 'children': [], 'value': '[]'},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'Cs'},{'id': '72', 'type': 'call', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'cntr'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '76', 'type': 'argument_list', 'children': ['77', '78']},{'id': '77', 'type': 'string', 'children': [], 'value': '"C"'},{'id': '78', 'type': 'integer', 'children': [], 'value': '0'},{'id': '79', 'type': 'if_statement', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'Cs'},{'id': '81', 'type': 'block', 'children': ['82', '89']},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'call', 'children': ['84', '87']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'string', 'children': [], 'value': '"C"'},{'id': '89', 'type': 'if_statement', 'children': ['90', '93']},{'id': '90', 'type': 'comparison_operator', 'children': ['91', '92'], 'value': '>'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'Cs'},{'id': '92', 'type': 'integer', 'children': [], 'value': '1'},{'id': '93', 'type': 'block', 'children': ['94']},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'call', 'children': ['96', '99']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '99', 'type': 'argument_list', 'children': ['100']},{'id': '100', 'type': 'call', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '102', 'type': 'argument_list', 'children': ['103']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'Cs'},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'assignment', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'Hs'},{'id': '107', 'type': 'call', 'children': ['108', '111']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'cntr'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '111', 'type': 'argument_list', 'children': ['112', '113']},{'id': '112', 'type': 'string', 'children': [], 'value': '"H"'},{'id': '113', 'type': 'integer', 'children': [], 'value': '0'},{'id': '114', 'type': 'if_statement', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'Hs'},{'id': '116', 'type': 'block', 'children': ['117', '124']},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'call', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'string', 'children': [], 'value': '"H"'},{'id': '124', 'type': 'if_statement', 'children': ['125', '128']},{'id': '125', 'type': 'comparison_operator', 'children': ['126', '127'], 'value': '>'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'Hs'},{'id': '127', 'type': 'integer', 'children': [], 'value': '1'},{'id': '128', 'type': 'block', 'children': ['129']},{'id': '129', 'type': 'expression_statement', 'children': ['130']},{'id': '130', 'type': 'call', 'children': ['131', '134']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'call', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '137', 'type': 'argument_list', 'children': ['138']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'Hs'},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'id': '140', 'type': 'assignment', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'heteros'},{'id': '142', 'type': 'call', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '144', 'type': 'argument_list', 'children': ['145', '150']},{'id': '145', 'type': 'call', 'children': ['146', '149']},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'cntr'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '149', 'type': 'argument_list', 'children': []},{'id': '150', 'type': 'keyword_argument', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '152', 'type': 'lambda', 'children': ['153', '155']},{'id': '153', 'type': 'lambda_parameters', 'children': ['154']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '155', 'type': 'call', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'atom_number'},{'id': '157', 'type': 'argument_list', 'children': ['158']},{'id': '158', 'type': 'subscript', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '160', 'type': 'integer', 'children': [], 'value': '0'},{'id': '161', 'type': 'for_statement', 'children': ['162', '165', '166']},{'id': '162', 'type': 'pattern_list', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'heteros'},{'id': '166', 'type': 'block', 'children': ['167', '174']},{'id': '167', 'type': 'expression_statement', 'children': ['168']},{'id': '168', 'type': 'call', 'children': ['169', '172']},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '172', 'type': 'argument_list', 'children': ['173']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '174', 'type': 'if_statement', 'children': ['175', '178']},{'id': '175', 'type': 'comparison_operator', 'children': ['176', '177'], 'value': '>'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '177', 'type': 'integer', 'children': [], 'value': '1'},{'id': '178', 'type': 'block', 'children': ['179']},{'id': '179', 'type': 'expression_statement', 'children': ['180']},{'id': '180', 'type': 'call', 'children': ['181', '184']},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'call', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '187', 'type': 'argument_list', 'children': ['188']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '189', 'type': 'expression_statement', 'children': ['190']},{'id': '190', 'type': 'augmented_assignment', 'children': ['191', '199'], 'value': '+='},{'id': '191', 'type': 'subscript', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'total_cntr'},{'id': '193', 'type': 'call', 'children': ['194', '197']},{'id': '194', 'type': 'attribute', 'children': ['195', '196']},{'id': '195', 'type': 'string', 'children': [], 'value': '""'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '197', 'type': 'argument_list', 'children': ['198']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '199', 'type': 'integer', 'children': [], 'value': '1'},{'id': '200', 'type': 'expression_statement', 'children': ['201']},{'id': '201', 'type': 'assignment', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'total'},{'id': '203', 'type': 'call', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '205', 'type': 'argument_list', 'children': ['206', '211', '222']},{'id': '206', 'type': 'call', 'children': ['207', '210']},{'id': '207', 'type': 'attribute', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'total_cntr'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '210', 'type': 'argument_list', 'children': []},{'id': '211', 'type': 'keyword_argument', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '213', 'type': 'lambda', 'children': ['214', '216']},{'id': '214', 'type': 'lambda_parameters', 'children': ['215']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '216', 'type': 'call', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '218', 'type': 'argument_list', 'children': ['219']},{'id': '219', 'type': 'subscript', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '221', 'type': 'integer', 'children': [], 'value': '0'},{'id': '222', 'type': 'keyword_argument', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '224', 'type': 'True', 'children': []},{'id': '225', 'type': 'expression_statement', 'children': ['226']},{'id': '226', 'type': 'assignment', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'total_text'},{'id': '228', 'type': 'list', 'children': [], 'value': '[]'},{'id': '229', 'type': 'for_statement', 'children': ['230', '233', '234']},{'id': '230', 'type': 'pattern_list', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'total'},{'id': '234', 'type': 'block', 'children': ['235']},{'id': '235', 'type': 'if_statement', 'children': ['236', '239', '252']},{'id': '236', 'type': 'comparison_operator', 'children': ['237', '238'], 'value': '>'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '238', 'type': 'integer', 'children': [], 'value': '1'},{'id': '239', 'type': 'block', 'children': ['240']},{'id': '240', 'type': 'expression_statement', 'children': ['241']},{'id': '241', 'type': 'call', 'children': ['242', '245']},{'id': '242', 'type': 'attribute', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'total_text'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '245', 'type': 'argument_list', 'children': ['246']},{'id': '246', 'type': 'binary_operator', 'children': ['247', '251'], 'value': '+'},{'id': '247', 'type': 'call', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '249', 'type': 'argument_list', 'children': ['250']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '252', 'type': 'else_clause', 'children': ['253']},{'id': '253', 'type': 'block', 'children': ['254']},{'id': '254', 'type': 'expression_statement', 'children': ['255']},{'id': '255', 'type': 'call', 'children': ['256', '259']},{'id': '256', 'type': 'attribute', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'total_text'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '259', 'type': 'argument_list', 'children': ['260']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '261', 'type': 'return_statement', 'children': ['262']},{'id': '262', 'type': 'call', 'children': ['263', '266']},{'id': '263', 'type': 'attribute', 'children': ['264', '265']},{'id': '264', 'type': 'string', 'children': [], 'value': '"."'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '266', 'type': 'argument_list', 'children': ['267']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'total_text'}
def formula(mol): 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)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_start_action_for_section'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'section'},{'id': '6', 'type': 'block', 'children': ['7', '13', '24', '34', '52', '56', '60', '71', '99', '114', '128', '137', '146']},{'id': '7', 'type': 'if_statement', 'children': ['8', '11']},{'id': '8', 'type': 'comparison_operator', 'children': ['9', '10'], 'value': '=='},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'section'},{'id': '10', 'type': 'string', 'children': [], 'value': '"configuration"'},{'id': '11', 'type': 'block', 'children': ['12']},{'id': '12', 'type': 'return_statement', 'children': []},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'call', 'children': ['15', '20']},{'id': '15', 'type': 'attribute', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'Global'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'LOGGER'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'binary_operator', 'children': ['22', '23'], 'value': '+'},{'id': '22', 'type': 'string', 'children': [], 'value': '"starting actions for section "'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'section'},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'action_configuration'},{'id': '27', 'type': 'subscript', 'children': ['28', '33']},{'id': '28', 'type': 'attribute', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'Global'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'CONFIG_MANAGER'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'sections'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'section'},{'id': '34', 'type': 'if_statement', 'children': ['35', '41']},{'id': '35', 'type': 'comparison_operator', 'children': ['36', '40'], 'value': '=='},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'action_configuration'},{'id': '40', 'type': 'integer', 'children': [], 'value': '0'},{'id': '41', 'type': 'block', 'children': ['42', '51']},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'call', 'children': ['44', '49']},{'id': '44', 'type': 'attribute', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'Global'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'LOGGER'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'warn'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'string', 'children': [], 'value': 'f"section {section} has no configuration, skipping"'},{'id': '51', 'type': 'return_statement', 'children': []},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'action_type'},{'id': '55', 'type': 'None', 'children': []},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'new_managed_input'},{'id': '59', 'type': 'list', 'children': [], 'value': '[]'},{'id': '60', 'type': 'if_statement', 'children': ['61', '64']},{'id': '61', 'type': 'comparison_operator', 'children': ['62', '63'], 'value': 'in'},{'id': '62', 'type': 'string', 'children': [], 'value': '"type"'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'action_configuration'},{'id': '64', 'type': 'block', 'children': ['65']},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'action_type'},{'id': '68', 'type': 'subscript', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'action_configuration'},{'id': '70', 'type': 'string', 'children': [], 'value': '"type"'},{'id': '71', 'type': 'if_statement', 'children': ['72', '75']},{'id': '72', 'type': 'comparison_operator', 'children': ['73', '74'], 'value': 'in'},{'id': '73', 'type': 'string', 'children': [], 'value': '"input"'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'action_configuration'},{'id': '75', 'type': 'block', 'children': ['76', '82']},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'assignment', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'action_input'},{'id': '79', 'type': 'subscript', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'action_configuration'},{'id': '81', 'type': 'string', 'children': [], 'value': '"input"'},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'assignment', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'new_managed_input'},{'id': '85', 'type': 'generator_expression', 'children': ['86', '91']},{'id': '86', 'type': 'call', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '90', 'type': 'argument_list', 'children': []},{'id': '91', 'type': 'for_in_clause', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '93', 'type': 'call', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'action_input'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'string', 'children': [], 'value': '","'},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'assignment', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'my_action'},{'id': '102', 'type': 'call', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'Action'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'create_action_for_code'},{'id': '106', 'type': 'argument_list', 'children': ['107', '108', '109', '110']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'action_type'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'section'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'action_configuration'},{'id': '110', 'type': 'call', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'new_managed_input'},{'id': '114', 'type': 'if_statement', 'children': ['115', '117']},{'id': '115', 'type': 'not_operator', 'children': ['116']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'my_action'},{'id': '117', 'type': 'block', 'children': ['118', '127']},{'id': '118', 'type': 'expression_statement', 'children': ['119']},{'id': '119', 'type': 'call', 'children': ['120', '125']},{'id': '120', 'type': 'attribute', 'children': ['121', '124']},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'Global'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'LOGGER'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'warn'},{'id': '125', 'type': 'argument_list', 'children': ['126']},{'id': '126', 'type': 'string', 'children': [], 'value': 'f"can\'t find a type for action {section}, the action will be skipped"'},{'id': '127', 'type': 'return_statement', 'children': []},{'id': '128', 'type': 'expression_statement', 'children': ['129']},{'id': '129', 'type': 'call', 'children': ['130', '135']},{'id': '130', 'type': 'attribute', 'children': ['131', '134']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'actions'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '135', 'type': 'argument_list', 'children': ['136']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'my_action'},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'call', 'children': ['139', '144']},{'id': '139', 'type': 'attribute', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'Global'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'LOGGER'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '144', 'type': 'argument_list', 'children': ['145']},{'id': '145', 'type': 'string', 'children': [], 'value': '"updating the subscriptions table"'},{'id': '146', 'type': 'for_statement', 'children': ['147', '148', '151']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'my_input'},{'id': '148', 'type': 'attribute', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'my_action'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'monitored_input'},{'id': '151', 'type': 'block', 'children': ['152']},{'id': '152', 'type': 'expression_statement', 'children': ['153']},{'id': '153', 'type': 'call', 'children': ['154', '165']},{'id': '154', 'type': 'attribute', 'children': ['155', '164']},{'id': '155', 'type': 'call', 'children': ['156', '161']},{'id': '156', 'type': 'attribute', 'children': ['157', '160']},{'id': '157', 'type': 'attribute', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'subscriptions'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'setdefault'},{'id': '161', 'type': 'argument_list', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'my_input'},{'id': '163', 'type': 'list', 'children': [], 'value': '[]'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '165', 'type': 'argument_list', 'children': ['166']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'my_action'}
def _start_action_for_section(self, section): if section == "configuration": return Global.LOGGER.debug("starting actions for section " + section) 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 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)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'check_completion'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'mark_incomplete'},{'id': '7', 'type': 'False', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'clear'},{'id': '10', 'type': 'False', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'return_stats'},{'id': '13', 'type': 'False', 'children': []},{'id': '14', 'type': 'block', 'children': ['15', '21', '47', '166', '180']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'to_clear'},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '20', 'type': 'argument_list', 'children': []},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '26']},{'id': '23', 'type': 'pattern_list', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'is_complete'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'stats'},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': '_check_completion'},{'id': '28', 'type': 'argument_list', 'children': ['29', '30', '33', '36', '39', '44']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '30', 'type': 'keyword_argument', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'mark_incomplete'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'mark_incomplete'},{'id': '33', 'type': 'keyword_argument', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'clear'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'clear'},{'id': '36', 'type': 'keyword_argument', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'stats'},{'id': '38', 'type': 'dictionary', 'children': []},{'id': '39', 'type': 'keyword_argument', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'visited'},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '43', 'type': 'argument_list', 'children': []},{'id': '44', 'type': 'keyword_argument', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'to_clear'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'to_clear'},{'id': '47', 'type': 'while_statement', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'to_clear'},{'id': '49', 'type': 'block', 'children': ['50', '54', '157']},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'found_clearable_task'},{'id': '53', 'type': 'False', 'children': []},{'id': '54', 'type': 'for_statement', 'children': ['55', '56', '64']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'task_id'},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'to_clear'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '63', 'type': 'argument_list', 'children': []},{'id': '64', 'type': 'block', 'children': ['65', '71']},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '68', 'type': 'subscript', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'to_clear'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'task_id'},{'id': '71', 'type': 'if_statement', 'children': ['72', '76']},{'id': '72', 'type': 'not_operator', 'children': ['73']},{'id': '73', 'type': 'subscript', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '75', 'type': 'string', 'children': [], 'value': "'required_by'"},{'id': '76', 'type': 'block', 'children': ['77', '81', '87', '136', '140']},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'found_clearable_task'},{'id': '80', 'type': 'True', 'children': []},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '84', 'type': 'subscript', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '86', 'type': 'string', 'children': [], 'value': "'task'"},{'id': '87', 'type': 'if_statement', 'children': ['88', '93', '123']},{'id': '88', 'type': 'call', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '90', 'type': 'argument_list', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'ORMTask'},{'id': '93', 'type': 'block', 'children': ['94', '100', '106', '112']},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'call', 'children': ['96', '99']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'mark_incomplete'},{'id': '99', 'type': 'argument_list', 'children': []},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'call', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'clear'},{'id': '105', 'type': 'argument_list', 'children': []},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'call', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': '_increment_stats'},{'id': '109', 'type': 'argument_list', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'stats'},{'id': '111', 'type': 'string', 'children': [], 'value': "'Cleared'"},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'call', 'children': ['114', '119']},{'id': '114', 'type': 'attribute', 'children': ['115', '118']},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '119', 'type': 'argument_list', 'children': ['120']},{'id': '120', 'type': 'binary_operator', 'children': ['121', '122'], 'value': '+'},{'id': '121', 'type': 'string', 'children': [], 'value': '"Cleared task: "'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'task_id'},{'id': '123', 'type': 'else_clause', 'children': ['124']},{'id': '124', 'type': 'block', 'children': ['125']},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'call', 'children': ['127', '132']},{'id': '127', 'type': 'attribute', 'children': ['128', '131']},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'binary_operator', 'children': ['134', '135'], 'value': '+'},{'id': '134', 'type': 'string', 'children': [], 'value': "'Cannot clear task, not an ORMTask: '"},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'task_id'},{'id': '136', 'type': 'delete_statement', 'children': ['137']},{'id': '137', 'type': 'subscript', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'to_clear'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'task_id'},{'id': '140', 'type': 'for_statement', 'children': ['141', '142', '147']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'w'},{'id': '142', 'type': 'call', 'children': ['143', '146']},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'to_clear'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '146', 'type': 'argument_list', 'children': []},{'id': '147', 'type': 'block', 'children': ['148']},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'call', 'children': ['150', '155']},{'id': '150', 'type': 'attribute', 'children': ['151', '154']},{'id': '151', 'type': 'subscript', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'w'},{'id': '153', 'type': 'string', 'children': [], 'value': "'required_by'"},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'discard'},{'id': '155', 'type': 'argument_list', 'children': ['156']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'task_id'},{'id': '157', 'type': 'if_statement', 'children': ['158', '160']},{'id': '158', 'type': 'not_operator', 'children': ['159']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'found_clearable_task'},{'id': '160', 'type': 'block', 'children': ['161']},{'id': '161', 'type': 'raise_statement', 'children': ['162']},{'id': '162', 'type': 'call', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'},{'id': '164', 'type': 'argument_list', 'children': ['165']},{'id': '165', 'type': 'string', 'children': [], 'value': '"Error in recursive task clearing, no clearable task found"'},{'id': '166', 'type': 'expression_statement', 'children': ['167']},{'id': '167', 'type': 'call', 'children': ['168', '173']},{'id': '168', 'type': 'attribute', 'children': ['169', '172']},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '173', 'type': 'argument_list', 'children': ['174']},{'id': '174', 'type': 'binary_operator', 'children': ['175', '176'], 'value': '+'},{'id': '175', 'type': 'string', 'children': [], 'value': '"Task completion checking, summary:\\n"'},{'id': '176', 'type': 'call', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '178', 'type': 'argument_list', 'children': ['179']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'stats'},{'id': '180', 'type': 'if_statement', 'children': ['181', '182', '187']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'return_stats'},{'id': '182', 'type': 'block', 'children': ['183']},{'id': '183', 'type': 'return_statement', 'children': ['184']},{'id': '184', 'type': 'expression_list', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'is_complete'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'stats'},{'id': '187', 'type': 'else_clause', 'children': ['188']},{'id': '188', 'type': 'block', 'children': ['189']},{'id': '189', 'type': 'return_statement', 'children': ['190']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'is_complete'}
def check_completion(task, mark_incomplete=False, clear=False, return_stats=False): to_clear = dict() is_complete, stats = _check_completion(task, mark_incomplete=mark_incomplete, clear=clear, stats={}, visited=dict(), to_clear=to_clear) while to_clear: found_clearable_task = False for task_id in list(to_clear.keys()): v = to_clear[task_id] if not v['required_by']: 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) 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
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_connection_string'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'hide_password'},{'id': '7', 'type': 'True', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '17', '27', '37', '47', '57', '67', '77', '105', '164', '170']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'connection_string'},{'id': '12', 'type': 'binary_operator', 'children': ['13', '16'], 'value': '+'},{'id': '13', 'type': 'subscript', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '15', 'type': 'string', 'children': [], 'value': "'driver'"},{'id': '16', 'type': 'string', 'children': [], 'value': "'://'"},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '24', 'type': 'argument_list', 'children': ['25', '26']},{'id': '25', 'type': 'string', 'children': [], 'value': "'user'"},{'id': '26', 'type': 'None', 'children': []},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'password'},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '34', 'type': 'argument_list', 'children': ['35', '36']},{'id': '35', 'type': 'string', 'children': [], 'value': "'password'"},{'id': '36', 'type': 'None', 'children': []},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'host'},{'id': '40', 'type': 'call', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '44', 'type': 'argument_list', 'children': ['45', '46']},{'id': '45', 'type': 'string', 'children': [], 'value': "'host'"},{'id': '46', 'type': 'None', 'children': []},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'port'},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '54', 'type': 'argument_list', 'children': ['55', '56']},{'id': '55', 'type': 'string', 'children': [], 'value': "'port'"},{'id': '56', 'type': 'None', 'children': []},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'database'},{'id': '60', 'type': 'call', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '64', 'type': 'argument_list', 'children': ['65', '66']},{'id': '65', 'type': 'string', 'children': [], 'value': "'database'"},{'id': '66', 'type': 'None', 'children': []},{'id': '67', 'type': 'if_statement', 'children': ['68', '71']},{'id': '68', 'type': 'comparison_operator', 'children': ['69', '70'], 'value': 'is'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'database'},{'id': '70', 'type': 'None', 'children': []},{'id': '71', 'type': 'block', 'children': ['72']},{'id': '72', 'type': 'raise_statement', 'children': ['73']},{'id': '73', 'type': 'call', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'string', 'children': [], 'value': '"Field \'database\' of connection parameters cannot be None."'},{'id': '77', 'type': 'if_statement', 'children': ['78', '85']},{'id': '78', 'type': 'boolean_operator', 'children': ['79', '82'], 'value': 'and'},{'id': '79', 'type': 'comparison_operator', 'children': ['80', '81'], 'value': 'is'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'password'},{'id': '81', 'type': 'None', 'children': []},{'id': '82', 'type': 'comparison_operator', 'children': ['83', '84'], 'value': 'is'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '84', 'type': 'None', 'children': []},{'id': '85', 'type': 'block', 'children': ['86', '95']},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'assignment', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'password'},{'id': '89', 'type': 'call', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'Client'},{'id': '92', 'type': 'identifier', 'children': [], 'value': '_get_password'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '95', 'type': 'if_statement', 'children': ['96', '99']},{'id': '96', 'type': 'comparison_operator', 'children': ['97', '98'], 'value': 'is'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'password'},{'id': '98', 'type': 'None', 'children': []},{'id': '99', 'type': 'block', 'children': ['100']},{'id': '100', 'type': 'raise_statement', 'children': ['101']},{'id': '101', 'type': 'call', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'string', 'children': [], 'value': '"Password not defined and not available in keyring."'},{'id': '105', 'type': 'if_statement', 'children': ['106', '109']},{'id': '106', 'type': 'comparison_operator', 'children': ['107', '108'], 'value': 'is'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'host'},{'id': '108', 'type': 'None', 'children': []},{'id': '109', 'type': 'block', 'children': ['110', '146', '150']},{'id': '110', 'type': 'if_statement', 'children': ['111', '114']},{'id': '111', 'type': 'comparison_operator', 'children': ['112', '113'], 'value': 'is'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '113', 'type': 'None', 'children': []},{'id': '114', 'type': 'block', 'children': ['115', '119', '142']},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'augmented_assignment', 'children': ['117', '118'], 'value': '+='},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'connection_string'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '119', 'type': 'if_statement', 'children': ['120', '126']},{'id': '120', 'type': 'comparison_operator', 'children': ['121', '125'], 'value': '>'},{'id': '121', 'type': 'call', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '123', 'type': 'argument_list', 'children': ['124']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'password'},{'id': '125', 'type': 'integer', 'children': [], 'value': '0'},{'id': '126', 'type': 'block', 'children': ['127']},{'id': '127', 'type': 'if_statement', 'children': ['128', '129', '134']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'hide_password'},{'id': '129', 'type': 'block', 'children': ['130']},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'augmented_assignment', 'children': ['132', '133'], 'value': '+='},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'connection_string'},{'id': '133', 'type': 'string', 'children': [], 'value': '":[password hidden]"'},{'id': '134', 'type': 'else_clause', 'children': ['135']},{'id': '135', 'type': 'block', 'children': ['136']},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'augmented_assignment', 'children': ['138', '139'], 'value': '+='},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'connection_string'},{'id': '139', 'type': 'binary_operator', 'children': ['140', '141'], 'value': '+'},{'id': '140', 'type': 'string', 'children': [], 'value': '":"'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'password'},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'augmented_assignment', 'children': ['144', '145'], 'value': '+='},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'connection_string'},{'id': '145', 'type': 'string', 'children': [], 'value': '"@"'},{'id': '146', 'type': 'expression_statement', 'children': ['147']},{'id': '147', 'type': 'augmented_assignment', 'children': ['148', '149'], 'value': '+='},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'connection_string'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'host'},{'id': '150', 'type': 'if_statement', 'children': ['151', '154']},{'id': '151', 'type': 'comparison_operator', 'children': ['152', '153'], 'value': 'is'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'port'},{'id': '153', 'type': 'None', 'children': []},{'id': '154', 'type': 'block', 'children': ['155']},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'augmented_assignment', 'children': ['157', '158'], 'value': '+='},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'connection_string'},{'id': '158', 'type': 'binary_operator', 'children': ['159', '160'], 'value': '+'},{'id': '159', 'type': 'string', 'children': [], 'value': "':'"},{'id': '160', 'type': 'call', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '162', 'type': 'argument_list', 'children': ['163']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'port'},{'id': '164', 'type': 'expression_statement', 'children': ['165']},{'id': '165', 'type': 'augmented_assignment', 'children': ['166', '167'], 'value': '+='},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'connection_string'},{'id': '167', 'type': 'binary_operator', 'children': ['168', '169'], 'value': '+'},{'id': '168', 'type': 'string', 'children': [], 'value': "'/'"},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'database'},{'id': '170', 'type': 'return_statement', 'children': ['171']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'connection_string'}
def get_connection_string(params, hide_password=True): 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 None and user is not None: password = Client._get_password(params) if password is None: raise RuntimeError("Password not defined and not available in keyring.") if host is not None: if user is not None: connection_string += user 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) connection_string += '/' + database return connection_string
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '4']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'movie_network'},{'id': '3', 'type': 'parameters', 'children': []},{'id': '4', 'type': 'block', 'children': ['5', '14', '20', '28', '36', '69', '78', '96', '105', '156', '165', '186', '192', '198', '210', '277', '329', '364', '378', '388', '398', '417', '424']},{'id': '5', 'type': 'expression_statement', 'children': ['6']},{'id': '6', 'type': 'assignment', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'template'},{'id': '8', 'type': 'call', 'children': ['9', '12']},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'jenv'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'get_template'},{'id': '12', 'type': 'argument_list', 'children': ['13']},{'id': '13', 'type': 'string', 'children': [], 'value': '"movie_network.html"'},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '19', 'type': 'argument_list', 'children': []},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'cl'},{'id': '23', 'type': 'call', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'client'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'get_client'},{'id': '27', 'type': 'argument_list', 'children': []},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '31', 'type': 'call', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'cl'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'create_session'},{'id': '35', 'type': 'argument_list', 'children': []},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '39', 'type': 'call', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '43', 'type': 'argument_list', 'children': ['44', '49', '54', '59', '64']},{'id': '44', 'type': 'attribute', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'Movie'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '49', 'type': 'attribute', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'Movie'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '54', 'type': 'attribute', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'Movie'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '59', 'type': 'attribute', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'Movie'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'budget_inflation_adjusted'},{'id': '64', 'type': 'attribute', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'Movie'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'imdb_rating'},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'movies'},{'id': '72', 'type': 'call', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'cl'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'df_query'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '81', 'type': 'call', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '85', 'type': 'argument_list', 'children': ['86', '91']},{'id': '86', 'type': 'attribute', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'MovieAppearance'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'movie_id'},{'id': '91', 'type': 'attribute', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'MovieAppearance'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'character_id'},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'assignment', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'appearances'},{'id': '99', 'type': 'call', 'children': ['100', '103']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'cl'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'df_query'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'assignment', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '108', 'type': 'call', 'children': ['109', '132']},{'id': '109', 'type': 'attribute', 'children': ['110', '130', '131']},{'id': '110', 'type': 'call', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '114', 'type': 'argument_list', 'children': ['115', '120', '125']},{'id': '115', 'type': 'attribute', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'Character'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '120', 'type': 'attribute', 'children': ['121', '124']},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'Character'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '125', 'type': 'attribute', 'children': ['126', '129']},{'id': '126', 'type': 'attribute', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'Character'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '130', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'call', 'children': ['134', '141']},{'id': '134', 'type': 'attribute', 'children': ['135', '140']},{'id': '135', 'type': 'attribute', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'Character'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'in_'},{'id': '141', 'type': 'argument_list', 'children': ['142']},{'id': '142', 'type': 'list_comprehension', 'children': ['143', '147']},{'id': '143', 'type': 'call', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '145', 'type': 'argument_list', 'children': ['146']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '147', 'type': 'for_in_clause', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '149', 'type': 'call', 'children': ['150', '155']},{'id': '150', 'type': 'attribute', 'children': ['151', '154']},{'id': '151', 'type': 'subscript', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'appearances'},{'id': '153', 'type': 'string', 'children': [], 'value': "'character_id'"},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'unique'},{'id': '155', 'type': 'argument_list', 'children': []},{'id': '156', 'type': 'expression_statement', 'children': ['157']},{'id': '157', 'type': 'assignment', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'characters'},{'id': '159', 'type': 'call', 'children': ['160', '163']},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'cl'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'df_query'},{'id': '163', 'type': 'argument_list', 'children': ['164']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '165', 'type': 'expression_statement', 'children': ['166']},{'id': '166', 'type': 'assignment', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '168', 'type': 'call', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '170', 'type': 'argument_list', 'children': ['171', '174', '177', '180', '183']},{'id': '171', 'type': 'keyword_argument', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '173', 'type': 'list', 'children': [], 'value': '[]'},{'id': '174', 'type': 'keyword_argument', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '176', 'type': 'list', 'children': [], 'value': '[]'},{'id': '177', 'type': 'keyword_argument', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'links'},{'id': '179', 'type': 'list', 'children': [], 'value': '[]'},{'id': '180', 'type': 'keyword_argument', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'directed'},{'id': '182', 'type': 'False', 'children': []},{'id': '183', 'type': 'keyword_argument', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'multigraph'},{'id': '185', 'type': 'True', 'children': []},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'assignment', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'movie_node_id'},{'id': '189', 'type': 'call', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '191', 'type': 'argument_list', 'children': []},{'id': '192', 'type': 'expression_statement', 'children': ['193']},{'id': '193', 'type': 'assignment', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'character_node_id'},{'id': '195', 'type': 'call', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '197', 'type': 'argument_list', 'children': []},{'id': '198', 'type': 'expression_statement', 'children': ['199']},{'id': '199', 'type': 'assignment', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'movie_size_factor'},{'id': '201', 'type': 'binary_operator', 'children': ['202', '203'], 'value': '/'},{'id': '202', 'type': 'float', 'children': [], 'value': '100.'},{'id': '203', 'type': 'call', 'children': ['204', '209']},{'id': '204', 'type': 'attribute', 'children': ['205', '208']},{'id': '205', 'type': 'subscript', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'movies'},{'id': '207', 'type': 'string', 'children': [], 'value': "'budget_inflation_adjusted'"},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '209', 'type': 'argument_list', 'children': []},{'id': '210', 'type': 'for_statement', 'children': ['211', '214', '219']},{'id': '211', 'type': 'pattern_list', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '214', 'type': 'call', 'children': ['215', '218']},{'id': '215', 'type': 'attribute', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'movies'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'iterrows'},{'id': '218', 'type': 'argument_list', 'children': []},{'id': '219', 'type': 'block', 'children': ['220', '233']},{'id': '220', 'type': 'expression_statement', 'children': ['221']},{'id': '221', 'type': 'assignment', 'children': ['222', '227']},{'id': '222', 'type': 'subscript', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'movie_node_id'},{'id': '224', 'type': 'subscript', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '226', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '227', 'type': 'call', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '229', 'type': 'argument_list', 'children': ['230']},{'id': '230', 'type': 'subscript', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '232', 'type': 'string', 'children': [], 'value': "'nodes'"},{'id': '233', 'type': 'expression_statement', 'children': ['234']},{'id': '234', 'type': 'call', 'children': ['235', '240']},{'id': '235', 'type': 'attribute', 'children': ['236', '239']},{'id': '236', 'type': 'subscript', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '238', 'type': 'string', 'children': [], 'value': "'nodes'"},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '240', 'type': 'argument_list', 'children': ['241']},{'id': '241', 'type': 'call', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '243', 'type': 'argument_list', 'children': ['244', '249', '260', '267', '270']},{'id': '244', 'type': 'keyword_argument', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '246', 'type': 'subscript', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '248', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '249', 'type': 'keyword_argument', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '251', 'type': 'call', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '253', 'type': 'argument_list', 'children': ['254', '255']},{'id': '254', 'type': 'float', 'children': [], 'value': '5.'},{'id': '255', 'type': 'binary_operator', 'children': ['256', '259'], 'value': '*'},{'id': '256', 'type': 'subscript', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '258', 'type': 'string', 'children': [], 'value': "'budget_inflation_adjusted'"},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'movie_size_factor'},{'id': '260', 'type': 'keyword_argument', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'score'},{'id': '262', 'type': 'binary_operator', 'children': ['263', '266'], 'value': '/'},{'id': '263', 'type': 'subscript', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '265', 'type': 'string', 'children': [], 'value': "'imdb_rating'"},{'id': '266', 'type': 'float', 'children': [], 'value': '10.'},{'id': '267', 'type': 'keyword_argument', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '269', 'type': 'string', 'children': [], 'value': "'square'"},{'id': '270', 'type': 'keyword_argument', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '272', 'type': 'binary_operator', 'children': ['273', '274'], 'value': '+'},{'id': '273', 'type': 'string', 'children': [], 'value': '"http://marvel.wikia.com"'},{'id': '274', 'type': 'subscript', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '276', 'type': 'string', 'children': [], 'value': "'url'"},{'id': '277', 'type': 'for_statement', 'children': ['278', '281', '286']},{'id': '278', 'type': 'pattern_list', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '281', 'type': 'call', 'children': ['282', '285']},{'id': '282', 'type': 'attribute', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'characters'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'iterrows'},{'id': '285', 'type': 'argument_list', 'children': []},{'id': '286', 'type': 'block', 'children': ['287', '300']},{'id': '287', 'type': 'expression_statement', 'children': ['288']},{'id': '288', 'type': 'assignment', 'children': ['289', '294']},{'id': '289', 'type': 'subscript', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'character_node_id'},{'id': '291', 'type': 'subscript', 'children': ['292', '293']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '293', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '294', 'type': 'call', 'children': ['295', '296']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '296', 'type': 'argument_list', 'children': ['297']},{'id': '297', 'type': 'subscript', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '299', 'type': 'string', 'children': [], 'value': "'nodes'"},{'id': '300', 'type': 'expression_statement', 'children': ['301']},{'id': '301', 'type': 'call', 'children': ['302', '307']},{'id': '302', 'type': 'attribute', 'children': ['303', '306']},{'id': '303', 'type': 'subscript', 'children': ['304', '305']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '305', 'type': 'string', 'children': [], 'value': "'nodes'"},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '307', 'type': 'argument_list', 'children': ['308']},{'id': '308', 'type': 'call', 'children': ['309', '310']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '310', 'type': 'argument_list', 'children': ['311', '316', '319', '322']},{'id': '311', 'type': 'keyword_argument', 'children': ['312', '313']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '313', 'type': 'subscript', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '315', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '316', 'type': 'keyword_argument', 'children': ['317', '318']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '318', 'type': 'integer', 'children': [], 'value': '10'},{'id': '319', 'type': 'keyword_argument', 'children': ['320', '321']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '321', 'type': 'string', 'children': [], 'value': "'circle'"},{'id': '322', 'type': 'keyword_argument', 'children': ['323', '324']},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '324', 'type': 'binary_operator', 'children': ['325', '326'], 'value': '+'},{'id': '325', 'type': 'string', 'children': [], 'value': '"http://marvel.wikia.com"'},{'id': '326', 'type': 'subscript', 'children': ['327', '328']},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '328', 'type': 'string', 'children': [], 'value': "'url'"},{'id': '329', 'type': 'for_statement', 'children': ['330', '333', '338']},{'id': '330', 'type': 'pattern_list', 'children': ['331', '332']},{'id': '331', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '333', 'type': 'call', 'children': ['334', '337']},{'id': '334', 'type': 'attribute', 'children': ['335', '336']},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'appearances'},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'iterrows'},{'id': '337', 'type': 'argument_list', 'children': []},{'id': '338', 'type': 'block', 'children': ['339']},{'id': '339', 'type': 'expression_statement', 'children': ['340']},{'id': '340', 'type': 'call', 'children': ['341', '346']},{'id': '341', 'type': 'attribute', 'children': ['342', '345']},{'id': '342', 'type': 'subscript', 'children': ['343', '344']},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '344', 'type': 'string', 'children': [], 'value': "'links'"},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '346', 'type': 'argument_list', 'children': ['347']},{'id': '347', 'type': 'call', 'children': ['348', '349']},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '349', 'type': 'argument_list', 'children': ['350', '357']},{'id': '350', 'type': 'keyword_argument', 'children': ['351', '352']},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '352', 'type': 'subscript', 'children': ['353', '354']},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'movie_node_id'},{'id': '354', 'type': 'subscript', 'children': ['355', '356']},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '356', 'type': 'string', 'children': [], 'value': "'movie_id'"},{'id': '357', 'type': 'keyword_argument', 'children': ['358', '359']},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '359', 'type': 'subscript', 'children': ['360', '361']},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'character_node_id'},{'id': '361', 'type': 'subscript', 'children': ['362', '363']},{'id': '362', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '363', 'type': 'string', 'children': [], 'value': "'character_id'"},{'id': '364', 'type': 'expression_statement', 'children': ['365']},{'id': '365', 'type': 'assignment', 'children': ['366', '369']},{'id': '366', 'type': 'subscript', 'children': ['367', '368']},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '368', 'type': 'string', 'children': [], 'value': "'graph'"},{'id': '369', 'type': 'call', 'children': ['370', '373']},{'id': '370', 'type': 'attribute', 'children': ['371', '372']},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '372', 'type': 'identifier', 'children': [], 'value': 'dumps'},{'id': '373', 'type': 'argument_list', 'children': ['374', '375']},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '375', 'type': 'keyword_argument', 'children': ['376', '377']},{'id': '376', 'type': 'identifier', 'children': [], 'value': 'indent'},{'id': '377', 'type': 'integer', 'children': [], 'value': '4'},{'id': '378', 'type': 'expression_statement', 'children': ['379']},{'id': '379', 'type': 'assignment', 'children': ['380', '381']},{'id': '380', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '381', 'type': 'call', 'children': ['382', '385']},{'id': '382', 'type': 'attribute', 'children': ['383', '384']},{'id': '383', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '384', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '385', 'type': 'argument_list', 'children': ['386', '387']},{'id': '386', 'type': 'identifier', 'children': [], 'value': 'out_dir'},{'id': '387', 'type': 'string', 'children': [], 'value': '"movie_network.html"'},{'id': '388', 'type': 'expression_statement', 'children': ['389']},{'id': '389', 'type': 'assignment', 'children': ['390', '391']},{'id': '390', 'type': 'identifier', 'children': [], 'value': 'html_content'},{'id': '391', 'type': 'call', 'children': ['392', '395']},{'id': '392', 'type': 'attribute', 'children': ['393', '394']},{'id': '393', 'type': 'identifier', 'children': [], 'value': 'template'},{'id': '394', 'type': 'identifier', 'children': [], 'value': 'render'},{'id': '395', 'type': 'argument_list', 'children': ['396']},{'id': '396', 'type': 'dictionary_splat', 'children': ['397']},{'id': '397', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '398', 'type': 'with_statement', 'children': ['399', '409']},{'id': '399', 'type': 'with_clause', 'children': ['400']},{'id': '400', 'type': 'with_item', 'children': ['401']},{'id': '401', 'type': 'as_pattern', 'children': ['402', '407']},{'id': '402', 'type': 'call', 'children': ['403', '404']},{'id': '403', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '404', 'type': 'argument_list', 'children': ['405', '406']},{'id': '405', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '406', 'type': 'string', 'children': [], 'value': "'w'"},{'id': '407', 'type': 'as_pattern_target', 'children': ['408']},{'id': '408', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '409', 'type': 'block', 'children': ['410']},{'id': '410', 'type': 'expression_statement', 'children': ['411']},{'id': '411', 'type': 'call', 'children': ['412', '415']},{'id': '412', 'type': 'attribute', 'children': ['413', '414']},{'id': '413', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '414', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '415', 'type': 'argument_list', 'children': ['416']},{'id': '416', 'type': 'identifier', 'children': [], 'value': 'html_content'},{'id': '417', 'type': 'expression_statement', 'children': ['418']},{'id': '418', 'type': 'call', 'children': ['419', '422']},{'id': '419', 'type': 'attribute', 'children': ['420', '421']},{'id': '420', 'type': 'identifier', 'children': [], 'value': 'plt'},{'id': '421', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '422', 'type': 'argument_list', 'children': ['423']},{'id': '423', 'type': 'string', 'children': [], 'value': "'all'"},{'id': '424', 'type': 'expression_statement', 'children': ['425']},{'id': '425', 'type': 'call', 'children': ['426', '429']},{'id': '426', 'type': 'attribute', 'children': ['427', '428']},{'id': '427', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '428', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '429', 'type': 'argument_list', 'children': []}
def movie_network(): template = jenv.get_template("movie_network.html") context = dict() cl = client.get_client() session = cl.create_session() 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) query = session.query(models.MovieAppearance.movie_id, models.MovieAppearance.character_id) appearances = cl.df_query(query) 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) graph = dict(nodes=[], graph=[], links=[], directed=False, multigraph=True) movie_node_id = dict() character_node_id = dict() movie_size_factor = 100. / movies['budget_inflation_adjusted'].max() for _, data in movies.iterrows(): movie_node_id[data['id']] = len(graph['nodes']) 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'])) for _, data in characters.iterrows(): character_node_id[data['id']] = len(graph['nodes']) graph['nodes'].append(dict(id=data['name'], size=10, type='circle', url="http://marvel.wikia.com" + data['url'])) for _, data in appearances.iterrows(): 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) 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) plt.close('all') session.close()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '19']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'better_exchook'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13', '16']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'etype'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'tb'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'debugshell'},{'id': '9', 'type': 'False', 'children': []},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'autodebugshell'},{'id': '12', 'type': 'True', 'children': []},{'id': '13', 'type': 'default_parameter', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '15', 'type': 'None', 'children': []},{'id': '16', 'type': 'default_parameter', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'with_color'},{'id': '18', 'type': 'None', 'children': []},{'id': '19', 'type': 'block', 'children': ['20', '31', '45', '54', '70', '78', '120', '123', '147', '205', '261', '283', '304']},{'id': '20', 'type': 'if_statement', 'children': ['21', '24']},{'id': '21', 'type': 'comparison_operator', 'children': ['22', '23'], 'value': 'is'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '23', 'type': 'None', 'children': []},{'id': '24', 'type': 'block', 'children': ['25']},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '31', 'type': 'function_definition', 'children': ['32', '33', '35']},{'id': '32', 'type': 'function_name', 'children': [], 'value': 'output'},{'id': '33', 'type': 'parameters', 'children': ['34']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'ln'},{'id': '35', 'type': 'block', 'children': ['36']},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'call', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'binary_operator', 'children': ['43', '44'], 'value': '+'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'ln'},{'id': '44', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'color'},{'id': '48', 'type': 'call', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'Color'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'keyword_argument', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'enable'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'with_color'},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'call', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'call', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'color'},{'id': '60', 'type': 'argument_list', 'children': ['61', '62', '67']},{'id': '61', 'type': 'string', 'children': [], 'value': '"EXCEPTION"'},{'id': '62', 'type': 'subscript', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'color'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'fg_colors'},{'id': '66', 'type': 'integer', 'children': [], 'value': '1'},{'id': '67', 'type': 'keyword_argument', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'bold'},{'id': '69', 'type': 'True', 'children': []},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '75']},{'id': '72', 'type': 'pattern_list', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'all_locals'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'all_globals'},{'id': '75', 'type': 'expression_list', 'children': ['76', '77']},{'id': '76', 'type': 'dictionary', 'children': []},{'id': '77', 'type': 'dictionary', 'children': []},{'id': '78', 'type': 'if_statement', 'children': ['79', '82', '105']},{'id': '79', 'type': 'comparison_operator', 'children': ['80', '81'], 'value': 'is'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'tb'},{'id': '81', 'type': 'None', 'children': []},{'id': '82', 'type': 'block', 'children': ['83']},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'call', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'print_tb'},{'id': '86', 'type': 'argument_list', 'children': ['87', '88', '91', '94', '97', '100']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'tb'},{'id': '88', 'type': 'keyword_argument', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'allLocals'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'all_locals'},{'id': '91', 'type': 'keyword_argument', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'allGlobals'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'all_globals'},{'id': '94', 'type': 'keyword_argument', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '97', 'type': 'keyword_argument', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'withTitle'},{'id': '99', 'type': 'True', 'children': []},{'id': '100', 'type': 'keyword_argument', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'with_color'},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'color'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'enable'},{'id': '105', 'type': 'else_clause', 'children': ['106']},{'id': '106', 'type': 'block', 'children': ['107']},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'call', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '110', 'type': 'argument_list', 'children': ['111']},{'id': '111', 'type': 'call', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'color'},{'id': '113', 'type': 'argument_list', 'children': ['114', '115']},{'id': '114', 'type': 'string', 'children': [], 'value': '"better_exchook: traceback unknown"'},{'id': '115', 'type': 'subscript', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'color'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'fg_colors'},{'id': '119', 'type': 'integer', 'children': [], 'value': '1'},{'id': '120', 'type': 'import_statement', 'children': ['121']},{'id': '121', 'type': 'dotted_name', 'children': ['122']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'types'},{'id': '123', 'type': 'function_definition', 'children': ['124', '125', '127']},{'id': '124', 'type': 'function_name', 'children': [], 'value': '_some_str'},{'id': '125', 'type': 'parameters', 'children': ['126']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '127', 'type': 'block', 'children': ['128']},{'id': '128', 'type': 'try_statement', 'children': ['129', '135']},{'id': '129', 'type': 'block', 'children': ['130']},{'id': '130', 'type': 'return_statement', 'children': ['131']},{'id': '131', 'type': 'call', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '133', 'type': 'argument_list', 'children': ['134']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '135', 'type': 'except_clause', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '137', 'type': 'block', 'children': ['138']},{'id': '138', 'type': 'return_statement', 'children': ['139']},{'id': '139', 'type': 'binary_operator', 'children': ['140', '141'], 'value': '%'},{'id': '140', 'type': 'string', 'children': [], 'value': "'<unprintable %s object>'"},{'id': '141', 'type': 'attribute', 'children': ['142', '146']},{'id': '142', 'type': 'call', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '144', 'type': 'argument_list', 'children': ['145']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '146', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '147', 'type': 'function_definition', 'children': ['148', '149', '152']},{'id': '148', 'type': 'function_name', 'children': [], 'value': '_format_final_exc_line'},{'id': '149', 'type': 'parameters', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'etype'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '152', 'type': 'block', 'children': ['153', '160', '203']},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'assignment', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'value_str'},{'id': '156', 'type': 'call', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': '_some_str'},{'id': '158', 'type': 'argument_list', 'children': ['159']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '160', 'type': 'if_statement', 'children': ['161', '167', '182']},{'id': '161', 'type': 'boolean_operator', 'children': ['162', '165'], 'value': 'or'},{'id': '162', 'type': 'comparison_operator', 'children': ['163', '164'], 'value': 'is'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '164', 'type': 'None', 'children': []},{'id': '165', 'type': 'not_operator', 'children': ['166']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'value_str'},{'id': '167', 'type': 'block', 'children': ['168']},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'id': '169', 'type': 'assignment', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '171', 'type': 'call', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'color'},{'id': '173', 'type': 'argument_list', 'children': ['174', '177']},{'id': '174', 'type': 'binary_operator', 'children': ['175', '176'], 'value': '%'},{'id': '175', 'type': 'string', 'children': [], 'value': '"%s"'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'etype'},{'id': '177', 'type': 'subscript', 'children': ['178', '181']},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'color'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'fg_colors'},{'id': '181', 'type': 'integer', 'children': [], 'value': '1'},{'id': '182', 'type': 'else_clause', 'children': ['183']},{'id': '183', 'type': 'block', 'children': ['184']},{'id': '184', 'type': 'expression_statement', 'children': ['185']},{'id': '185', 'type': 'assignment', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '187', 'type': 'binary_operator', 'children': ['188', '199'], 'value': '+'},{'id': '188', 'type': 'call', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'color'},{'id': '190', 'type': 'argument_list', 'children': ['191', '194']},{'id': '191', 'type': 'binary_operator', 'children': ['192', '193'], 'value': '%'},{'id': '192', 'type': 'string', 'children': [], 'value': '"%s"'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'etype'},{'id': '194', 'type': 'subscript', 'children': ['195', '198']},{'id': '195', 'type': 'attribute', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'color'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'fg_colors'},{'id': '198', 'type': 'integer', 'children': [], 'value': '1'},{'id': '199', 'type': 'binary_operator', 'children': ['200', '201'], 'value': '%'},{'id': '200', 'type': 'string', 'children': [], 'value': '": %s"'},{'id': '201', 'type': 'tuple', 'children': ['202']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'value_str'},{'id': '203', 'type': 'return_statement', 'children': ['204']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '205', 'type': 'if_statement', 'children': ['206', '238', '248']},{'id': '206', 'type': '()', 'children': ['207']},{'id': '207', 'type': 'boolean_operator', 'children': ['208', '232'], 'value': 'or'},{'id': '208', 'type': 'boolean_operator', 'children': ['209', '229'], 'value': 'or'},{'id': '209', 'type': 'boolean_operator', 'children': ['210', '215'], 'value': 'or'},{'id': '210', 'type': 'call', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '212', 'type': 'argument_list', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'etype'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'BaseException'},{'id': '215', 'type': '()', 'children': ['216']},{'id': '216', 'type': 'boolean_operator', 'children': ['217', '222'], 'value': 'and'},{'id': '217', 'type': 'call', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '219', 'type': 'argument_list', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'types'},{'id': '221', 'type': 'string', 'children': [], 'value': '"InstanceType"'},{'id': '222', 'type': 'call', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '224', 'type': 'argument_list', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'etype'},{'id': '226', 'type': 'attribute', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'types'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'InstanceType'},{'id': '229', 'type': 'comparison_operator', 'children': ['230', '231'], 'value': 'is'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'etype'},{'id': '231', 'type': 'None', 'children': []},{'id': '232', 'type': 'comparison_operator', 'children': ['233', '237'], 'value': 'is'},{'id': '233', 'type': 'call', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '235', 'type': 'argument_list', 'children': ['236']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'etype'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '238', 'type': 'block', 'children': ['239']},{'id': '239', 'type': 'expression_statement', 'children': ['240']},{'id': '240', 'type': 'call', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '242', 'type': 'argument_list', 'children': ['243']},{'id': '243', 'type': 'call', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': '_format_final_exc_line'},{'id': '245', 'type': 'argument_list', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'etype'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '248', 'type': 'else_clause', 'children': ['249']},{'id': '249', 'type': 'block', 'children': ['250']},{'id': '250', 'type': 'expression_statement', 'children': ['251']},{'id': '251', 'type': 'call', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '253', 'type': 'argument_list', 'children': ['254']},{'id': '254', 'type': 'call', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': '_format_final_exc_line'},{'id': '256', 'type': 'argument_list', 'children': ['257', '260']},{'id': '257', 'type': 'attribute', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'etype'},{'id': '259', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '261', 'type': 'if_statement', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'autodebugshell'},{'id': '263', 'type': 'block', 'children': ['264']},{'id': '264', 'type': 'try_statement', 'children': ['265', '279']},{'id': '265', 'type': 'block', 'children': ['266']},{'id': '266', 'type': 'expression_statement', 'children': ['267']},{'id': '267', 'type': 'assignment', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'debugshell'},{'id': '269', 'type': 'comparison_operator', 'children': ['270', '278'], 'value': '!='},{'id': '270', 'type': 'call', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '272', 'type': 'argument_list', 'children': ['273']},{'id': '273', 'type': 'subscript', 'children': ['274', '277']},{'id': '274', 'type': 'attribute', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'environ'},{'id': '277', 'type': 'string', 'children': [], 'value': '"DEBUG"'},{'id': '278', 'type': 'integer', 'children': [], 'value': '0'},{'id': '279', 'type': 'except_clause', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '281', 'type': 'block', 'children': ['282']},{'id': '282', 'type': 'pass_statement', 'children': []},{'id': '283', 'type': 'if_statement', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'debugshell'},{'id': '285', 'type': 'block', 'children': ['286', '291']},{'id': '286', 'type': 'expression_statement', 'children': ['287']},{'id': '287', 'type': 'call', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '289', 'type': 'argument_list', 'children': ['290']},{'id': '290', 'type': 'string', 'children': [], 'value': '"---------- DEBUG SHELL -----------"'},{'id': '291', 'type': 'expression_statement', 'children': ['292']},{'id': '292', 'type': 'call', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'debug_shell'},{'id': '294', 'type': 'argument_list', 'children': ['295', '298', '301']},{'id': '295', 'type': 'keyword_argument', 'children': ['296', '297']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'user_ns'},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'all_locals'},{'id': '298', 'type': 'keyword_argument', 'children': ['299', '300']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'user_global_ns'},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'all_globals'},{'id': '301', 'type': 'keyword_argument', 'children': ['302', '303']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'traceback'},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'tb'},{'id': '304', 'type': 'expression_statement', 'children': ['305']},{'id': '305', 'type': 'call', 'children': ['306', '309']},{'id': '306', 'type': 'attribute', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'flush'},{'id': '309', 'type': 'argument_list', 'children': []}
def better_exchook(etype, value, tb, debugshell=False, autodebugshell=True, file=None, with_color=None): if file is None: file = sys.stderr def output(ln): 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 def _some_str(value): try: return str(value) except Exception: return '<unprintable %s object>' % type(value).__name__ 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 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: 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()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'dump_all_thread_tracebacks'},{'id': '3', 'type': 'parameters', 'children': ['4', '7']},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'exclude_thread_ids'},{'id': '6', 'type': 'None', 'children': []},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'block', 'children': ['11', '20', '30', '33']},{'id': '11', 'type': 'if_statement', 'children': ['12', '15']},{'id': '12', 'type': 'comparison_operator', 'children': ['13', '14'], 'value': 'is'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'exclude_thread_ids'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'block', 'children': ['16']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'exclude_thread_ids'},{'id': '19', 'type': 'list', 'children': [], 'value': '[]'},{'id': '20', 'type': 'if_statement', 'children': ['21', '23']},{'id': '21', 'type': 'not_operator', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '23', 'type': 'block', 'children': ['24']},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '30', 'type': 'import_statement', 'children': ['31']},{'id': '31', 'type': 'dotted_name', 'children': ['32']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'threading'},{'id': '33', 'type': 'if_statement', 'children': ['34', '39', '198']},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '36', 'type': 'argument_list', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '38', 'type': 'string', 'children': [], 'value': '"_current_frames"'},{'id': '39', 'type': 'block', 'children': ['40', '48', '64', '190']},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '43', 'type': 'argument_list', 'children': ['44', '45']},{'id': '44', 'type': 'string', 'children': [], 'value': '""'},{'id': '45', 'type': 'keyword_argument', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'threads'},{'id': '51', 'type': 'dictionary_comprehension', 'children': ['52', '57']},{'id': '52', 'type': 'pair', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'ident'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '57', 'type': 'for_in_clause', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'threading'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '63', 'type': 'argument_list', 'children': []},{'id': '64', 'type': 'for_statement', 'children': ['65', '68', '77']},{'id': '65', 'type': 'pattern_list', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'tid'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'stack'},{'id': '68', 'type': 'call', 'children': ['69', '76']},{'id': '69', 'type': 'attribute', 'children': ['70', '75']},{'id': '70', 'type': 'call', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '73', 'type': 'identifier', 'children': [], 'value': '_current_frames'},{'id': '74', 'type': 'argument_list', 'children': []},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '76', 'type': 'argument_list', 'children': []},{'id': '77', 'type': 'block', 'children': ['78', '84', '90', '94', '103', '159', '174', '182']},{'id': '78', 'type': 'if_statement', 'children': ['79', '82']},{'id': '79', 'type': 'comparison_operator', 'children': ['80', '81'], 'value': 'in'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'tid'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'exclude_thread_ids'},{'id': '82', 'type': 'block', 'children': ['83']},{'id': '83', 'type': 'continue_statement', 'children': []},{'id': '84', 'type': 'if_statement', 'children': ['85', '88']},{'id': '85', 'type': 'comparison_operator', 'children': ['86', '87'], 'value': 'not'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'tid'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'threads'},{'id': '88', 'type': 'block', 'children': ['89']},{'id': '89', 'type': 'continue_statement', 'children': []},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'tags'},{'id': '93', 'type': 'list', 'children': [], 'value': '[]'},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'assignment', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'thread'},{'id': '97', 'type': 'call', 'children': ['98', '101']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'threads'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '101', 'type': 'argument_list', 'children': ['102']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'tid'},{'id': '103', 'type': 'if_statement', 'children': ['104', '105', '150']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'thread'},{'id': '105', 'type': 'block', 'children': ['106', '114', '128', '142']},{'id': '106', 'type': 'assert_statement', 'children': ['107']},{'id': '107', 'type': 'call', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '109', 'type': 'argument_list', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'thread'},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'threading'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'Thread'},{'id': '114', 'type': 'if_statement', 'children': ['115', '122']},{'id': '115', 'type': 'comparison_operator', 'children': ['116', '117'], 'value': 'is'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'thread'},{'id': '117', 'type': 'call', 'children': ['118', '121']},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'threading'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'currentThread'},{'id': '121', 'type': 'argument_list', 'children': []},{'id': '122', 'type': 'block', 'children': ['123']},{'id': '123', 'type': 'expression_statement', 'children': ['124']},{'id': '124', 'type': 'augmented_assignment', 'children': ['125', '126'], 'value': '+='},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'tags'},{'id': '126', 'type': 'list', 'children': ['127'], 'value': '["current"]'},{'id': '127', 'type': 'string', 'children': [], 'value': '"current"'},{'id': '128', 'type': 'if_statement', 'children': ['129', '136']},{'id': '129', 'type': 'call', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '131', 'type': 'argument_list', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'thread'},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'threading'},{'id': '135', 'type': 'identifier', 'children': [], 'value': '_MainThread'},{'id': '136', 'type': 'block', 'children': ['137']},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'augmented_assignment', 'children': ['139', '140'], 'value': '+='},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'tags'},{'id': '140', 'type': 'list', 'children': ['141'], 'value': '["main"]'},{'id': '141', 'type': 'string', 'children': [], 'value': '"main"'},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'augmented_assignment', 'children': ['144', '145'], 'value': '+='},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'tags'},{'id': '145', 'type': 'list', 'children': ['146'], 'value': '[str(thread)]'},{'id': '146', 'type': 'call', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '148', 'type': 'argument_list', 'children': ['149']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'thread'},{'id': '150', 'type': 'else_clause', 'children': ['151']},{'id': '151', 'type': 'block', 'children': ['152']},{'id': '152', 'type': 'expression_statement', 'children': ['153']},{'id': '153', 'type': 'augmented_assignment', 'children': ['154', '155'], 'value': '+='},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'tags'},{'id': '155', 'type': 'list', 'children': ['156'], 'value': '["unknown with id %i" % tid]'},{'id': '156', 'type': 'binary_operator', 'children': ['157', '158'], 'value': '%'},{'id': '157', 'type': 'string', 'children': [], 'value': '"unknown with id %i"'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'tid'},{'id': '159', 'type': 'expression_statement', 'children': ['160']},{'id': '160', 'type': 'call', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '162', 'type': 'argument_list', 'children': ['163', '171']},{'id': '163', 'type': 'binary_operator', 'children': ['164', '165'], 'value': '%'},{'id': '164', 'type': 'string', 'children': [], 'value': '"Thread %s:"'},{'id': '165', 'type': 'call', 'children': ['166', '169']},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'string', 'children': [], 'value': '", "'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '169', 'type': 'argument_list', 'children': ['170']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'tags'},{'id': '171', 'type': 'keyword_argument', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'id': '175', 'type': 'call', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'print_tb'},{'id': '177', 'type': 'argument_list', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'stack'},{'id': '179', 'type': 'keyword_argument', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '182', 'type': 'expression_statement', 'children': ['183']},{'id': '183', 'type': 'call', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '185', 'type': 'argument_list', 'children': ['186', '187']},{'id': '186', 'type': 'string', 'children': [], 'value': '""'},{'id': '187', 'type': 'keyword_argument', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '190', 'type': 'expression_statement', 'children': ['191']},{'id': '191', 'type': 'call', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '193', 'type': 'argument_list', 'children': ['194', '195']},{'id': '194', 'type': 'string', 'children': [], 'value': '"That were all threads."'},{'id': '195', 'type': 'keyword_argument', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '198', 'type': 'else_clause', 'children': ['199']},{'id': '199', 'type': 'block', 'children': ['200']},{'id': '200', 'type': 'expression_statement', 'children': ['201']},{'id': '201', 'type': 'call', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '203', 'type': 'argument_list', 'children': ['204', '205']},{'id': '204', 'type': 'string', 'children': [], 'value': '"Does not have sys._current_frames, cannot get thread tracebacks."'},{'id': '205', 'type': 'keyword_argument', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'file'}
def dump_all_thread_tracebacks(exclude_thread_ids=None, file=None): 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()} for tid, stack in sys._current_frames().items(): if tid in exclude_thread_ids: continue 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"] 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)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '4']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_main'},{'id': '3', 'type': 'parameters', 'children': []},{'id': '4', 'type': 'block', 'children': ['5', '160', '210', '235', '272', '285', '298', '317', '337', '341']},{'id': '5', 'type': 'if_statement', 'children': ['6', '16', '64', '92', '133']},{'id': '6', 'type': 'comparison_operator', 'children': ['7', '14'], 'value': '=='},{'id': '7', 'type': 'subscript', 'children': ['8', '11']},{'id': '8', 'type': 'attribute', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'argv'},{'id': '11', 'type': 'slice', 'children': ['12', '13']},{'id': '12', 'type': 'integer', 'children': [], 'value': '1'},{'id': '13', 'type': 'colon', 'children': []},{'id': '14', 'type': 'list', 'children': ['15'], 'value': '["test"]'},{'id': '15', 'type': 'string', 'children': [], 'value': '"test"'},{'id': '16', 'type': 'block', 'children': ['17', '53', '58']},{'id': '17', 'type': 'for_statement', 'children': ['18', '21', '31']},{'id': '18', 'type': 'pattern_list', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'call', 'children': ['25', '30']},{'id': '25', 'type': 'attribute', 'children': ['26', '29']},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'globals'},{'id': '28', 'type': 'argument_list', 'children': []},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '30', 'type': 'argument_list', 'children': []},{'id': '31', 'type': 'block', 'children': ['32', '42', '49']},{'id': '32', 'type': 'if_statement', 'children': ['33', '40']},{'id': '33', 'type': 'not_operator', 'children': ['34']},{'id': '34', 'type': 'call', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'string', 'children': [], 'value': '"test_"'},{'id': '40', 'type': 'block', 'children': ['41']},{'id': '41', 'type': 'continue_statement', 'children': []},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'call', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'binary_operator', 'children': ['47', '48'], 'value': '%'},{'id': '47', 'type': 'string', 'children': [], 'value': '"running: %s()"'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '52', 'type': 'argument_list', 'children': []},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'string', 'children': [], 'value': '"ok."'},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'exit'},{'id': '63', 'type': 'argument_list', 'children': []},{'id': '64', 'type': 'elif_clause', 'children': ['65', '75']},{'id': '65', 'type': 'comparison_operator', 'children': ['66', '73'], 'value': '=='},{'id': '66', 'type': 'subscript', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'argv'},{'id': '70', 'type': 'slice', 'children': ['71', '72']},{'id': '71', 'type': 'integer', 'children': [], 'value': '1'},{'id': '72', 'type': 'colon', 'children': []},{'id': '73', 'type': 'list', 'children': ['74'], 'value': '["debug_shell"]'},{'id': '74', 'type': 'string', 'children': [], 'value': '"debug_shell"'},{'id': '75', 'type': 'block', 'children': ['76', '86']},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'call', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'debug_shell'},{'id': '79', 'type': 'argument_list', 'children': ['80', '83']},{'id': '80', 'type': 'call', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'locals'},{'id': '82', 'type': 'argument_list', 'children': []},{'id': '83', 'type': 'call', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'globals'},{'id': '85', 'type': 'argument_list', 'children': []},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'call', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'exit'},{'id': '91', 'type': 'argument_list', 'children': []},{'id': '92', 'type': 'elif_clause', 'children': ['93', '103']},{'id': '93', 'type': 'comparison_operator', 'children': ['94', '101'], 'value': '=='},{'id': '94', 'type': 'subscript', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'argv'},{'id': '98', 'type': 'slice', 'children': ['99', '100']},{'id': '99', 'type': 'integer', 'children': [], 'value': '1'},{'id': '100', 'type': 'colon', 'children': []},{'id': '101', 'type': 'list', 'children': ['102'], 'value': '["debug_shell_exception"]'},{'id': '102', 'type': 'string', 'children': [], 'value': '"debug_shell_exception"'},{'id': '103', 'type': 'block', 'children': ['104', '127']},{'id': '104', 'type': 'try_statement', 'children': ['105', '111']},{'id': '105', 'type': 'block', 'children': ['106']},{'id': '106', 'type': 'raise_statement', 'children': ['107']},{'id': '107', 'type': 'call', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'string', 'children': [], 'value': '"demo exception"'},{'id': '111', 'type': 'except_clause', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '113', 'type': 'block', 'children': ['114']},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'call', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'better_exchook'},{'id': '117', 'type': 'argument_list', 'children': ['118', '124']},{'id': '118', 'type': 'list_splat', 'children': ['119']},{'id': '119', 'type': 'call', 'children': ['120', '123']},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'exc_info'},{'id': '123', 'type': 'argument_list', 'children': []},{'id': '124', 'type': 'keyword_argument', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'debugshell'},{'id': '126', 'type': 'True', 'children': []},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'call', 'children': ['129', '132']},{'id': '129', 'type': 'attribute', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'exit'},{'id': '132', 'type': 'argument_list', 'children': []},{'id': '133', 'type': 'elif_clause', 'children': ['134', '141']},{'id': '134', 'type': 'subscript', 'children': ['135', '138']},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'argv'},{'id': '138', 'type': 'slice', 'children': ['139', '140']},{'id': '139', 'type': 'integer', 'children': [], 'value': '1'},{'id': '140', 'type': 'colon', 'children': []},{'id': '141', 'type': 'block', 'children': ['142', '153']},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'call', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '145', 'type': 'argument_list', 'children': ['146']},{'id': '146', 'type': 'binary_operator', 'children': ['147', '148'], 'value': '%'},{'id': '147', 'type': 'string', 'children': [], 'value': '"Usage: %s (test|...)"'},{'id': '148', 'type': 'subscript', 'children': ['149', '152']},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'argv'},{'id': '152', 'type': 'integer', 'children': [], 'value': '0'},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'call', 'children': ['155', '158']},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'exit'},{'id': '158', 'type': 'argument_list', 'children': ['159']},{'id': '159', 'type': 'integer', 'children': [], 'value': '1'},{'id': '160', 'type': 'try_statement', 'children': ['161', '197']},{'id': '161', 'type': 'block', 'children': ['162', '172', '193']},{'id': '162', 'type': 'expression_statement', 'children': ['163']},{'id': '163', 'type': 'assignment', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '165', 'type': 'dictionary', 'children': ['166', '169']},{'id': '166', 'type': 'pair', 'children': ['167', '168']},{'id': '167', 'type': 'integer', 'children': [], 'value': '1'},{'id': '168', 'type': 'integer', 'children': [], 'value': '2'},{'id': '169', 'type': 'pair', 'children': ['170', '171']},{'id': '170', 'type': 'string', 'children': [], 'value': '"a"'},{'id': '171', 'type': 'string', 'children': [], 'value': '"b"'},{'id': '172', 'type': 'function_definition', 'children': ['173', '174', '175']},{'id': '173', 'type': 'function_name', 'children': [], 'value': 'f'},{'id': '174', 'type': 'parameters', 'children': []},{'id': '175', 'type': 'block', 'children': ['176', '180']},{'id': '176', 'type': 'expression_statement', 'children': ['177']},{'id': '177', 'type': 'assignment', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '179', 'type': 'string', 'children': [], 'value': '"foo"'},{'id': '180', 'type': 'expression_statement', 'children': ['181', '182', '183', '188', '191', '192']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '182', 'type': 'integer', 'children': [], 'value': '42'},{'id': '183', 'type': 'attribute', 'children': ['184', '187']},{'id': '184', 'type': 'attribute', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'stdin'},{'id': '187', 'type': 'identifier', 'children': [], 'value': '__class__'},{'id': '188', 'type': 'attribute', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'exc_info'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'z'},{'id': '193', 'type': 'expression_statement', 'children': ['194']},{'id': '194', 'type': 'call', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '196', 'type': 'argument_list', 'children': []},{'id': '197', 'type': 'except_clause', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '199', 'type': 'block', 'children': ['200']},{'id': '200', 'type': 'expression_statement', 'children': ['201']},{'id': '201', 'type': 'call', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'better_exchook'},{'id': '203', 'type': 'argument_list', 'children': ['204']},{'id': '204', 'type': 'list_splat', 'children': ['205']},{'id': '205', 'type': 'call', 'children': ['206', '209']},{'id': '206', 'type': 'attribute', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'exc_info'},{'id': '209', 'type': 'argument_list', 'children': []},{'id': '210', 'type': 'try_statement', 'children': ['211', '222']},{'id': '211', 'type': 'block', 'children': ['212']},{'id': '212', 'type': 'expression_statement', 'children': ['213']},{'id': '213', 'type': 'call', 'children': ['214', '219']},{'id': '214', 'type': '()', 'children': ['215']},{'id': '215', 'type': 'lambda', 'children': ['216', '218']},{'id': '216', 'type': 'lambda_parameters', 'children': ['217']},{'id': '217', 'type': 'identifier', 'children': [], 'value': '_x'},{'id': '218', 'type': 'None', 'children': []},{'id': '219', 'type': 'argument_list', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '221', 'type': 'integer', 'children': [], 'value': '42'},{'id': '222', 'type': 'except_clause', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '224', 'type': 'block', 'children': ['225']},{'id': '225', 'type': 'expression_statement', 'children': ['226']},{'id': '226', 'type': 'call', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'better_exchook'},{'id': '228', 'type': 'argument_list', 'children': ['229']},{'id': '229', 'type': 'list_splat', 'children': ['230']},{'id': '230', 'type': 'call', 'children': ['231', '234']},{'id': '231', 'type': 'attribute', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'exc_info'},{'id': '234', 'type': 'argument_list', 'children': []},{'id': '235', 'type': 'try_statement', 'children': ['236', '259']},{'id': '236', 'type': 'block', 'children': ['237', '250', '256']},{'id': '237', 'type': 'class_definition', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'Obj'},{'id': '239', 'type': 'block', 'children': ['240']},{'id': '240', 'type': 'function_definition', 'children': ['241', '242', '244']},{'id': '241', 'type': 'function_name', 'children': [], 'value': '__repr__'},{'id': '242', 'type': 'parameters', 'children': ['243']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '244', 'type': 'block', 'children': ['245']},{'id': '245', 'type': 'return_statement', 'children': ['246']},{'id': '246', 'type': '()', 'children': ['247']},{'id': '247', 'type': 'binary_operator', 'children': ['248', '249'], 'value': '+'},{'id': '248', 'type': 'string', 'children': [], 'value': '"<Obj multi-\\n"'},{'id': '249', 'type': 'string', 'children': [], 'value': '" line repr>"'},{'id': '250', 'type': 'expression_statement', 'children': ['251']},{'id': '251', 'type': 'assignment', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '253', 'type': 'call', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'Obj'},{'id': '255', 'type': 'argument_list', 'children': []},{'id': '256', 'type': 'assert_statement', 'children': ['257']},{'id': '257', 'type': 'not_operator', 'children': ['258']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '259', 'type': 'except_clause', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '261', 'type': 'block', 'children': ['262']},{'id': '262', 'type': 'expression_statement', 'children': ['263']},{'id': '263', 'type': 'call', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'better_exchook'},{'id': '265', 'type': 'argument_list', 'children': ['266']},{'id': '266', 'type': 'list_splat', 'children': ['267']},{'id': '267', 'type': 'call', 'children': ['268', '271']},{'id': '268', 'type': 'attribute', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'exc_info'},{'id': '271', 'type': 'argument_list', 'children': []},{'id': '272', 'type': 'function_definition', 'children': ['273', '274', '276']},{'id': '273', 'type': 'function_name', 'children': [], 'value': 'f1'},{'id': '274', 'type': 'parameters', 'children': ['275']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '276', 'type': 'block', 'children': ['277']},{'id': '277', 'type': 'expression_statement', 'children': ['278']},{'id': '278', 'type': 'call', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'f2'},{'id': '280', 'type': 'argument_list', 'children': ['281', '284']},{'id': '281', 'type': 'binary_operator', 'children': ['282', '283'], 'value': '+'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '283', 'type': 'integer', 'children': [], 'value': '1'},{'id': '284', 'type': 'integer', 'children': [], 'value': '2'},{'id': '285', 'type': 'function_definition', 'children': ['286', '287', '290']},{'id': '286', 'type': 'function_name', 'children': [], 'value': 'f2'},{'id': '287', 'type': 'parameters', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '290', 'type': 'block', 'children': ['291']},{'id': '291', 'type': 'expression_statement', 'children': ['292']},{'id': '292', 'type': 'call', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'f3'},{'id': '294', 'type': 'argument_list', 'children': ['295']},{'id': '295', 'type': 'binary_operator', 'children': ['296', '297'], 'value': '+'},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '298', 'type': 'function_definition', 'children': ['299', '300', '302']},{'id': '299', 'type': 'function_name', 'children': [], 'value': 'f3'},{'id': '300', 'type': 'parameters', 'children': ['301']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '302', 'type': 'block', 'children': ['303', '312']},{'id': '303', 'type': 'expression_statement', 'children': ['304']},{'id': '304', 'type': 'assignment', 'children': ['305', '306']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '306', 'type': 'binary_operator', 'children': ['307', '311'], 'value': '+'},{'id': '307', 'type': '()', 'children': ['308']},{'id': '308', 'type': 'binary_operator', 'children': ['309', '310'], 'value': '*'},{'id': '309', 'type': 'string', 'children': [], 'value': '"abc"'},{'id': '310', 'type': 'integer', 'children': [], 'value': '100'},{'id': '311', 'type': 'string', 'children': [], 'value': '"-interesting"'},{'id': '312', 'type': 'expression_statement', 'children': ['313']},{'id': '313', 'type': 'call', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '315', 'type': 'argument_list', 'children': ['316']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '317', 'type': 'try_statement', 'children': ['318', '324']},{'id': '318', 'type': 'block', 'children': ['319']},{'id': '319', 'type': 'expression_statement', 'children': ['320']},{'id': '320', 'type': 'call', 'children': ['321', '322']},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'f1'},{'id': '322', 'type': 'argument_list', 'children': ['323']},{'id': '323', 'type': 'integer', 'children': [], 'value': '13'},{'id': '324', 'type': 'except_clause', 'children': ['325', '326']},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '326', 'type': 'block', 'children': ['327']},{'id': '327', 'type': 'expression_statement', 'children': ['328']},{'id': '328', 'type': 'call', 'children': ['329', '330']},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'better_exchook'},{'id': '330', 'type': 'argument_list', 'children': ['331']},{'id': '331', 'type': 'list_splat', 'children': ['332']},{'id': '332', 'type': 'call', 'children': ['333', '336']},{'id': '333', 'type': 'attribute', 'children': ['334', '335']},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'exc_info'},{'id': '336', 'type': 'argument_list', 'children': []},{'id': '337', 'type': 'expression_statement', 'children': ['338']},{'id': '338', 'type': 'call', 'children': ['339', '340']},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'install'},{'id': '340', 'type': 'argument_list', 'children': []},{'id': '341', 'type': 'expression_statement', 'children': ['342']},{'id': '342', 'type': 'call', 'children': ['343', '344']},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'finalfail'},{'id': '344', 'type': 'argument_list', 'children': ['345']},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'sys'}
def _main(): 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) try: x = {1: 2, "a": "b"} def f(): y = "foo" x, 42, sys.stdin.__class__, sys.exc_info, y, z f() except Exception: better_exchook(*sys.exc_info()) try: (lambda _x: None)(__name__, 42) 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()) def f1(a): f2(a + 1, 2) def f2(a, b): f3(a + b) def f3(a): b = ("abc" * 100) + "-interesting" a(b) try: f1(13) except Exception: better_exchook(*sys.exc_info()) install() finalfail(sys)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'mol_supplier'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'no_halt'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'assign_descriptors'},{'id': '7', 'type': 'block', 'children': ['8', '111']},{'id': '8', 'type': 'function_definition', 'children': ['9', '10', '12']},{'id': '9', 'type': 'function_name', 'children': [], 'value': 'sdf_block'},{'id': '10', 'type': 'parameters', 'children': ['11']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'lns'},{'id': '12', 'type': 'block', 'children': ['13', '17', '21', '25', '103']},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '16', 'type': 'list', 'children': [], 'value': '[]'},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'opt'},{'id': '20', 'type': 'list', 'children': [], 'value': '[]'},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'is_mol'},{'id': '24', 'type': 'True', 'children': []},{'id': '25', 'type': 'for_statement', 'children': ['26', '27', '28']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'lns'},{'id': '28', 'type': 'block', 'children': ['29']},{'id': '29', 'type': 'if_statement', 'children': ['30', '36', '64', '76', '90']},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'string', 'children': [], 'value': '"$$$$"'},{'id': '36', 'type': 'block', 'children': ['37', '48', '52', '58']},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'yield', 'children': ['39']},{'id': '39', 'type': 'expression_list', 'children': ['40', '44']},{'id': '40', 'type': 'subscript', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '42', 'type': 'slice', 'children': ['43']},{'id': '43', 'type': 'colon', 'children': []},{'id': '44', 'type': 'subscript', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'opt'},{'id': '46', 'type': 'slice', 'children': ['47']},{'id': '47', 'type': 'colon', 'children': []},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'is_mol'},{'id': '51', 'type': 'True', 'children': []},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'call', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'clear'},{'id': '57', 'type': 'argument_list', 'children': []},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'opt'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'clear'},{'id': '63', 'type': 'argument_list', 'children': []},{'id': '64', 'type': 'elif_clause', 'children': ['65', '71']},{'id': '65', 'type': 'call', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'string', 'children': [], 'value': '"M END"'},{'id': '71', 'type': 'block', 'children': ['72']},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'is_mol'},{'id': '75', 'type': 'False', 'children': []},{'id': '76', 'type': 'elif_clause', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'is_mol'},{'id': '78', 'type': 'block', 'children': ['79']},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'call', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'call', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'rstrip'},{'id': '89', 'type': 'argument_list', 'children': []},{'id': '90', 'type': 'else_clause', 'children': ['91']},{'id': '91', 'type': 'block', 'children': ['92']},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'call', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'opt'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'call', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'rstrip'},{'id': '102', 'type': 'argument_list', 'children': []},{'id': '103', 'type': 'if_statement', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '105', 'type': 'block', 'children': ['106']},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'yield', 'children': ['108']},{'id': '108', 'type': 'expression_list', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'opt'},{'id': '111', 'type': 'for_statement', 'children': ['112', '117', '124']},{'id': '112', 'type': 'pattern_list', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '114', 'type': 'tuple_pattern', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'opt'},{'id': '117', 'type': 'call', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '119', 'type': 'argument_list', 'children': ['120']},{'id': '120', 'type': 'call', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'sdf_block'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '124', 'type': 'block', 'children': ['125']},{'id': '125', 'type': 'try_statement', 'children': ['126', '144', '186', '221']},{'id': '126', 'type': 'block', 'children': ['127', '134']},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'assignment', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '130', 'type': 'call', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'molecule'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '134', 'type': 'if_statement', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'assign_descriptors'},{'id': '136', 'type': 'block', 'children': ['137']},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'call', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'molutil'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'assign_descriptors'},{'id': '142', 'type': 'argument_list', 'children': ['143']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '144', 'type': 'except_clause', 'children': ['145', '149']},{'id': '145', 'type': 'as_pattern', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '147', 'type': 'as_pattern_target', 'children': ['148']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '149', 'type': 'block', 'children': ['150']},{'id': '150', 'type': 'if_statement', 'children': ['151', '152', '174']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'no_halt'},{'id': '152', 'type': 'block', 'children': ['153', '165']},{'id': '153', 'type': 'print_statement', 'children': ['154']},{'id': '154', 'type': '()', 'children': ['155', '158']},{'id': '155', 'type': 'ERROR', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'Unsupported'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'symbol'},{'id': '158', 'type': 'call', 'children': ['159', '160']},{'id': '159', 'type': 'dictionary', 'children': []},{'id': '160', 'type': 'argument_list', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '162', 'type': 'binary_operator', 'children': ['163', '164'], 'value': '+'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '164', 'type': 'integer', 'children': [], 'value': '1'},{'id': '165', 'type': 'expression_statement', 'children': ['166']},{'id': '166', 'type': 'assignment', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '168', 'type': 'call', 'children': ['169', '172']},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'molutil'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'null_molecule'},{'id': '172', 'type': 'argument_list', 'children': ['173']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'assign_descriptors'},{'id': '174', 'type': 'else_clause', 'children': ['175']},{'id': '175', 'type': 'block', 'children': ['176']},{'id': '176', 'type': 'raise_statement', 'children': ['177']},{'id': '177', 'type': 'call', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '179', 'type': 'argument_list', 'children': ['180']},{'id': '180', 'type': 'call', 'children': ['181', '184']},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'string', 'children': [], 'value': '"Unsupported symbol: {}"'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '186', 'type': 'except_clause', 'children': ['187', '191']},{'id': '187', 'type': 'as_pattern', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'},{'id': '189', 'type': 'as_pattern_target', 'children': ['190']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '191', 'type': 'block', 'children': ['192']},{'id': '192', 'type': 'if_statement', 'children': ['193', '194', '209']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'no_halt'},{'id': '194', 'type': 'block', 'children': ['195']},{'id': '195', 'type': 'print_statement', 'children': ['196']},{'id': '196', 'type': '()', 'children': ['197', '202']},{'id': '197', 'type': 'ERROR', 'children': ['198', '199', '200', '201']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'Failed'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'to'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'minimize'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'ring'},{'id': '202', 'type': 'call', 'children': ['203', '204']},{'id': '203', 'type': 'dictionary', 'children': []},{'id': '204', 'type': 'argument_list', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '206', 'type': 'binary_operator', 'children': ['207', '208'], 'value': '+'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '208', 'type': 'integer', 'children': [], 'value': '1'},{'id': '209', 'type': 'else_clause', 'children': ['210']},{'id': '210', 'type': 'block', 'children': ['211']},{'id': '211', 'type': 'raise_statement', 'children': ['212']},{'id': '212', 'type': 'call', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'},{'id': '214', 'type': 'argument_list', 'children': ['215']},{'id': '215', 'type': 'call', 'children': ['216', '219']},{'id': '216', 'type': 'attribute', 'children': ['217', '218']},{'id': '217', 'type': 'string', 'children': [], 'value': '"Failed to minimize ring: {}"'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '219', 'type': 'argument_list', 'children': ['220']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '221', 'type': 'except_clause', 'children': ['222']},{'id': '222', 'type': 'block', 'children': ['223']},{'id': '223', 'type': 'if_statement', 'children': ['224', '225', '272']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'no_halt'},{'id': '225', 'type': 'ERROR', 'children': ['226', '228', '229', '230', '271']},{'id': '226', 'type': 'ERROR', 'children': ['227']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'Unexpected'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '230', 'type': 'ERROR', 'children': ['231', '241', '245', '246', '247', '248', '249', '257', '258', '266', '270']},{'id': '231', 'type': 'attribute', 'children': ['232', '238', '240']},{'id': '232', 'type': 'call', 'children': ['233', '236']},{'id': '233', 'type': 'attribute', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'molutil'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'null_molecule'},{'id': '236', 'type': 'argument_list', 'children': ['237']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'assign_descriptors'},{'id': '238', 'type': 'ERROR', 'children': ['239']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '241', 'type': 'call', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'optional_data'},{'id': '243', 'type': 'argument_list', 'children': ['244']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'opt'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'yield'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'continue'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'else'},{'id': '249', 'type': 'call', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '251', 'type': 'argument_list', 'children': ['252']},{'id': '252', 'type': 'call', 'children': ['253', '256']},{'id': '253', 'type': 'attribute', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'traceback'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'format_exc'},{'id': '256', 'type': 'argument_list', 'children': []},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'raise'},{'id': '258', 'type': 'attribute', 'children': ['259', '263', '265']},{'id': '259', 'type': 'call', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '261', 'type': 'argument_list', 'children': ['262']},{'id': '262', 'type': 'string', 'children': [], 'value': '"Unsupported Error"'},{'id': '263', 'type': 'ERROR', 'children': ['264']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '266', 'type': 'call', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'optional_data'},{'id': '268', 'type': 'argument_list', 'children': ['269']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'opt'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'yield'},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '272', 'type': 'block', 'children': [], 'value': ''}
def mol_supplier(lines, no_halt, assign_descriptors): 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: {} ( 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: {} ( err, i + 1) ) else: raise RuntimeError("Failed to minimize ring: {}".format(err)) except: if no_halt: print("Unexpected error ( 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
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'render_diagram'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'root_task'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'out_base'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'max_param_len'},{'id': '8', 'type': 'integer', 'children': [], 'value': '20'},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'horizontal'},{'id': '11', 'type': 'False', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'colored'},{'id': '14', 'type': 'False', 'children': []},{'id': '15', 'type': 'block', 'children': ['16', '19', '22', '25', '30', '39', '44', '54', '89', '95', '101', '312', '317', '324', '355', '368', '393']},{'id': '16', 'type': 'import_statement', 'children': ['17']},{'id': '17', 'type': 'dotted_name', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '19', 'type': 'import_statement', 'children': ['20']},{'id': '20', 'type': 'dotted_name', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'codecs'},{'id': '22', 'type': 'import_statement', 'children': ['23']},{'id': '23', 'type': 'dotted_name', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'subprocess'},{'id': '25', 'type': 'import_from_statement', 'children': ['26', '28']},{'id': '26', 'type': 'dotted_name', 'children': ['27']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'ozelot'},{'id': '28', 'type': 'dotted_name', 'children': ['29']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '30', 'type': 'import_from_statement', 'children': ['31', '35', '37']},{'id': '31', 'type': 'dotted_name', 'children': ['32', '33', '34']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'ozelot'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'etl'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'tasks'},{'id': '35', 'type': 'dotted_name', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'get_task_name'},{'id': '37', 'type': 'dotted_name', 'children': ['38']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'get_task_param_string'},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '42', 'type': 'list', 'children': ['43'], 'value': '[u"digraph G {"]'},{'id': '43', 'type': 'string', 'children': [], 'value': 'u"digraph G {"'},{'id': '44', 'type': 'if_statement', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'horizontal'},{'id': '46', 'type': 'block', 'children': ['47']},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'call', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'string', 'children': [], 'value': 'u"rankdir=LR;"'},{'id': '54', 'type': 'function_definition', 'children': ['55', '56', '58']},{'id': '55', 'type': 'function_name', 'children': [], 'value': 'get_id'},{'id': '56', 'type': 'parameters', 'children': ['57']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '58', 'type': 'block', 'children': ['59', '73']},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'assignment', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '62', 'type': 'binary_operator', 'children': ['63', '69'], 'value': '+'},{'id': '63', 'type': 'binary_operator', 'children': ['64', '68'], 'value': '+'},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'get_task_name'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '68', 'type': 'string', 'children': [], 'value': '"_"'},{'id': '69', 'type': 'call', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'get_task_param_string'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '73', 'type': 'return_statement', 'children': ['74']},{'id': '74', 'type': 'call', 'children': ['75', '78']},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'sub'},{'id': '78', 'type': 'argument_list', 'children': ['79', '80', '81']},{'id': '79', 'type': 'string', 'children': [], 'value': "r'\\W+'"},{'id': '80', 'type': 'string', 'children': [], 'value': "''"},{'id': '81', 'type': 'call', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'sub'},{'id': '85', 'type': 'argument_list', 'children': ['86', '87', '88']},{'id': '86', 'type': 'string', 'children': [], 'value': "' '"},{'id': '87', 'type': 'string', 'children': [], 'value': "'_'"},{'id': '88', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '89', 'type': 'expression_statement', 'children': ['90']},{'id': '90', 'type': 'assignment', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'existing_nodes'},{'id': '92', 'type': 'call', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '94', 'type': 'argument_list', 'children': []},{'id': '95', 'type': 'expression_statement', 'children': ['96']},{'id': '96', 'type': 'assignment', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'existing_edges'},{'id': '98', 'type': 'call', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '100', 'type': 'argument_list', 'children': []},{'id': '101', 'type': 'function_definition', 'children': ['102', '103', '108']},{'id': '102', 'type': 'function_name', 'children': [], 'value': '_build'},{'id': '103', 'type': 'parameters', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '105', 'type': 'default_parameter', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'parent_id'},{'id': '107', 'type': 'None', 'children': []},{'id': '108', 'type': 'block', 'children': ['109', '116', '284']},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'tid'},{'id': '112', 'type': 'call', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'get_id'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '116', 'type': 'if_statement', 'children': ['117', '120']},{'id': '117', 'type': 'comparison_operator', 'children': ['118', '119'], 'value': 'not'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'tid'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'existing_nodes'},{'id': '120', 'type': 'block', 'children': ['121', '129', '133', '176', '197', '206', '231', '261', '268']},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'assignment', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '124', 'type': 'call', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'to_str_params'},{'id': '128', 'type': 'argument_list', 'children': []},{'id': '129', 'type': 'expression_statement', 'children': ['130']},{'id': '130', 'type': 'assignment', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'param_list'},{'id': '132', 'type': 'string', 'children': [], 'value': '""'},{'id': '133', 'type': 'for_statement', 'children': ['134', '137', '142']},{'id': '134', 'type': 'pattern_list', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '137', 'type': 'call', 'children': ['138', '141']},{'id': '138', 'type': 'attribute', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '141', 'type': 'argument_list', 'children': []},{'id': '142', 'type': 'block', 'children': ['143', '161']},{'id': '143', 'type': 'if_statement', 'children': ['144', '150']},{'id': '144', 'type': 'comparison_operator', 'children': ['145', '149'], 'value': '>'},{'id': '145', 'type': 'call', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '147', 'type': 'argument_list', 'children': ['148']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'max_param_len'},{'id': '150', 'type': 'block', 'children': ['151']},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'assignment', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '154', 'type': 'binary_operator', 'children': ['155', '160'], 'value': '+'},{'id': '155', 'type': 'subscript', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '157', 'type': 'slice', 'children': ['158', '159']},{'id': '158', 'type': 'colon', 'children': []},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'max_param_len'},{'id': '160', 'type': 'string', 'children': [], 'value': '"..."'},{'id': '161', 'type': 'expression_statement', 'children': ['162']},{'id': '162', 'type': 'augmented_assignment', 'children': ['163', '164'], 'value': '+='},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'param_list'},{'id': '164', 'type': 'call', 'children': ['165', '173']},{'id': '165', 'type': 'attribute', 'children': ['166', '172']},{'id': '166', 'type': 'concatenated_string', 'children': ['167', '168', '169', '170', '171']},{'id': '167', 'type': 'string', 'children': [], 'value': '"<TR><TD ALIGN=\\"LEFT\\">"'},{'id': '168', 'type': 'string', 'children': [], 'value': '"<FONT POINT-SIZE=\\"10\\">{:s}</FONT>"'},{'id': '169', 'type': 'string', 'children': [], 'value': '"</TD><TD ALIGN=\\"LEFT\\">"'},{'id': '170', 'type': 'string', 'children': [], 'value': '"<FONT POINT-SIZE=\\"10\\">{:s}</FONT>"'},{'id': '171', 'type': 'string', 'children': [], 'value': '"</TD></TR>"'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '173', 'type': 'argument_list', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '176', 'type': 'expression_statement', 'children': ['177']},{'id': '177', 'type': 'assignment', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '179', 'type': 'binary_operator', 'children': ['180', '196'], 'value': '+'},{'id': '180', 'type': 'binary_operator', 'children': ['181', '195'], 'value': '+'},{'id': '181', 'type': 'call', 'children': ['182', '190']},{'id': '182', 'type': 'attribute', 'children': ['183', '189']},{'id': '183', 'type': 'concatenated_string', 'children': ['184', '185', '186', '187', '188']},{'id': '184', 'type': 'string', 'children': [], 'value': '"<TABLE BORDER=\\"0\\" CELLSPACING=\\"1\\" CELLPADDING=\\"1\\">"'},{'id': '185', 'type': 'string', 'children': [], 'value': '"<TR><TD COLSPAN=\\"2\\" ALIGN=\\"CENTER\\">"'},{'id': '186', 'type': 'string', 'children': [], 'value': '"<FONT POINT-SIZE=\\"12\\">{:s}</FONT>"'},{'id': '187', 'type': 'string', 'children': [], 'value': '"</TD></TR>"'},{'id': '188', 'type': 'string', 'children': [], 'value': '""'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '190', 'type': 'argument_list', 'children': ['191']},{'id': '191', 'type': 'call', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'get_task_name'},{'id': '193', 'type': 'argument_list', 'children': ['194']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'param_list'},{'id': '196', 'type': 'string', 'children': [], 'value': '"</TABLE>"'},{'id': '197', 'type': 'expression_statement', 'children': ['198']},{'id': '198', 'type': 'assignment', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'style'},{'id': '200', 'type': 'call', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '202', 'type': 'argument_list', 'children': ['203', '204', '205']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '204', 'type': 'string', 'children': [], 'value': "'diagram_style'"},{'id': '205', 'type': 'list', 'children': [], 'value': '[]'},{'id': '206', 'type': 'if_statement', 'children': ['207', '208', '225']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'colored'},{'id': '208', 'type': 'block', 'children': ['209']},{'id': '209', 'type': 'expression_statement', 'children': ['210']},{'id': '210', 'type': 'assignment', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'color'},{'id': '212', 'type': 'call', 'children': ['213', '216']},{'id': '213', 'type': 'attribute', 'children': ['214', '215']},{'id': '214', 'type': 'string', 'children': [], 'value': '\', color="{:s}"\''},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '216', 'type': 'argument_list', 'children': ['217']},{'id': '217', 'type': 'conditional_expression', 'children': ['218', '219', '224'], 'value': 'if'},{'id': '218', 'type': 'string', 'children': [], 'value': '"green"'},{'id': '219', 'type': 'call', 'children': ['220', '223']},{'id': '220', 'type': 'attribute', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'complete'},{'id': '223', 'type': 'argument_list', 'children': []},{'id': '224', 'type': 'string', 'children': [], 'value': '"red"'},{'id': '225', 'type': 'else_clause', 'children': ['226']},{'id': '226', 'type': 'block', 'children': ['227']},{'id': '227', 'type': 'expression_statement', 'children': ['228']},{'id': '228', 'type': 'assignment', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'color'},{'id': '230', 'type': 'string', 'children': [], 'value': "''"},{'id': '231', 'type': 'expression_statement', 'children': ['232']},{'id': '232', 'type': 'call', 'children': ['233', '236']},{'id': '233', 'type': 'attribute', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '236', 'type': 'argument_list', 'children': ['237']},{'id': '237', 'type': 'call', 'children': ['238', '243']},{'id': '238', 'type': 'attribute', 'children': ['239', '242']},{'id': '239', 'type': 'concatenated_string', 'children': ['240', '241']},{'id': '240', 'type': 'string', 'children': [], 'value': 'u"{name:s} [label=< {label:s} >, shape=\\"rect\\" {color:s}, style=\\"{style:s}\\"];\\n"'},{'id': '241', 'type': 'string', 'children': [], 'value': 'u""'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '243', 'type': 'argument_list', 'children': ['244', '247', '250', '253']},{'id': '244', 'type': 'keyword_argument', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'tid'},{'id': '247', 'type': 'keyword_argument', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '250', 'type': 'keyword_argument', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'color'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'color'},{'id': '253', 'type': 'keyword_argument', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'style'},{'id': '255', 'type': 'call', 'children': ['256', '259']},{'id': '256', 'type': 'attribute', 'children': ['257', '258']},{'id': '257', 'type': 'string', 'children': [], 'value': "','"},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '259', 'type': 'argument_list', 'children': ['260']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'style'},{'id': '261', 'type': 'expression_statement', 'children': ['262']},{'id': '262', 'type': 'call', 'children': ['263', '266']},{'id': '263', 'type': 'attribute', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'existing_nodes'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '266', 'type': 'argument_list', 'children': ['267']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'tid'},{'id': '268', 'type': 'for_statement', 'children': ['269', '270', '275']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'req'},{'id': '270', 'type': 'call', 'children': ['271', '274']},{'id': '271', 'type': 'attribute', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'requires'},{'id': '274', 'type': 'argument_list', 'children': []},{'id': '275', 'type': 'block', 'children': ['276']},{'id': '276', 'type': 'expression_statement', 'children': ['277']},{'id': '277', 'type': 'call', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': '_build'},{'id': '279', 'type': 'argument_list', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'req'},{'id': '281', 'type': 'keyword_argument', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'parent_id'},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'tid'},{'id': '284', 'type': 'if_statement', 'children': ['285', '294']},{'id': '285', 'type': 'boolean_operator', 'children': ['286', '289'], 'value': 'and'},{'id': '286', 'type': 'comparison_operator', 'children': ['287', '288'], 'value': 'is'},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'parent_id'},{'id': '288', 'type': 'None', 'children': []},{'id': '289', 'type': 'comparison_operator', 'children': ['290', '293'], 'value': 'not'},{'id': '290', 'type': 'tuple', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'tid'},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'parent_id'},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'existing_edges'},{'id': '294', 'type': 'block', 'children': ['295']},{'id': '295', 'type': 'expression_statement', 'children': ['296']},{'id': '296', 'type': 'call', 'children': ['297', '300']},{'id': '297', 'type': 'attribute', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '300', 'type': 'argument_list', 'children': ['301']},{'id': '301', 'type': 'call', 'children': ['302', '305']},{'id': '302', 'type': 'attribute', 'children': ['303', '304']},{'id': '303', 'type': 'string', 'children': [], 'value': 'u"{source:s} -> {target:s};\\n"'},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '305', 'type': 'argument_list', 'children': ['306', '309']},{'id': '306', 'type': 'keyword_argument', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'tid'},{'id': '309', 'type': 'keyword_argument', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'parent_id'},{'id': '312', 'type': 'expression_statement', 'children': ['313']},{'id': '313', 'type': 'call', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': '_build'},{'id': '315', 'type': 'argument_list', 'children': ['316']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'root_task'},{'id': '317', 'type': 'expression_statement', 'children': ['318']},{'id': '318', 'type': 'call', 'children': ['319', '322']},{'id': '319', 'type': 'attribute', 'children': ['320', '321']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '322', 'type': 'argument_list', 'children': ['323']},{'id': '323', 'type': 'string', 'children': [], 'value': 'u"}"'},{'id': '324', 'type': 'with_statement', 'children': ['325', '342']},{'id': '325', 'type': 'with_clause', 'children': ['326']},{'id': '326', 'type': 'with_item', 'children': ['327']},{'id': '327', 'type': 'as_pattern', 'children': ['328', '340']},{'id': '328', 'type': 'call', 'children': ['329', '332']},{'id': '329', 'type': 'attribute', 'children': ['330', '331']},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'codecs'},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '332', 'type': 'argument_list', 'children': ['333', '336', '337']},{'id': '333', 'type': 'binary_operator', 'children': ['334', '335'], 'value': '+'},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'out_base'},{'id': '335', 'type': 'string', 'children': [], 'value': "'.dot'"},{'id': '336', 'type': 'string', 'children': [], 'value': "'w'"},{'id': '337', 'type': 'keyword_argument', 'children': ['338', '339']},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '339', 'type': 'string', 'children': [], 'value': "'utf-8'"},{'id': '340', 'type': 'as_pattern_target', 'children': ['341']},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '342', 'type': 'block', 'children': ['343']},{'id': '343', 'type': 'expression_statement', 'children': ['344']},{'id': '344', 'type': 'call', 'children': ['345', '348']},{'id': '345', 'type': 'attribute', 'children': ['346', '347']},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '348', 'type': 'argument_list', 'children': ['349']},{'id': '349', 'type': 'call', 'children': ['350', '353']},{'id': '350', 'type': 'attribute', 'children': ['351', '352']},{'id': '351', 'type': 'string', 'children': [], 'value': 'u"\\n"'},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '353', 'type': 'argument_list', 'children': ['354']},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '355', 'type': 'if_statement', 'children': ['356', '362']},{'id': '356', 'type': 'not_operator', 'children': ['357']},{'id': '357', 'type': 'call', 'children': ['358', '359']},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '359', 'type': 'argument_list', 'children': ['360', '361']},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '361', 'type': 'string', 'children': [], 'value': "'DOT_EXECUTABLE'"},{'id': '362', 'type': 'block', 'children': ['363']},{'id': '363', 'type': 'raise_statement', 'children': ['364']},{'id': '364', 'type': 'call', 'children': ['365', '366']},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'},{'id': '366', 'type': 'argument_list', 'children': ['367']},{'id': '367', 'type': 'string', 'children': [], 'value': '"Please configure the \'DOT_EXECUTABLE\' variable in your \'project_config.py\'"'},{'id': '368', 'type': 'if_statement', 'children': ['369', '380']},{'id': '369', 'type': 'not_operator', 'children': ['370']},{'id': '370', 'type': 'call', 'children': ['371', '376']},{'id': '371', 'type': 'attribute', 'children': ['372', '375']},{'id': '372', 'type': 'attribute', 'children': ['373', '374']},{'id': '373', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '375', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '376', 'type': 'argument_list', 'children': ['377']},{'id': '377', 'type': 'attribute', 'children': ['378', '379']},{'id': '378', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '379', 'type': 'identifier', 'children': [], 'value': 'DOT_EXECUTABLE'},{'id': '380', 'type': 'block', 'children': ['381']},{'id': '381', 'type': 'raise_statement', 'children': ['382']},{'id': '382', 'type': 'call', 'children': ['383', '384']},{'id': '383', 'type': 'identifier', 'children': [], 'value': 'IOError'},{'id': '384', 'type': 'argument_list', 'children': ['385']},{'id': '385', 'type': 'binary_operator', 'children': ['386', '387'], 'value': '+'},{'id': '386', 'type': 'string', 'children': [], 'value': '"Could not find file pointed to by \'DOT_EXECUTABLE\': "'},{'id': '387', 'type': 'call', 'children': ['388', '389']},{'id': '388', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '389', 'type': 'argument_list', 'children': ['390']},{'id': '390', 'type': 'attribute', 'children': ['391', '392']},{'id': '391', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'DOT_EXECUTABLE'},{'id': '393', 'type': 'expression_statement', 'children': ['394']},{'id': '394', 'type': 'call', 'children': ['395', '398']},{'id': '395', 'type': 'attribute', 'children': ['396', '397']},{'id': '396', 'type': 'identifier', 'children': [], 'value': 'subprocess'},{'id': '397', 'type': 'identifier', 'children': [], 'value': 'check_call'},{'id': '398', 'type': 'argument_list', 'children': ['399']},{'id': '399', 'type': 'list', 'children': ['400', '403', '404', '405', '406', '409'], 'value': "[\n config.DOT_EXECUTABLE,\n '-T', 'png',\n '-o', out_base + '.png',\n out_base + '.dot'\n ]"},{'id': '400', 'type': 'attribute', 'children': ['401', '402']},{'id': '401', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '402', 'type': 'identifier', 'children': [], 'value': 'DOT_EXECUTABLE'},{'id': '403', 'type': 'string', 'children': [], 'value': "'-T'"},{'id': '404', 'type': 'string', 'children': [], 'value': "'png'"},{'id': '405', 'type': 'string', 'children': [], 'value': "'-o'"},{'id': '406', 'type': 'binary_operator', 'children': ['407', '408'], 'value': '+'},{'id': '407', 'type': 'identifier', 'children': [], 'value': 'out_base'},{'id': '408', 'type': 'string', 'children': [], 'value': "'.png'"},{'id': '409', 'type': 'binary_operator', 'children': ['410', '411'], 'value': '+'},{'id': '410', 'type': 'identifier', 'children': [], 'value': 'out_base'},{'id': '411', 'type': 'string', 'children': [], 'value': "'.dot'"}
def render_diagram(root_task, out_base, max_param_len=20, horizontal=False, colored=False): import re import codecs import subprocess from ozelot import config from ozelot.etl.tasks import get_task_name, get_task_param_string lines = [u"digraph G {"] if horizontal: lines.append(u"rankdir=LR;") def get_id(task): s = get_task_name(task) + "_" + get_task_param_string(task) return re.sub(r'\W+', '', re.sub(' ', '_', s)) existing_nodes = set() existing_edges = set() def _build(task, parent_id=None): tid = get_id(task) if tid not in existing_nodes: params = task.to_str_params() param_list = "" for k, v in params.items(): 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 = '' 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) for req in task.requires(): _build(req, parent_id=tid) 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)) _build(root_task) lines.append(u"}") with codecs.open(out_base + '.dot', 'w', encoding='utf-8') as f: f.write(u"\n".join(lines)) 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)) subprocess.check_call([ config.DOT_EXECUTABLE, '-T', 'png', '-o', out_base + '.png', out_base + '.dot' ])
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '21']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'binarize'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'category_classes'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'all_classes'},{'id': '8', 'type': 'True', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'drop'},{'id': '11', 'type': 'True', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'astype'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'inplace'},{'id': '17', 'type': 'True', 'children': []},{'id': '18', 'type': 'default_parameter', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'min_freq'},{'id': '20', 'type': 'None', 'children': []},{'id': '21', 'type': 'block', 'children': ['22', '63', '78', '164', '182']},{'id': '22', 'type': 'if_statement', 'children': ['23', '29', '53']},{'id': '23', 'type': 'comparison_operator', 'children': ['24', '28'], 'value': 'is'},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'category_classes'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '29', 'type': 'block', 'children': ['30', '37']},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'category_classes'},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'category_classes'},{'id': '40', 'type': 'dictionary_comprehension', 'children': ['41', '50']},{'id': '41', 'type': 'pair', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '43', 'type': 'call', 'children': ['44', '49']},{'id': '44', 'type': 'attribute', 'children': ['45', '48']},{'id': '45', 'type': 'subscript', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'unique'},{'id': '49', 'type': 'argument_list', 'children': []},{'id': '50', 'type': 'for_in_clause', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '53', 'type': 'else_clause', 'children': ['54']},{'id': '54', 'type': 'block', 'children': ['55']},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '58', 'type': 'call', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'category_classes'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '62', 'type': 'argument_list', 'children': []},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'df_new'},{'id': '66', 'type': 'conditional_expression', 'children': ['67', '68', '69'], 'value': 'if'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'inplace'},{'id': '69', 'type': 'call', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'drop'},{'id': '73', 'type': 'argument_list', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '75', 'type': 'keyword_argument', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '77', 'type': 'integer', 'children': [], 'value': '1'},{'id': '78', 'type': 'for_statement', 'children': ['79', '80', '81']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '81', 'type': 'block', 'children': ['82', '88']},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'assignment', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'classes'},{'id': '85', 'type': 'subscript', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'category_classes'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '88', 'type': 'for_statement', 'children': ['89', '90', '106']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '90', 'type': 'call', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'conditional_expression', 'children': ['94', '100', '102'], 'value': 'if'},{'id': '94', 'type': 'binary_operator', 'children': ['95', '99'], 'value': '-'},{'id': '95', 'type': 'call', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'classes'},{'id': '99', 'type': 'integer', 'children': [], 'value': '1'},{'id': '100', 'type': 'not_operator', 'children': ['101']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'all_classes'},{'id': '102', 'type': 'call', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '104', 'type': 'argument_list', 'children': ['105']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'classes'},{'id': '106', 'type': 'block', 'children': ['107', '117']},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '110', 'type': 'comparison_operator', 'children': ['111', '114'], 'value': '=='},{'id': '111', 'type': 'subscript', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '114', 'type': 'subscript', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'classes'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '117', 'type': 'if_statement', 'children': ['118', '128']},{'id': '118', 'type': 'boolean_operator', 'children': ['119', '121'], 'value': 'or'},{'id': '119', 'type': 'not_operator', 'children': ['120']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'min_freq'},{'id': '121', 'type': 'comparison_operator', 'children': ['122', '127'], 'value': '>='},{'id': '122', 'type': 'call', 'children': ['123', '126']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '126', 'type': 'argument_list', 'children': []},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'min_freq'},{'id': '128', 'type': 'block', 'children': ['129', '143']},{'id': '129', 'type': 'if_statement', 'children': ['130', '133']},{'id': '130', 'type': 'comparison_operator', 'children': ['131', '132'], 'value': 'is'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'astype'},{'id': '132', 'type': 'None', 'children': []},{'id': '133', 'type': 'block', 'children': ['134']},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'assignment', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '137', 'type': 'call', 'children': ['138', '141']},{'id': '138', 'type': 'attribute', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'astype'},{'id': '141', 'type': 'argument_list', 'children': ['142']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'astype'},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'assignment', 'children': ['145', '163']},{'id': '145', 'type': 'subscript', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'df_new'},{'id': '147', 'type': 'binary_operator', 'children': ['148', '149'], 'value': '%'},{'id': '148', 'type': 'string', 'children': [], 'value': "'%s_%s'"},{'id': '149', 'type': 'tuple', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '151', 'type': 'call', 'children': ['152', '160']},{'id': '152', 'type': 'attribute', 'children': ['153', '159']},{'id': '153', 'type': 'call', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '155', 'type': 'argument_list', 'children': ['156']},{'id': '156', 'type': 'subscript', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'classes'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '160', 'type': 'argument_list', 'children': ['161', '162']},{'id': '161', 'type': 'string', 'children': [], 'value': "' '"},{'id': '162', 'type': 'string', 'children': [], 'value': "'_'"},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '164', 'type': 'if_statement', 'children': ['165', '168']},{'id': '165', 'type': 'boolean_operator', 'children': ['166', '167'], 'value': 'and'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'drop'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'inplace'},{'id': '168', 'type': 'block', 'children': ['169']},{'id': '169', 'type': 'expression_statement', 'children': ['170']},{'id': '170', 'type': 'call', 'children': ['171', '174']},{'id': '171', 'type': 'attribute', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'df_new'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'drop'},{'id': '174', 'type': 'argument_list', 'children': ['175', '176', '179']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '176', 'type': 'keyword_argument', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '178', 'type': 'integer', 'children': [], 'value': '1'},{'id': '179', 'type': 'keyword_argument', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'inplace'},{'id': '181', 'type': 'True', 'children': []},{'id': '182', 'type': 'return_statement', 'children': ['183']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'df_new'}
def binarize(df, category_classes, all_classes=True, drop=True, astype=None, inplace=True, min_freq=None): 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
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'find_package_docs'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'package_dir'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'skippedNames'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '18', '27', '39', '51', '72', '92', '96', '100', '104', '191', '261', '350', '361']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'getLogger'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '18', 'type': 'if_statement', 'children': ['19', '22']},{'id': '19', 'type': 'comparison_operator', 'children': ['20', '21'], 'value': 'is'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'skippedNames'},{'id': '21', 'type': 'None', 'children': []},{'id': '22', 'type': 'block', 'children': ['23']},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'skippedNames'},{'id': '26', 'type': 'list', 'children': [], 'value': '[]'},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'doc_dir'},{'id': '30', 'type': 'call', 'children': ['31', '36']},{'id': '31', 'type': 'attribute', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '36', 'type': 'argument_list', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'package_dir'},{'id': '38', 'type': 'string', 'children': [], 'value': "'doc'"},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'modules_yaml_path'},{'id': '42', 'type': 'call', 'children': ['43', '48']},{'id': '43', 'type': 'attribute', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '48', 'type': 'argument_list', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'doc_dir'},{'id': '50', 'type': 'string', 'children': [], 'value': "'manifest.yaml'"},{'id': '51', 'type': 'if_statement', 'children': ['52', '61']},{'id': '52', 'type': 'not_operator', 'children': ['53']},{'id': '53', 'type': 'call', 'children': ['54', '59']},{'id': '54', 'type': 'attribute', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'modules_yaml_path'},{'id': '61', 'type': 'block', 'children': ['62']},{'id': '62', 'type': 'raise_statement', 'children': ['63']},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'NoPackageDocs'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'call', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'string', 'children': [], 'value': "'Manifest YAML not found: {0}'"},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'modules_yaml_path'},{'id': '72', 'type': 'with_statement', 'children': ['73', '82']},{'id': '73', 'type': 'with_clause', 'children': ['74']},{'id': '74', 'type': 'with_item', 'children': ['75']},{'id': '75', 'type': 'as_pattern', 'children': ['76', '80']},{'id': '76', 'type': 'call', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'modules_yaml_path'},{'id': '80', 'type': 'as_pattern_target', 'children': ['81']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '82', 'type': 'block', 'children': ['83']},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'manifest_data'},{'id': '86', 'type': 'call', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'yaml'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'safe_load'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'assignment', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'module_dirs'},{'id': '95', 'type': 'dictionary', 'children': []},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'assignment', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'package_dirs'},{'id': '99', 'type': 'dictionary', 'children': []},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'static_dirs'},{'id': '103', 'type': 'dictionary', 'children': []},{'id': '104', 'type': 'if_statement', 'children': ['105', '108']},{'id': '105', 'type': 'comparison_operator', 'children': ['106', '107'], 'value': 'in'},{'id': '106', 'type': 'string', 'children': [], 'value': "'modules'"},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'manifest_data'},{'id': '108', 'type': 'block', 'children': ['109']},{'id': '109', 'type': 'for_statement', 'children': ['110', '111', '114']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'module_name'},{'id': '111', 'type': 'subscript', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'manifest_data'},{'id': '113', 'type': 'string', 'children': [], 'value': "'modules'"},{'id': '114', 'type': 'block', 'children': ['115', '133', '145', '173', '179']},{'id': '115', 'type': 'if_statement', 'children': ['116', '119']},{'id': '116', 'type': 'comparison_operator', 'children': ['117', '118'], 'value': 'in'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'module_name'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'skippedNames'},{'id': '119', 'type': 'block', 'children': ['120', '132']},{'id': '120', 'type': 'expression_statement', 'children': ['121']},{'id': '121', 'type': 'call', 'children': ['122', '125']},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '125', 'type': 'argument_list', 'children': ['126']},{'id': '126', 'type': 'call', 'children': ['127', '130']},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'string', 'children': [], 'value': "'Skipping module {0}'"},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '130', 'type': 'argument_list', 'children': ['131']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'module_name'},{'id': '132', 'type': 'continue_statement', 'children': []},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'assignment', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'module_dir'},{'id': '136', 'type': 'call', 'children': ['137', '142']},{'id': '137', 'type': 'attribute', 'children': ['138', '141']},{'id': '138', 'type': 'attribute', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '142', 'type': 'argument_list', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'doc_dir'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'module_name'},{'id': '145', 'type': 'if_statement', 'children': ['146', '155']},{'id': '146', 'type': 'not_operator', 'children': ['147']},{'id': '147', 'type': 'call', 'children': ['148', '153']},{'id': '148', 'type': 'attribute', 'children': ['149', '152']},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'isdir'},{'id': '153', 'type': 'argument_list', 'children': ['154']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'module_dir'},{'id': '155', 'type': 'block', 'children': ['156', '165', '172']},{'id': '156', 'type': 'expression_statement', 'children': ['157']},{'id': '157', 'type': 'assignment', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '159', 'type': 'call', 'children': ['160', '163']},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'string', 'children': [], 'value': "'module doc dir not found: {0}'"},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '163', 'type': 'argument_list', 'children': ['164']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'module_dir'},{'id': '165', 'type': 'expression_statement', 'children': ['166']},{'id': '166', 'type': 'call', 'children': ['167', '170']},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '170', 'type': 'argument_list', 'children': ['171']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '172', 'type': 'continue_statement', 'children': []},{'id': '173', 'type': 'expression_statement', 'children': ['174']},{'id': '174', 'type': 'assignment', 'children': ['175', '178']},{'id': '175', 'type': 'subscript', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'module_dirs'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'module_name'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'module_dir'},{'id': '179', 'type': 'expression_statement', 'children': ['180']},{'id': '180', 'type': 'call', 'children': ['181', '184']},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'call', 'children': ['186', '189']},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'string', 'children': [], 'value': "'Found module doc dir {0}'"},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '189', 'type': 'argument_list', 'children': ['190']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'module_dir'},{'id': '191', 'type': 'if_statement', 'children': ['192', '195']},{'id': '192', 'type': 'comparison_operator', 'children': ['193', '194'], 'value': 'in'},{'id': '193', 'type': 'string', 'children': [], 'value': "'package'"},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'manifest_data'},{'id': '195', 'type': 'block', 'children': ['196', '202', '214']},{'id': '196', 'type': 'expression_statement', 'children': ['197']},{'id': '197', 'type': 'assignment', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'package_name'},{'id': '199', 'type': 'subscript', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'manifest_data'},{'id': '201', 'type': 'string', 'children': [], 'value': "'package'"},{'id': '202', 'type': 'expression_statement', 'children': ['203']},{'id': '203', 'type': 'assignment', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'full_package_dir'},{'id': '205', 'type': 'call', 'children': ['206', '211']},{'id': '206', 'type': 'attribute', 'children': ['207', '210']},{'id': '207', 'type': 'attribute', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '211', 'type': 'argument_list', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'doc_dir'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'package_name'},{'id': '214', 'type': 'if_statement', 'children': ['215', '228', '247']},{'id': '215', 'type': 'boolean_operator', 'children': ['216', '224', '225'], 'value': 'and'},{'id': '216', 'type': 'call', 'children': ['217', '222']},{'id': '217', 'type': 'attribute', 'children': ['218', '221']},{'id': '218', 'type': 'attribute', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'isdir'},{'id': '222', 'type': 'argument_list', 'children': ['223']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'full_package_dir'},{'id': '224', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '225', 'type': 'comparison_operator', 'children': ['226', '227'], 'value': 'not'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'package_name'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'skippedNames'},{'id': '228', 'type': 'block', 'children': ['229', '235']},{'id': '229', 'type': 'expression_statement', 'children': ['230']},{'id': '230', 'type': 'assignment', 'children': ['231', '234']},{'id': '231', 'type': 'subscript', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'package_dirs'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'package_name'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'full_package_dir'},{'id': '235', 'type': 'expression_statement', 'children': ['236']},{'id': '236', 'type': 'call', 'children': ['237', '240']},{'id': '237', 'type': 'attribute', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '240', 'type': 'argument_list', 'children': ['241']},{'id': '241', 'type': 'call', 'children': ['242', '245']},{'id': '242', 'type': 'attribute', 'children': ['243', '244']},{'id': '243', 'type': 'string', 'children': [], 'value': "'Found package doc dir {0}'"},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '245', 'type': 'argument_list', 'children': ['246']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'full_package_dir'},{'id': '247', 'type': 'else_clause', 'children': ['248']},{'id': '248', 'type': 'block', 'children': ['249']},{'id': '249', 'type': 'expression_statement', 'children': ['250']},{'id': '250', 'type': 'call', 'children': ['251', '254']},{'id': '251', 'type': 'attribute', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '254', 'type': 'argument_list', 'children': ['255']},{'id': '255', 'type': 'call', 'children': ['256', '259']},{'id': '256', 'type': 'attribute', 'children': ['257', '258']},{'id': '257', 'type': 'string', 'children': [], 'value': "'package doc dir excluded or not found: {0}'"},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '259', 'type': 'argument_list', 'children': ['260']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'full_package_dir'},{'id': '261', 'type': 'if_statement', 'children': ['262', '265']},{'id': '262', 'type': 'comparison_operator', 'children': ['263', '264'], 'value': 'in'},{'id': '263', 'type': 'string', 'children': [], 'value': "'statics'"},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'manifest_data'},{'id': '265', 'type': 'block', 'children': ['266']},{'id': '266', 'type': 'for_statement', 'children': ['267', '268', '271']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'static_dirname'},{'id': '268', 'type': 'subscript', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'manifest_data'},{'id': '270', 'type': 'string', 'children': [], 'value': "'statics'"},{'id': '271', 'type': 'block', 'children': ['272', '284', '312', '332', '338']},{'id': '272', 'type': 'expression_statement', 'children': ['273']},{'id': '273', 'type': 'assignment', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'full_static_dir'},{'id': '275', 'type': 'call', 'children': ['276', '281']},{'id': '276', 'type': 'attribute', 'children': ['277', '280']},{'id': '277', 'type': 'attribute', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '281', 'type': 'argument_list', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'doc_dir'},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'static_dirname'},{'id': '284', 'type': 'if_statement', 'children': ['285', '294']},{'id': '285', 'type': 'not_operator', 'children': ['286']},{'id': '286', 'type': 'call', 'children': ['287', '292']},{'id': '287', 'type': 'attribute', 'children': ['288', '291']},{'id': '288', 'type': 'attribute', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'isdir'},{'id': '292', 'type': 'argument_list', 'children': ['293']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'full_static_dir'},{'id': '294', 'type': 'block', 'children': ['295', '304', '311']},{'id': '295', 'type': 'expression_statement', 'children': ['296']},{'id': '296', 'type': 'assignment', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '298', 'type': 'call', 'children': ['299', '302']},{'id': '299', 'type': 'attribute', 'children': ['300', '301']},{'id': '300', 'type': 'string', 'children': [], 'value': "'_static doc dir not found: {0}'"},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '302', 'type': 'argument_list', 'children': ['303']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'full_static_dir'},{'id': '304', 'type': 'expression_statement', 'children': ['305']},{'id': '305', 'type': 'call', 'children': ['306', '309']},{'id': '306', 'type': 'attribute', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '309', 'type': 'argument_list', 'children': ['310']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '311', 'type': 'continue_statement', 'children': []},{'id': '312', 'type': 'expression_statement', 'children': ['313']},{'id': '313', 'type': 'assignment', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'relative_static_dir'},{'id': '315', 'type': 'call', 'children': ['316', '321']},{'id': '316', 'type': 'attribute', 'children': ['317', '320']},{'id': '317', 'type': 'attribute', 'children': ['318', '319']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'relpath'},{'id': '321', 'type': 'argument_list', 'children': ['322', '323']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'full_static_dir'},{'id': '323', 'type': 'call', 'children': ['324', '329']},{'id': '324', 'type': 'attribute', 'children': ['325', '328']},{'id': '325', 'type': 'attribute', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '329', 'type': 'argument_list', 'children': ['330', '331']},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'doc_dir'},{'id': '331', 'type': 'string', 'children': [], 'value': "'_static'"},{'id': '332', 'type': 'expression_statement', 'children': ['333']},{'id': '333', 'type': 'assignment', 'children': ['334', '337']},{'id': '334', 'type': 'subscript', 'children': ['335', '336']},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'static_dirs'},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'relative_static_dir'},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'full_static_dir'},{'id': '338', 'type': 'expression_statement', 'children': ['339']},{'id': '339', 'type': 'call', 'children': ['340', '343']},{'id': '340', 'type': 'attribute', 'children': ['341', '342']},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '343', 'type': 'argument_list', 'children': ['344']},{'id': '344', 'type': 'call', 'children': ['345', '348']},{'id': '345', 'type': 'attribute', 'children': ['346', '347']},{'id': '346', 'type': 'string', 'children': [], 'value': "'Found _static doc dir: {0}'"},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '348', 'type': 'argument_list', 'children': ['349']},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'full_static_dir'},{'id': '350', 'type': 'expression_statement', 'children': ['351']},{'id': '351', 'type': 'assignment', 'children': ['352', '353']},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'Dirs'},{'id': '353', 'type': 'call', 'children': ['354', '355']},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'namedtuple'},{'id': '355', 'type': 'argument_list', 'children': ['356', '357']},{'id': '356', 'type': 'string', 'children': [], 'value': "'Dirs'"},{'id': '357', 'type': 'list', 'children': ['358', '359', '360'], 'value': "['module_dirs', 'package_dirs', 'static_dirs']"},{'id': '358', 'type': 'string', 'children': [], 'value': "'module_dirs'"},{'id': '359', 'type': 'string', 'children': [], 'value': "'package_dirs'"},{'id': '360', 'type': 'string', 'children': [], 'value': "'static_dirs'"},{'id': '361', 'type': 'return_statement', 'children': ['362']},{'id': '362', 'type': 'call', 'children': ['363', '364']},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'Dirs'},{'id': '364', 'type': 'argument_list', 'children': ['365', '368', '371']},{'id': '365', 'type': 'keyword_argument', 'children': ['366', '367']},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'module_dirs'},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'module_dirs'},{'id': '368', 'type': 'keyword_argument', 'children': ['369', '370']},{'id': '369', 'type': 'identifier', 'children': [], 'value': 'package_dirs'},{'id': '370', 'type': 'identifier', 'children': [], 'value': 'package_dirs'},{'id': '371', 'type': 'keyword_argument', 'children': ['372', '373']},{'id': '372', 'type': 'identifier', 'children': [], 'value': 'static_dirs'},{'id': '373', 'type': 'identifier', 'children': [], 'value': 'static_dirs'}
def find_package_docs(package_dir, skippedNames=None): 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) 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) 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) if not os.path.isdir(full_static_dir): message = '_static doc dir not found: {0}'.format( full_static_dir) logger.warning(message) continue 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)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_max_id'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '6', 'type': 'block', 'children': ['7', '11', '56', '70', '90', '99']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'id_base'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'for_statement', 'children': ['12', '13', '22']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '13', 'type': 'binary_operator', 'children': ['14', '16'], 'value': '+'},{'id': '14', 'type': 'list', 'children': ['15'], 'value': '[cls]'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '21', 'type': 'identifier', 'children': [], 'value': '__bases__'},{'id': '22', 'type': 'block', 'children': ['23']},{'id': '23', 'type': 'for_statement', 'children': ['24', '25', '28']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'base_class'},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '27', 'type': 'identifier', 'children': [], 'value': '__bases__'},{'id': '28', 'type': 'block', 'children': ['29']},{'id': '29', 'type': 'if_statement', 'children': ['30', '35']},{'id': '30', 'type': 'comparison_operator', 'children': ['31', '34'], 'value': '=='},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'base_class'},{'id': '33', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '34', 'type': 'string', 'children': [], 'value': "'Base'"},{'id': '35', 'type': 'block', 'children': ['36']},{'id': '36', 'type': 'if_statement', 'children': ['37', '40', '45']},{'id': '37', 'type': 'comparison_operator', 'children': ['38', '39'], 'value': 'is'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'id_base'},{'id': '39', 'type': 'None', 'children': []},{'id': '40', 'type': 'block', 'children': ['41']},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'id_base'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '45', 'type': 'else_clause', 'children': ['46']},{'id': '46', 'type': 'block', 'children': ['47']},{'id': '47', 'type': 'raise_statement', 'children': ['48']},{'id': '48', 'type': 'call', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'binary_operator', 'children': ['52', '53'], 'value': '+'},{'id': '52', 'type': 'string', 'children': [], 'value': '"Multiple base object classes for class "'},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '55', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '56', 'type': 'if_statement', 'children': ['57', '60']},{'id': '57', 'type': 'comparison_operator', 'children': ['58', '59'], 'value': 'is'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'id_base'},{'id': '59', 'type': 'None', 'children': []},{'id': '60', 'type': 'block', 'children': ['61']},{'id': '61', 'type': 'raise_statement', 'children': ['62']},{'id': '62', 'type': 'call', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'binary_operator', 'children': ['66', '67'], 'value': '+'},{'id': '66', 'type': 'string', 'children': [], 'value': '"Error searching for base class of "'},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '69', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'max_id'},{'id': '73', 'type': 'call', 'children': ['74', '89']},{'id': '74', 'type': 'attribute', 'children': ['75', '88']},{'id': '75', 'type': 'call', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'call', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'id_base'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'scalar'},{'id': '89', 'type': 'argument_list', 'children': []},{'id': '90', 'type': 'if_statement', 'children': ['91', '94']},{'id': '91', 'type': 'comparison_operator', 'children': ['92', '93'], 'value': 'is'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'max_id'},{'id': '93', 'type': 'None', 'children': []},{'id': '94', 'type': 'block', 'children': ['95']},{'id': '95', 'type': 'expression_statement', 'children': ['96']},{'id': '96', 'type': 'assignment', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'max_id'},{'id': '98', 'type': 'integer', 'children': [], 'value': '0'},{'id': '99', 'type': 'return_statement', 'children': ['100']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'max_id'}
def get_max_id(cls, session): 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: id_base = c else: raise RuntimeError("Multiple base object classes for class " + cls.__name__) if id_base is None: raise RuntimeError("Error searching for base class of " + cls.__name__) max_id = session.query(func.max(id_base.id)).scalar() if max_id is None: max_id = 0 return max_id
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_insert_automodapi_configs'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '5', 'type': 'block', 'children': ['6', '12', '18', '24', '30', '36', '42', '50']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '11']},{'id': '8', 'type': 'subscript', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '10', 'type': 'string', 'children': [], 'value': "'numpydoc_show_class_members'"},{'id': '11', 'type': 'False', 'children': []},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '17']},{'id': '14', 'type': 'subscript', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '16', 'type': 'string', 'children': [], 'value': "'autosummary_generate'"},{'id': '17', 'type': 'True', 'children': []},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '23']},{'id': '20', 'type': 'subscript', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '22', 'type': 'string', 'children': [], 'value': "'automodapi_toctreedirnm'"},{'id': '23', 'type': 'string', 'children': [], 'value': "'py-api'"},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '29']},{'id': '26', 'type': 'subscript', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '28', 'type': 'string', 'children': [], 'value': "'automodsumm_inherited_members'"},{'id': '29', 'type': 'True', 'children': []},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '35']},{'id': '32', 'type': 'subscript', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '34', 'type': 'string', 'children': [], 'value': "'autodoc_inherit_docstrings'"},{'id': '35', 'type': 'True', 'children': []},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '41']},{'id': '38', 'type': 'subscript', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '40', 'type': 'string', 'children': [], 'value': "'autoclass_content'"},{'id': '41', 'type': 'string', 'children': [], 'value': '"class"'},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '47']},{'id': '44', 'type': 'subscript', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '46', 'type': 'string', 'children': [], 'value': "'autodoc_default_flags'"},{'id': '47', 'type': 'list', 'children': ['48', '49'], 'value': "['show-inheritance',\n 'special-members']"},{'id': '48', 'type': 'string', 'children': [], 'value': "'show-inheritance'"},{'id': '49', 'type': 'string', 'children': [], 'value': "'special-members'"},{'id': '50', 'type': 'return_statement', 'children': ['51']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'c'}
def _insert_automodapi_configs(c): c['numpydoc_show_class_members'] = False c['autosummary_generate'] = True c['automodapi_toctreedirnm'] = 'py-api' c['automodsumm_inherited_members'] = True c['autodoc_inherit_docstrings'] = True c['autoclass_content'] = "class" c['autodoc_default_flags'] = ['show-inheritance', 'special-members'] return c
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'build_pipelines_lsst_io_configs'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'keyword_separator', 'children': []},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'project_name'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'copyright'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '17', '21', '31', '44', '51', '58', '65', '72', '79', '86', '96', '107', '122', '128', '142', '149', '156']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'call', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'setrecursionlimit'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'integer', 'children': [], 'value': '2000'},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '20', 'type': 'dictionary', 'children': []},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': '_insert_common_sphinx_configs'},{'id': '26', 'type': 'argument_list', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '28', 'type': 'keyword_argument', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'project_name'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'project_name'},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': '_insert_html_configs'},{'id': '36', 'type': 'argument_list', 'children': ['37', '38', '41']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '38', 'type': 'keyword_argument', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'project_name'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'project_name'},{'id': '41', 'type': 'keyword_argument', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'short_project_name'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'project_name'},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '47', 'type': 'call', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': '_insert_extensions'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': '_insert_intersphinx_mapping'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': '_insert_automodapi_configs'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '68', 'type': 'call', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': '_insert_matplotlib_configs'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '75', 'type': 'call', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': '_insert_graphviz_configs'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '82', 'type': 'call', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': '_insert_eups_version'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'assignment', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'date'},{'id': '89', 'type': 'call', 'children': ['90', '95']},{'id': '90', 'type': 'attribute', 'children': ['91', '94']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '95', 'type': 'argument_list', 'children': []},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'assignment', 'children': ['98', '101']},{'id': '98', 'type': 'subscript', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '100', 'type': 'string', 'children': [], 'value': "'today'"},{'id': '101', 'type': 'call', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'date'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'strftime'},{'id': '105', 'type': 'argument_list', 'children': ['106']},{'id': '106', 'type': 'string', 'children': [], 'value': "'%Y-%m-%d'"},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '112']},{'id': '109', 'type': 'subscript', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '111', 'type': 'string', 'children': [], 'value': "'copyright'"},{'id': '112', 'type': 'call', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'string', 'children': [], 'value': "'2015-{year} LSST contributors'"},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '116', 'type': 'argument_list', 'children': ['117']},{'id': '117', 'type': 'keyword_argument', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'year'},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'date'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'year'},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'assignment', 'children': ['124', '127']},{'id': '124', 'type': 'subscript', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '126', 'type': 'string', 'children': [], 'value': "'todo_include_todos'"},{'id': '127', 'type': 'False', 'children': []},{'id': '128', 'type': 'expression_statement', 'children': ['129']},{'id': '129', 'type': 'assignment', 'children': ['130', '133']},{'id': '130', 'type': 'subscript', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '132', 'type': 'string', 'children': [], 'value': "'exclude_patterns'"},{'id': '133', 'type': 'list', 'children': ['134', '135', '136', '137', '138', '139', '140', '141'], 'value': "[\n 'README.rst',\n '_build',\n 'releases/note-source/*.rst',\n 'releases/tickets-source/*.rst',\n 'ups',\n '.pyvenv',\n '.github',\n 'home',\n ]"},{'id': '134', 'type': 'string', 'children': [], 'value': "'README.rst'"},{'id': '135', 'type': 'string', 'children': [], 'value': "'_build'"},{'id': '136', 'type': 'string', 'children': [], 'value': "'releases/note-source/*.rst'"},{'id': '137', 'type': 'string', 'children': [], 'value': "'releases/tickets-source/*.rst'"},{'id': '138', 'type': 'string', 'children': [], 'value': "'ups'"},{'id': '139', 'type': 'string', 'children': [], 'value': "'.pyvenv'"},{'id': '140', 'type': 'string', 'children': [], 'value': "'.github'"},{'id': '141', 'type': 'string', 'children': [], 'value': "'home'"},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'assignment', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '145', 'type': 'call', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': '_insert_rst_epilog'},{'id': '147', 'type': 'argument_list', 'children': ['148']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'assignment', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '152', 'type': 'call', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': '_insert_jinja_configuration'},{'id': '154', 'type': 'argument_list', 'children': ['155']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '156', 'type': 'return_statement', 'children': ['157']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'c'}
def build_pipelines_lsst_io_configs(*, project_name, copyright=None): sys.setrecursionlimit(2000) c = {} c = _insert_common_sphinx_configs( c, project_name=project_name) c = _insert_html_configs( c, project_name=project_name, short_project_name=project_name) c = _insert_extensions(c) c = _insert_intersphinx_mapping(c) c = _insert_automodapi_configs(c) c = _insert_matplotlib_configs(c) c = _insert_graphviz_configs(c) c = _insert_eups_version(c) date = datetime.datetime.now() c['today'] = date.strftime('%Y-%m-%d') c['copyright'] = '2015-{year} LSST contributors'.format( year=date.year) c['todo_include_todos'] = False c['exclude_patterns'] = [ 'README.rst', '_build', 'releases/note-source/*.rst', 'releases/tickets-source/*.rst', 'ups', '.pyvenv', '.github', 'home', ] c = _insert_rst_epilog(c) c = _insert_jinja_configuration(c) return c