code
stringlengths 51
2.34k
| sequence
stringlengths 1.16k
13.1k
| docstring
stringlengths 11
171
|
|---|---|---|
def box_text(text, width, offset=0):
box = " " * offset + "-" * (width+2) + "\n"
box += " " * offset + "|" + text.center(width) + "|" + "\n"
box += " " * offset + "-" * (width+2)
return box
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'box_text'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'width'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '8', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '9', 'type': 'block', 'children': ['10', '25', '44', '57']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}; {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'box'}; {'id': '13', 'type': 'binary_operator', 'children': ['14', '24'], 'value': '+'}; {'id': '14', 'type': 'binary_operator', 'children': ['15', '18'], 'value': '+'}; {'id': '15', 'type': 'binary_operator', 'children': ['16', '17'], 'value': '*'}; {'id': '16', 'type': 'string', 'children': [], 'value': '" "'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '18', 'type': 'binary_operator', 'children': ['19', '20'], 'value': '*'}; {'id': '19', 'type': 'string', 'children': [], 'value': '"-"'}; {'id': '20', 'type': '()', 'children': ['21']}; {'id': '21', 'type': 'binary_operator', 'children': ['22', '23'], 'value': '+'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'width'}; {'id': '23', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '24', 'type': 'string', 'children': [], 'value': '"\\n"'}; {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'augmented_assignment', 'children': ['27', '28'], 'value': '+='}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'box'}; {'id': '28', 'type': 'binary_operator', 'children': ['29', '43'], 'value': '+'}; {'id': '29', 'type': 'binary_operator', 'children': ['30', '42'], 'value': '+'}; {'id': '30', 'type': 'binary_operator', 'children': ['31', '36'], 'value': '+'}; {'id': '31', 'type': 'binary_operator', 'children': ['32', '35'], 'value': '+'}; {'id': '32', 'type': 'binary_operator', 'children': ['33', '34'], 'value': '*'}; {'id': '33', 'type': 'string', 'children': [], 'value': '" "'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '35', 'type': 'string', 'children': [], 'value': '"|"'}; {'id': '36', 'type': 'call', 'children': ['37', '40']}; {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'center'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'width'}; {'id': '42', 'type': 'string', 'children': [], 'value': '"|"'}; {'id': '43', 'type': 'string', 'children': [], 'value': '"\\n"'}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}; {'id': '45', 'type': 'augmented_assignment', 'children': ['46', '47'], 'value': '+='}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'box'}; {'id': '47', 'type': 'binary_operator', 'children': ['48', '51'], 'value': '+'}; {'id': '48', 'type': 'binary_operator', 'children': ['49', '50'], 'value': '*'}; {'id': '49', 'type': 'string', 'children': [], 'value': '" "'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '51', 'type': 'binary_operator', 'children': ['52', '53'], 'value': '*'}; {'id': '52', 'type': 'string', 'children': [], 'value': '"-"'}; {'id': '53', 'type': '()', 'children': ['54']}; {'id': '54', 'type': 'binary_operator', 'children': ['55', '56'], 'value': '+'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'width'}; {'id': '56', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '57', 'type': 'return_statement', 'children': ['58']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'box'}
|
Return text inside an ascii textbox
|
def match_comment(self):
match = self.match(r"<%doc>(.*?)</%doc>", re.S)
if match:
self.append_node(parsetree.Comment, match.group(1))
return True
else:
return False
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'match_comment'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '18']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'match'}; {'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': 'match'}; {'id': '13', 'type': 'argument_list', 'children': ['14', '15']}; {'id': '14', 'type': 'string', 'children': [], 'value': 'r"<%doc>(.*?)</%doc>"'}; {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'S'}; {'id': '18', 'type': 'if_statement', 'children': ['19', '20', '38']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '20', 'type': 'block', 'children': ['21', '36']}; {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'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': 'append_node'}; {'id': '26', 'type': 'argument_list', 'children': ['27', '30']}; {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'parsetree'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'Comment'}; {'id': '30', 'type': 'call', 'children': ['31', '34']}; {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}; {'id': '35', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '36', 'type': 'return_statement', 'children': ['37']}; {'id': '37', 'type': 'True', 'children': []}; {'id': '38', 'type': 'else_clause', 'children': ['39']}; {'id': '39', 'type': 'block', 'children': ['40']}; {'id': '40', 'type': 'return_statement', 'children': ['41']}; {'id': '41', 'type': 'False', 'children': []}
|
matches the multiline version of a comment
|
def _change_kind(self, post_uid):
post_data = self.get_post_data()
logger.info('admin post update: {0}'.format(post_data))
MPost.update_misc(post_uid, kind=post_data['kcat'])
update_category(post_uid, post_data)
self.redirect('/{0}/{1}'.format(router_post[post_data['kcat']], post_uid))
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_change_kind'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'post_uid'}; {'id': '6', 'type': 'block', 'children': ['7', '15', '27', '39', '45']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'post_data'}; {'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': 'get_post_data'}; {'id': '14', 'type': 'argument_list', 'children': []}; {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'call', 'children': ['17', '20']}; {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}; {'id': '21', 'type': 'call', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'string', 'children': [], 'value': "'admin post update: {0}'"}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'post_data'}; {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'call', 'children': ['29', '32']}; {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'MPost'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'update_misc'}; {'id': '32', 'type': 'argument_list', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'post_uid'}; {'id': '34', 'type': 'keyword_argument', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'kind'}; {'id': '36', 'type': 'subscript', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'post_data'}; {'id': '38', 'type': 'string', 'children': [], 'value': "'kcat'"}; {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'call', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'update_category'}; {'id': '42', 'type': 'argument_list', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'post_uid'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'post_data'}; {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'call', 'children': ['47', '50']}; {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'redirect'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}; {'id': '51', 'type': 'call', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}; {'id': '53', 'type': 'string', 'children': [], 'value': "'/{0}/{1}'"}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '55', 'type': 'argument_list', 'children': ['56', '61']}; {'id': '56', 'type': 'subscript', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'router_post'}; {'id': '58', 'type': 'subscript', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'post_data'}; {'id': '60', 'type': 'string', 'children': [], 'value': "'kcat'"}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'post_uid'}
|
To modify the category of the post, and kind.
|
def acknowledge_streamer(self, index, ack, force):
if index >= len(self.graph.streamers):
return _pack_sgerror(SensorGraphError.STREAMER_NOT_ALLOCATED)
old_ack = self.streamer_acks.get(index, 0)
if ack != 0:
if ack <= old_ack and not force:
return _pack_sgerror(SensorGraphError.OLD_ACKNOWLEDGE_UPDATE)
self.streamer_acks[index] = ack
current_ack = self.streamer_acks.get(index, 0)
return self._seek_streamer(index, current_ack)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'acknowledge_streamer'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'ack'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'force'}; {'id': '8', 'type': 'block', 'children': ['9', '28', '40', '68', '80']}; {'id': '9', 'type': 'if_statement', 'children': ['10', '20']}; {'id': '10', 'type': 'comparison_operator', 'children': ['11', '12'], 'value': '>='}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '12', 'type': 'call', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}; {'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': 'graph'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'streamers'}; {'id': '20', 'type': 'block', 'children': ['21']}; {'id': '21', 'type': 'return_statement', 'children': ['22']}; {'id': '22', 'type': 'call', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': '_pack_sgerror'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}; {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'SensorGraphError'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'STREAMER_NOT_ALLOCATED'}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}; {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'old_ack'}; {'id': '31', 'type': 'call', 'children': ['32', '37']}; {'id': '32', 'type': 'attribute', 'children': ['33', '36']}; {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'streamer_acks'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '37', 'type': 'argument_list', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '39', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '40', 'type': 'if_statement', 'children': ['41', '44']}; {'id': '41', 'type': 'comparison_operator', 'children': ['42', '43'], 'value': '!='}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'ack'}; {'id': '43', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '44', 'type': 'block', 'children': ['45', '60']}; {'id': '45', 'type': 'if_statement', 'children': ['46', '52']}; {'id': '46', 'type': 'boolean_operator', 'children': ['47', '50'], 'value': 'and'}; {'id': '47', 'type': 'comparison_operator', 'children': ['48', '49'], 'value': '<='}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'ack'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'old_ack'}; {'id': '50', 'type': 'not_operator', 'children': ['51']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'force'}; {'id': '52', 'type': 'block', 'children': ['53']}; {'id': '53', 'type': 'return_statement', 'children': ['54']}; {'id': '54', 'type': 'call', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': '_pack_sgerror'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}; {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'SensorGraphError'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'OLD_ACKNOWLEDGE_UPDATE'}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}; {'id': '61', 'type': 'assignment', 'children': ['62', '67']}; {'id': '62', 'type': 'subscript', 'children': ['63', '66']}; {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'streamer_acks'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'ack'}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}; {'id': '69', 'type': 'assignment', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'current_ack'}; {'id': '71', 'type': 'call', 'children': ['72', '77']}; {'id': '72', 'type': 'attribute', 'children': ['73', '76']}; {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'streamer_acks'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '77', 'type': 'argument_list', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '79', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '80', 'type': 'return_statement', 'children': ['81']}; {'id': '81', 'type': 'call', 'children': ['82', '85']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': '_seek_streamer'}; {'id': '85', 'type': 'argument_list', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'current_ack'}
|
Acknowledge a streamer value as received from the remote side.
|
def merge_nested_environment_dicts(env_dicts, env_name=None, env_root=None):
if all(isinstance(val, (six.string_types, list))
for (_key, val) in env_dicts.items()):
return flatten_path_lists(env_dicts, env_root)
if env_name is None:
if env_dicts.get('*'):
return flatten_path_lists(env_dicts.get('*'), env_root)
raise AttributeError("Provided config key:val pairs %s aren't usable with no environment provided" % env_dicts)
if not env_dicts.get('*') and not env_dicts.get(env_name):
raise AttributeError("Provided config key:val pairs %s aren't usable with environment %s" % (env_dicts, env_name))
combined_dicts = merge_dicts(env_dicts.get('*', {}),
env_dicts.get(env_name, {}))
return flatten_path_lists(combined_dicts, env_root)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'merge_nested_environment_dicts'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'env_dicts'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'env_name'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'env_root'}; {'id': '10', 'type': 'None', 'children': []}; {'id': '11', 'type': 'block', 'children': ['12', '41', '72', '98', '118']}; {'id': '12', 'type': 'if_statement', 'children': ['13', '34']}; {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'all'}; {'id': '15', 'type': 'generator_expression', 'children': ['16', '25']}; {'id': '16', 'type': 'call', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '18', 'type': 'argument_list', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '20', 'type': 'tuple', 'children': ['21', '24']}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'string_types'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '25', 'type': 'for_in_clause', 'children': ['26', '29']}; {'id': '26', 'type': 'tuple_pattern', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': '_key'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '29', 'type': 'call', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'env_dicts'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '33', 'type': 'argument_list', 'children': []}; {'id': '34', 'type': 'block', 'children': ['35']}; {'id': '35', 'type': 'return_statement', 'children': ['36']}; {'id': '36', 'type': 'call', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'flatten_path_lists'}; {'id': '38', 'type': 'argument_list', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'env_dicts'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'env_root'}; {'id': '41', 'type': 'if_statement', 'children': ['42', '45']}; {'id': '42', 'type': 'comparison_operator', 'children': ['43', '44'], 'value': 'is'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'env_name'}; {'id': '44', 'type': 'None', 'children': []}; {'id': '45', 'type': 'block', 'children': ['46', '65']}; {'id': '46', 'type': 'if_statement', 'children': ['47', '53']}; {'id': '47', 'type': 'call', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'env_dicts'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'string', 'children': [], 'value': "'*'"}; {'id': '53', 'type': 'block', 'children': ['54']}; {'id': '54', 'type': 'return_statement', 'children': ['55']}; {'id': '55', 'type': 'call', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'flatten_path_lists'}; {'id': '57', 'type': 'argument_list', 'children': ['58', '64']}; {'id': '58', 'type': 'call', 'children': ['59', '62']}; {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'env_dicts'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}; {'id': '63', 'type': 'string', 'children': [], 'value': "'*'"}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'env_root'}; {'id': '65', 'type': 'raise_statement', 'children': ['66']}; {'id': '66', 'type': 'call', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'AttributeError'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}; {'id': '69', 'type': 'binary_operator', 'children': ['70', '71'], 'value': '%'}; {'id': '70', 'type': 'string', 'children': [], 'value': '"Provided config key:val pairs %s aren\'t usable with no environment provided"'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'env_dicts'}; {'id': '72', 'type': 'if_statement', 'children': ['73', '88']}; {'id': '73', 'type': 'boolean_operator', 'children': ['74', '81'], 'value': 'and'}; {'id': '74', 'type': 'not_operator', 'children': ['75']}; {'id': '75', 'type': 'call', 'children': ['76', '79']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'env_dicts'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'string', 'children': [], 'value': "'*'"}; {'id': '81', 'type': 'not_operator', 'children': ['82']}; {'id': '82', 'type': 'call', 'children': ['83', '86']}; {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'env_dicts'}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '86', 'type': 'argument_list', 'children': ['87']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'env_name'}; {'id': '88', 'type': 'block', 'children': ['89']}; {'id': '89', 'type': 'raise_statement', 'children': ['90']}; {'id': '90', 'type': 'call', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'AttributeError'}; {'id': '92', 'type': 'argument_list', 'children': ['93']}; {'id': '93', 'type': 'binary_operator', 'children': ['94', '95'], 'value': '%'}; {'id': '94', 'type': 'string', 'children': [], 'value': '"Provided config key:val pairs %s aren\'t usable with environment %s"'}; {'id': '95', 'type': 'tuple', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'env_dicts'}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'env_name'}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}; {'id': '99', 'type': 'assignment', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'combined_dicts'}; {'id': '101', 'type': 'call', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'merge_dicts'}; {'id': '103', 'type': 'argument_list', 'children': ['104', '111']}; {'id': '104', 'type': 'call', 'children': ['105', '108']}; {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'env_dicts'}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '108', 'type': 'argument_list', 'children': ['109', '110']}; {'id': '109', 'type': 'string', 'children': [], 'value': "'*'"}; {'id': '110', 'type': 'dictionary', 'children': []}; {'id': '111', 'type': 'call', 'children': ['112', '115']}; {'id': '112', 'type': 'attribute', 'children': ['113', '114']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'env_dicts'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '115', 'type': 'argument_list', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'env_name'}; {'id': '117', 'type': 'dictionary', 'children': []}; {'id': '118', 'type': 'return_statement', 'children': ['119']}; {'id': '119', 'type': 'call', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'flatten_path_lists'}; {'id': '121', 'type': 'argument_list', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'combined_dicts'}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'env_root'}
|
Return single-level dictionary from dictionary of dictionaries.
|
def match(tgt, opts=None):
if not opts:
opts = __opts__
if HAS_RANGE:
range_ = seco.range.Range(opts['range_server'])
try:
return opts['grains']['fqdn'] in range_.expand(tgt)
except seco.range.RangeException as exc:
log.debug('Range exception in compound match: %s', exc)
return False
return False
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'match'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'tgt'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'opts'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '17', '68']}; {'id': '9', 'type': 'if_statement', 'children': ['10', '12']}; {'id': '10', 'type': 'not_operator', 'children': ['11']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'opts'}; {'id': '12', 'type': 'block', 'children': ['13']}; {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'opts'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': '__opts__'}; {'id': '17', 'type': 'if_statement', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'HAS_RANGE'}; {'id': '19', 'type': 'block', 'children': ['20', '33']}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}; {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'range_'}; {'id': '23', 'type': 'call', 'children': ['24', '29']}; {'id': '24', 'type': 'attribute', 'children': ['25', '28']}; {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'seco'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'Range'}; {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'subscript', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'opts'}; {'id': '32', 'type': 'string', 'children': [], 'value': "'range_server'"}; {'id': '33', 'type': 'try_statement', 'children': ['34', '48']}; {'id': '34', 'type': 'block', 'children': ['35']}; {'id': '35', 'type': 'return_statement', 'children': ['36']}; {'id': '36', 'type': 'comparison_operator', 'children': ['37', '42'], 'value': 'in'}; {'id': '37', 'type': 'subscript', 'children': ['38', '41']}; {'id': '38', 'type': 'subscript', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'opts'}; {'id': '40', 'type': 'string', 'children': [], 'value': "'grains'"}; {'id': '41', 'type': 'string', 'children': [], 'value': "'fqdn'"}; {'id': '42', 'type': 'call', 'children': ['43', '46']}; {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'range_'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'expand'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'tgt'}; {'id': '48', 'type': 'except_clause', 'children': ['49', '57']}; {'id': '49', 'type': 'as_pattern', 'children': ['50', '55']}; {'id': '50', 'type': 'attribute', 'children': ['51', '54']}; {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'seco'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'RangeException'}; {'id': '55', 'type': 'as_pattern_target', 'children': ['56']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'exc'}; {'id': '57', 'type': 'block', 'children': ['58', '66']}; {'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': 'log'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '63', 'type': 'argument_list', 'children': ['64', '65']}; {'id': '64', 'type': 'string', 'children': [], 'value': "'Range exception in compound match: %s'"}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'exc'}; {'id': '66', 'type': 'return_statement', 'children': ['67']}; {'id': '67', 'type': 'False', 'children': []}; {'id': '68', 'type': 'return_statement', 'children': ['69']}; {'id': '69', 'type': 'False', 'children': []}
|
Matches based on range cluster
|
def register_foreign_device(self, addr, ttl):
if _debug: BIPBBMD._debug("register_foreign_device %r %r", addr, ttl)
if isinstance(addr, Address):
pass
elif isinstance(addr, str):
addr = Address(addr)
else:
raise TypeError("addr must be a string or an Address")
for fdte in self.bbmdFDT:
if addr == fdte.fdAddress:
break
else:
fdte = FDTEntry()
fdte.fdAddress = addr
self.bbmdFDT.append( fdte )
fdte.fdTTL = ttl
fdte.fdRemain = ttl + 5
return 0
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'register_foreign_device'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'addr'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'ttl'}; {'id': '7', 'type': 'block', 'children': ['8', '20', '49', '86', '92', '100']}; {'id': '8', 'type': 'if_statement', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': '_debug'}; {'id': '10', 'type': 'block', 'children': ['11']}; {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'call', 'children': ['13', '16']}; {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'BIPBBMD'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': '_debug'}; {'id': '16', 'type': 'argument_list', 'children': ['17', '18', '19']}; {'id': '17', 'type': 'string', 'children': [], 'value': '"register_foreign_device %r %r"'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'addr'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'ttl'}; {'id': '20', 'type': 'if_statement', 'children': ['21', '26', '28', '42']}; {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '23', 'type': 'argument_list', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'addr'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'Address'}; {'id': '26', 'type': 'block', 'children': ['27']}; {'id': '27', 'type': 'pass_statement', 'children': []}; {'id': '28', 'type': 'elif_clause', 'children': ['29', '34']}; {'id': '29', 'type': 'call', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '31', 'type': 'argument_list', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'addr'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'str'}; {'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': 'addr'}; {'id': '38', 'type': 'call', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'Address'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'addr'}; {'id': '42', 'type': 'else_clause', 'children': ['43']}; {'id': '43', 'type': 'block', 'children': ['44']}; {'id': '44', 'type': 'raise_statement', 'children': ['45']}; {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'TypeError'}; {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'string', 'children': [], 'value': '"addr must be a string or an Address"'}; {'id': '49', 'type': 'for_statement', 'children': ['50', '51', '54', '63']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'fdte'}; {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'bbmdFDT'}; {'id': '54', 'type': 'block', 'children': ['55']}; {'id': '55', 'type': 'if_statement', 'children': ['56', '61']}; {'id': '56', 'type': 'comparison_operator', 'children': ['57', '58'], 'value': '=='}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'addr'}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'fdte'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'fdAddress'}; {'id': '61', 'type': 'block', 'children': ['62']}; {'id': '62', 'type': 'break_statement', 'children': []}; {'id': '63', 'type': 'else_clause', 'children': ['64']}; {'id': '64', 'type': 'block', 'children': ['65', '71', '77']}; {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'fdte'}; {'id': '68', 'type': 'call', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'FDTEntry'}; {'id': '70', 'type': 'argument_list', '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': 'fdte'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'fdAddress'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'addr'}; {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'call', 'children': ['79', '84']}; {'id': '79', 'type': 'attribute', 'children': ['80', '83']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'bbmdFDT'}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '84', 'type': 'argument_list', 'children': ['85']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'fdte'}; {'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': 'fdte'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'fdTTL'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'ttl'}; {'id': '92', 'type': 'expression_statement', 'children': ['93']}; {'id': '93', 'type': 'assignment', 'children': ['94', '97']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'fdte'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'fdRemain'}; {'id': '97', 'type': 'binary_operator', 'children': ['98', '99'], 'value': '+'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'ttl'}; {'id': '99', 'type': 'integer', 'children': [], 'value': '5'}; {'id': '100', 'type': 'return_statement', 'children': ['101']}; {'id': '101', 'type': 'integer', 'children': [], 'value': '0'}
|
Add a foreign device to the FDT.
|
def _write(self, stream, text, byte_order):
if text:
self._write_txt(stream)
else:
if self._have_list:
self._write_bin(stream, byte_order)
else:
stream.write(self.data.astype(self.dtype(byte_order),
copy=False).data)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_write'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'stream'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'byte_order'}; {'id': '8', 'type': 'block', 'children': ['9']}; {'id': '9', 'type': 'if_statement', 'children': ['10', '11', '19']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '11', 'type': 'block', 'children': ['12']}; {'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': 'self'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': '_write_txt'}; {'id': '17', 'type': 'argument_list', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'stream'}; {'id': '19', 'type': 'else_clause', 'children': ['20']}; {'id': '20', 'type': 'block', 'children': ['21']}; {'id': '21', 'type': 'if_statement', 'children': ['22', '25', '34']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': '_have_list'}; {'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': 'self'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': '_write_bin'}; {'id': '31', 'type': 'argument_list', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'stream'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'byte_order'}; {'id': '34', 'type': 'else_clause', 'children': ['35']}; {'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': 'stream'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'attribute', 'children': ['43', '59']}; {'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': 'data'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'astype'}; {'id': '49', 'type': 'argument_list', 'children': ['50', '56']}; {'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': 'dtype'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'byte_order'}; {'id': '56', 'type': 'keyword_argument', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '58', 'type': 'False', 'children': []}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'data'}
|
Write the data to a PLY file.
|
def open(self, filename, mode='r', bufsize=-1):
sftp_client = self.open_sftp()
return sftp_client.open(filename, mode, bufsize)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'open'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '8', 'type': 'string', 'children': [], 'value': "'r'"}; {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'bufsize'}; {'id': '11', 'type': 'unary_operator', 'children': ['12'], 'value': '-'}; {'id': '12', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '13', 'type': 'block', 'children': ['14', '22']}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}; {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'sftp_client'}; {'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': 'open_sftp'}; {'id': '21', 'type': 'argument_list', 'children': []}; {'id': '22', 'type': 'return_statement', 'children': ['23']}; {'id': '23', 'type': 'call', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'sftp_client'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '27', 'type': 'argument_list', 'children': ['28', '29', '30']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'bufsize'}
|
Open a file on the remote system and return a file-like object.
|
def setup_buttons(self):
self.fromcursor_btn = create_toolbutton(
self, icon=ima.icon('fromcursor'), tip=_('Go to cursor position'),
triggered=self.treewidget.go_to_cursor_position)
buttons = [self.fromcursor_btn]
for action in [self.treewidget.collapse_all_action,
self.treewidget.expand_all_action,
self.treewidget.restore_action,
self.treewidget.collapse_selection_action,
self.treewidget.expand_selection_action]:
buttons.append(create_toolbutton(self))
buttons[-1].setDefaultAction(action)
return buttons
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'setup_buttons'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '36', '43', '92']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '11']}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'fromcursor_btn'}; {'id': '11', 'type': 'call', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'create_toolbutton'}; {'id': '13', 'type': 'argument_list', 'children': ['14', '15', '23', '29']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '15', 'type': 'keyword_argument', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'icon'}; {'id': '17', 'type': 'call', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'ima'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'icon'}; {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'string', 'children': [], 'value': "'fromcursor'"}; {'id': '23', 'type': 'keyword_argument', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'tip'}; {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'string', 'children': [], 'value': "'Go to cursor position'"}; {'id': '29', 'type': 'keyword_argument', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'triggered'}; {'id': '31', 'type': 'attribute', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'treewidget'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'go_to_cursor_position'}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}; {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'buttons'}; {'id': '39', 'type': 'list', 'children': ['40'], 'value': '[self.fromcursor_btn]'}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'fromcursor_btn'}; {'id': '43', 'type': 'for_statement', 'children': ['44', '45', '71']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '45', 'type': 'list', 'children': ['46', '51', '56', '61', '66'], 'value': '[self.treewidget.collapse_all_action,\r\n self.treewidget.expand_all_action,\r\n self.treewidget.restore_action,\r\n self.treewidget.collapse_selection_action,\r\n self.treewidget.expand_selection_action]'}; {'id': '46', 'type': 'attribute', 'children': ['47', '50']}; {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'treewidget'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'collapse_all_action'}; {'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': 'treewidget'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'expand_all_action'}; {'id': '56', 'type': 'attribute', 'children': ['57', '60']}; {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'treewidget'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'restore_action'}; {'id': '61', 'type': 'attribute', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'treewidget'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'collapse_selection_action'}; {'id': '66', 'type': 'attribute', 'children': ['67', '70']}; {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'treewidget'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'expand_selection_action'}; {'id': '71', 'type': 'block', 'children': ['72', '82']}; {'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': 'buttons'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'call', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'create_toolbutton'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}; {'id': '83', 'type': 'call', 'children': ['84', '90']}; {'id': '84', 'type': 'attribute', 'children': ['85', '89']}; {'id': '85', 'type': 'subscript', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'buttons'}; {'id': '87', 'type': 'unary_operator', 'children': ['88'], 'value': '-'}; {'id': '88', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'setDefaultAction'}; {'id': '90', 'type': 'argument_list', 'children': ['91']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '92', 'type': 'return_statement', 'children': ['93']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'buttons'}
|
Setup the buttons of the outline explorer widget toolbar.
|
def to_dict(self):
return {'id': self.m_key + "_" + str(self.id_knwKB),
'key': self.m_key,
'value': self.m_value,
'kbid': self.kb.id if self.kb else None,
'kbname': self.kb.name if self.kb else None}
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'to_dict'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6']}; {'id': '6', 'type': 'return_statement', 'children': ['7']}; {'id': '7', 'type': 'dictionary', 'children': ['8', '22', '27', '32', '44']}; {'id': '8', 'type': 'pair', 'children': ['9', '10']}; {'id': '9', 'type': 'string', 'children': [], 'value': "'id'"}; {'id': '10', 'type': 'binary_operator', 'children': ['11', '16'], 'value': '+'}; {'id': '11', 'type': 'binary_operator', 'children': ['12', '15'], 'value': '+'}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'm_key'}; {'id': '15', 'type': 'string', 'children': [], 'value': '"_"'}; {'id': '16', 'type': 'call', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}; {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'id_knwKB'}; {'id': '22', 'type': 'pair', 'children': ['23', '24']}; {'id': '23', 'type': 'string', 'children': [], 'value': "'key'"}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'm_key'}; {'id': '27', 'type': 'pair', 'children': ['28', '29']}; {'id': '28', 'type': 'string', 'children': [], 'value': "'value'"}; {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'm_value'}; {'id': '32', 'type': 'pair', 'children': ['33', '34']}; {'id': '33', 'type': 'string', 'children': [], 'value': "'kbid'"}; {'id': '34', 'type': 'conditional_expression', 'children': ['35', '40', '43'], 'value': 'if'}; {'id': '35', 'type': 'attribute', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'kb'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'kb'}; {'id': '43', 'type': 'None', 'children': []}; {'id': '44', 'type': 'pair', 'children': ['45', '46']}; {'id': '45', 'type': 'string', 'children': [], 'value': "'kbname'"}; {'id': '46', 'type': 'conditional_expression', 'children': ['47', '52', '55'], 'value': 'if'}; {'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': 'kb'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'kb'}; {'id': '55', 'type': 'None', 'children': []}
|
Return a dict representation of KnwKBRVAL.
|
def table_path(cls, project, instance, table):
return google.api_core.path_template.expand(
"projects/{project}/instances/{instance}/tables/{table}",
project=project,
instance=instance,
table=table,
)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'table_path'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'project'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'instance'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'table'}; {'id': '8', 'type': 'block', 'children': ['9']}; {'id': '9', 'type': 'return_statement', 'children': ['10']}; {'id': '10', 'type': 'call', 'children': ['11', '18']}; {'id': '11', 'type': 'attribute', 'children': ['12', '17']}; {'id': '12', 'type': 'attribute', 'children': ['13', '16']}; {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'google'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'api_core'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'path_template'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'expand'}; {'id': '18', 'type': 'argument_list', 'children': ['19', '20', '23', '26']}; {'id': '19', 'type': 'string', 'children': [], 'value': '"projects/{project}/instances/{instance}/tables/{table}"'}; {'id': '20', 'type': 'keyword_argument', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'project'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'project'}; {'id': '23', 'type': 'keyword_argument', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'instance'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'instance'}; {'id': '26', 'type': 'keyword_argument', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'table'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'table'}
|
Return a fully-qualified table string.
|
def to_plot_units(self, data, dtype_vert=False):
if dtype_vert == 'vert_av' or not dtype_vert:
conv_factor = self.units.plot_units_conv
elif dtype_vert == ('vert_int'):
conv_factor = self.units.vert_int_plot_units_conv
else:
raise ValueError("dtype_vert value `{0}` not recognized. Only "
"bool(dtype_vert) = False, 'vert_av', and "
"'vert_int' supported.".format(dtype_vert))
if isinstance(data, dict):
return {key: val*conv_factor for key, val in data.items()}
return data*conv_factor
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'to_plot_units'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'dtype_vert'}; {'id': '8', 'type': 'False', 'children': []}; {'id': '9', 'type': 'block', 'children': ['10', '55', '78']}; {'id': '10', 'type': 'if_statement', 'children': ['11', '17', '26', '40']}; {'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': 'dtype_vert'}; {'id': '14', 'type': 'string', 'children': [], 'value': "'vert_av'"}; {'id': '15', 'type': 'not_operator', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'dtype_vert'}; {'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': 'conv_factor'}; {'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': 'units'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'plot_units_conv'}; {'id': '26', 'type': 'elif_clause', 'children': ['27', '31']}; {'id': '27', 'type': 'comparison_operator', 'children': ['28', '29'], 'value': '=='}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'dtype_vert'}; {'id': '29', 'type': '()', 'children': ['30']}; {'id': '30', 'type': 'string', 'children': [], 'value': "'vert_int'"}; {'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': 'conv_factor'}; {'id': '35', 'type': 'attribute', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'units'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'vert_int_plot_units_conv'}; {'id': '40', 'type': 'else_clause', 'children': ['41']}; {'id': '41', 'type': 'block', 'children': ['42']}; {'id': '42', 'type': 'raise_statement', 'children': ['43']}; {'id': '43', 'type': 'call', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'call', 'children': ['47', '53']}; {'id': '47', 'type': 'attribute', 'children': ['48', '52']}; {'id': '48', 'type': 'concatenated_string', 'children': ['49', '50', '51']}; {'id': '49', 'type': 'string', 'children': [], 'value': '"dtype_vert value `{0}` not recognized. Only "'}; {'id': '50', 'type': 'string', 'children': [], 'value': '"bool(dtype_vert) = False, \'vert_av\', and "'}; {'id': '51', 'type': 'string', 'children': [], 'value': '"\'vert_int\' supported."'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'dtype_vert'}; {'id': '55', 'type': 'if_statement', 'children': ['56', '61']}; {'id': '56', 'type': 'call', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '58', 'type': 'argument_list', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '61', 'type': 'block', 'children': ['62']}; {'id': '62', 'type': 'return_statement', 'children': ['63']}; {'id': '63', 'type': 'dictionary_comprehension', 'children': ['64', '69']}; {'id': '64', 'type': 'pair', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '66', 'type': 'binary_operator', 'children': ['67', '68'], 'value': '*'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'conv_factor'}; {'id': '69', 'type': 'for_in_clause', 'children': ['70', '73']}; {'id': '70', 'type': 'pattern_list', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '73', 'type': 'call', 'children': ['74', '77']}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '77', 'type': 'argument_list', 'children': []}; {'id': '78', 'type': 'return_statement', 'children': ['79']}; {'id': '79', 'type': 'binary_operator', 'children': ['80', '81'], 'value': '*'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'conv_factor'}
|
Convert the given data to plotting units.
|
def success(self, objects, message=None):
if self.is_context_only(objects):
return self.redirect(message=_("Changes saved."))
ids = map(api.get_id, objects)
if not message:
message = _("Saved items: {}").format(", ".join(ids))
return self.redirect(message=message)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'success'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'objects'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '8', 'type': 'None', 'children': []}; {'id': '9', 'type': 'block', 'children': ['10', '30', '40', '61']}; {'id': '10', 'type': 'if_statement', 'children': ['11', '17']}; {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'is_context_only'}; {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'objects'}; {'id': '17', 'type': 'block', 'children': ['18']}; {'id': '18', 'type': 'return_statement', 'children': ['19']}; {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'redirect'}; {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'keyword_argument', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '26', 'type': 'call', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}; {'id': '29', 'type': 'string', 'children': [], 'value': '"Changes saved."'}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}; {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'ids'}; {'id': '33', 'type': 'call', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'map'}; {'id': '35', 'type': 'argument_list', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'api'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'get_id'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'objects'}; {'id': '40', 'type': 'if_statement', 'children': ['41', '43']}; {'id': '41', 'type': 'not_operator', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'message'}; {'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': 'message'}; {'id': '47', 'type': 'call', 'children': ['48', '54']}; {'id': '48', 'type': 'attribute', 'children': ['49', '53']}; {'id': '49', 'type': 'call', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'string', 'children': [], 'value': '"Saved items: {}"'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}; {'id': '55', 'type': 'call', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}; {'id': '57', 'type': 'string', 'children': [], 'value': '", "'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '59', 'type': 'argument_list', 'children': ['60']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'ids'}; {'id': '61', 'type': 'return_statement', 'children': ['62']}; {'id': '62', 'type': 'call', 'children': ['63', '66']}; {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'redirect'}; {'id': '66', 'type': 'argument_list', 'children': ['67']}; {'id': '67', 'type': 'keyword_argument', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'message'}
|
Redirects the user to success page with informative message
|
def _load_meta_cache(self):
try:
if self._should_invalidate_cache():
os.remove(self._cache_filename)
else:
with open(self._cache_filename, 'rb') as f:
self._document_meta = compat.pickle.load(f)
except (OSError, IOError, compat.pickle.PickleError,
ImportError, AttributeError):
pass
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_load_meta_cache'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6']}; {'id': '6', 'type': 'try_statement', 'children': ['7', '53']}; {'id': '7', 'type': 'block', 'children': ['8']}; {'id': '8', 'type': 'if_statement', 'children': ['9', '14', '24']}; {'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': '_should_invalidate_cache'}; {'id': '13', 'type': 'argument_list', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15']}; {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'call', 'children': ['17', '20']}; {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'remove'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': '_cache_filename'}; {'id': '24', 'type': 'else_clause', 'children': ['25']}; {'id': '25', 'type': 'block', 'children': ['26']}; {'id': '26', 'type': 'with_statement', 'children': ['27', '39']}; {'id': '27', 'type': 'with_clause', 'children': ['28']}; {'id': '28', 'type': 'with_item', 'children': ['29']}; {'id': '29', 'type': 'as_pattern', 'children': ['30', '37']}; {'id': '30', 'type': 'call', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '32', 'type': 'argument_list', 'children': ['33', '36']}; {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': '_cache_filename'}; {'id': '36', 'type': 'string', 'children': [], 'value': "'rb'"}; {'id': '37', 'type': 'as_pattern_target', 'children': ['38']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'f'}; {'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': '_document_meta'}; {'id': '45', 'type': 'call', 'children': ['46', '51']}; {'id': '46', 'type': 'attribute', 'children': ['47', '50']}; {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'compat'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'pickle'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'load'}; {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '53', 'type': 'except_clause', 'children': ['54', '64']}; {'id': '54', 'type': 'tuple', 'children': ['55', '56', '57', '62', '63']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'OSError'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'IOError'}; {'id': '57', 'type': 'attribute', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'compat'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'pickle'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'PickleError'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'ImportError'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'AttributeError'}; {'id': '64', 'type': 'block', 'children': ['65']}; {'id': '65', 'type': 'pass_statement', 'children': []}
|
Try to load metadata from file.
|
def story_archive(request, slug, template_name='staffmembers/story_archive.html'):
member = get_object_or_404(StaffMember, slug__iexact=slug, is_active=True)
stories = []
if hasattr(member, 'story_set'):
from story.settings import PUBLISHED_STATUS
stories = member.story_set.filter(publish_date__lte=datetime.now()
).filter(status__exact=PUBLISHED_STATUS
).order_by('-publish_date')
return render_to_response(template_name,
{'member': member,
'stories': stories},
context_instance=RequestContext(request))
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'story_archive'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'slug'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'template_name'}; {'id': '8', 'type': 'string', 'children': [], 'value': "'staffmembers/story_archive.html'"}; {'id': '9', 'type': 'block', 'children': ['10', '23', '27', '69']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}; {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'member'}; {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'get_object_or_404'}; {'id': '15', 'type': 'argument_list', 'children': ['16', '17', '20']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'StaffMember'}; {'id': '17', 'type': 'keyword_argument', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'slug__iexact'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'slug'}; {'id': '20', 'type': 'keyword_argument', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'is_active'}; {'id': '22', 'type': 'True', 'children': []}; {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'stories'}; {'id': '26', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '27', 'type': 'if_statement', 'children': ['28', '33']}; {'id': '28', 'type': 'call', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'hasattr'}; {'id': '30', 'type': 'argument_list', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'member'}; {'id': '32', 'type': 'string', 'children': [], 'value': "'story_set'"}; {'id': '33', 'type': 'block', 'children': ['34', '40']}; {'id': '34', 'type': 'import_from_statement', 'children': ['35', '38']}; {'id': '35', 'type': 'dotted_name', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'story'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'settings'}; {'id': '38', 'type': 'dotted_name', 'children': ['39']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'PUBLISHED_STATUS'}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}; {'id': '41', 'type': 'assignment', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'stories'}; {'id': '43', 'type': 'call', 'children': ['44', '67']}; {'id': '44', 'type': 'attribute', 'children': ['45', '66']}; {'id': '45', 'type': 'call', 'children': ['46', '62']}; {'id': '46', 'type': 'attribute', 'children': ['47', '61']}; {'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': 'member'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'story_set'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'filter'}; {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'keyword_argument', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'publish_date__lte'}; {'id': '56', 'type': 'call', 'children': ['57', '60']}; {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'now'}; {'id': '60', 'type': 'argument_list', 'children': []}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'filter'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}; {'id': '63', 'type': 'keyword_argument', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'status__exact'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'PUBLISHED_STATUS'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'order_by'}; {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'string', 'children': [], 'value': "'-publish_date'"}; {'id': '69', 'type': 'return_statement', 'children': ['70']}; {'id': '70', 'type': 'call', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'render_to_response'}; {'id': '72', 'type': 'argument_list', 'children': ['73', '74', '81']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'template_name'}; {'id': '74', 'type': 'dictionary', 'children': ['75', '78']}; {'id': '75', 'type': 'pair', 'children': ['76', '77']}; {'id': '76', 'type': 'string', 'children': [], 'value': "'member'"}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'member'}; {'id': '78', 'type': 'pair', 'children': ['79', '80']}; {'id': '79', 'type': 'string', 'children': [], 'value': "'stories'"}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'stories'}; {'id': '81', 'type': 'keyword_argument', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'context_instance'}; {'id': '83', 'type': 'call', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'RequestContext'}; {'id': '85', 'type': 'argument_list', 'children': ['86']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'request'}
|
Return the list of stories written by this staff member
|
def accept_quality(accept, default=1):
quality = default
if accept and ";" in accept:
accept, rest = accept.split(";", 1)
accept_quality = RE_ACCEPT_QUALITY.search(rest)
if accept_quality:
quality = float(accept_quality.groupdict().get('quality', quality).strip())
return (quality, accept.strip())
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'accept_quality'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'accept'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '7', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '8', 'type': 'block', 'children': ['9', '13', '65']}; {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'quality'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '13', 'type': 'if_statement', 'children': ['14', '19']}; {'id': '14', 'type': 'boolean_operator', 'children': ['15', '16'], 'value': 'and'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'accept'}; {'id': '16', 'type': 'comparison_operator', 'children': ['17', '18'], 'value': 'in'}; {'id': '17', 'type': 'string', 'children': [], 'value': '";"'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'accept'}; {'id': '19', 'type': 'block', 'children': ['20', '32', '41']}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}; {'id': '21', 'type': 'assignment', 'children': ['22', '25']}; {'id': '22', 'type': 'pattern_list', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'accept'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'rest'}; {'id': '25', 'type': 'call', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'accept'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '29', 'type': 'argument_list', 'children': ['30', '31']}; {'id': '30', 'type': 'string', 'children': [], 'value': '";"'}; {'id': '31', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}; {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'accept_quality'}; {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'RE_ACCEPT_QUALITY'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'search'}; {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'rest'}; {'id': '41', 'type': 'if_statement', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'accept_quality'}; {'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': 'quality'}; {'id': '47', 'type': 'call', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'call', 'children': ['51', '64']}; {'id': '51', 'type': 'attribute', 'children': ['52', '63']}; {'id': '52', 'type': 'call', 'children': ['53', '60']}; {'id': '53', 'type': 'attribute', 'children': ['54', '59']}; {'id': '54', 'type': 'call', 'children': ['55', '58']}; {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'accept_quality'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'groupdict'}; {'id': '58', 'type': 'argument_list', 'children': []}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '60', 'type': 'argument_list', 'children': ['61', '62']}; {'id': '61', 'type': 'string', 'children': [], 'value': "'quality'"}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'quality'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '64', 'type': 'argument_list', 'children': []}; {'id': '65', 'type': 'return_statement', 'children': ['66']}; {'id': '66', 'type': 'tuple', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'quality'}; {'id': '68', 'type': 'call', 'children': ['69', '72']}; {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'accept'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '72', 'type': 'argument_list', 'children': []}
|
Separates out the quality score from the accepted content_type
|
def directory_files(path):
for entry in os.scandir(path):
if not entry.name.startswith('.') and entry.is_file():
yield entry.name
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'directory_files'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '5', 'type': 'block', 'children': ['6']}; {'id': '6', 'type': 'for_statement', 'children': ['7', '8', '14']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '8', 'type': 'call', 'children': ['9', '12']}; {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'scandir'}; {'id': '12', 'type': 'argument_list', 'children': ['13']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '14', 'type': 'block', 'children': ['15']}; {'id': '15', 'type': 'if_statement', 'children': ['16', '31']}; {'id': '16', 'type': 'boolean_operator', 'children': ['17', '26'], 'value': 'and'}; {'id': '17', 'type': 'not_operator', 'children': ['18']}; {'id': '18', 'type': 'call', 'children': ['19', '24']}; {'id': '19', 'type': 'attribute', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'startswith'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}; {'id': '25', 'type': 'string', 'children': [], 'value': "'.'"}; {'id': '26', 'type': 'call', 'children': ['27', '30']}; {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'is_file'}; {'id': '30', 'type': 'argument_list', 'children': []}; {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}; {'id': '33', 'type': 'yield', 'children': ['34']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'name'}
|
Yield directory file names.
|
def detect_vcs():
location = os.path.abspath('.')
while True:
for vcs in Git, Mercurial, Bazaar, Subversion:
if vcs.detect(location):
return vcs
parent = os.path.dirname(location)
if parent == location:
raise Failure("Couldn't find version control data"
" (git/hg/bzr/svn supported)")
location = parent
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '4']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'detect_vcs'}; {'id': '3', 'type': 'parameters', 'children': []}; {'id': '4', 'type': 'block', 'children': ['5', '16']}; {'id': '5', 'type': 'expression_statement', 'children': ['6']}; {'id': '6', 'type': 'assignment', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'location'}; {'id': '8', 'type': 'call', 'children': ['9', '14']}; {'id': '9', 'type': 'attribute', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'abspath'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}; {'id': '15', 'type': 'string', 'children': [], 'value': "'.'"}; {'id': '16', 'type': 'while_statement', 'children': ['17', '18']}; {'id': '17', 'type': 'True', 'children': []}; {'id': '18', 'type': 'block', 'children': ['19', '37', '48', '60']}; {'id': '19', 'type': 'for_statement', 'children': ['20', '21', '26']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'vcs'}; {'id': '21', 'type': 'expression_list', 'children': ['22', '23', '24', '25']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'Git'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'Mercurial'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'Bazaar'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'Subversion'}; {'id': '26', 'type': 'block', 'children': ['27']}; {'id': '27', 'type': 'if_statement', 'children': ['28', '34']}; {'id': '28', 'type': 'call', 'children': ['29', '32']}; {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'vcs'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'detect'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'location'}; {'id': '34', 'type': 'block', 'children': ['35']}; {'id': '35', 'type': 'return_statement', 'children': ['36']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'vcs'}; {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '40', 'type': 'call', 'children': ['41', '46']}; {'id': '41', 'type': 'attribute', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'dirname'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'location'}; {'id': '48', 'type': 'if_statement', 'children': ['49', '52']}; {'id': '49', 'type': 'comparison_operator', 'children': ['50', '51'], 'value': '=='}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'location'}; {'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': 'Failure'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}; {'id': '57', 'type': 'concatenated_string', 'children': ['58', '59']}; {'id': '58', 'type': 'string', 'children': [], 'value': '"Couldn\'t find version control data"'}; {'id': '59', 'type': 'string', 'children': [], 'value': '" (git/hg/bzr/svn supported)"'}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}; {'id': '61', 'type': 'assignment', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'location'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'parent'}
|
Detect the version control system used for the current directory.
|
def local_bifurcation_angles(neurites, neurite_type=NeuriteType.all):
return map_sections(_bifurcationfunc.local_bifurcation_angle,
neurites,
neurite_type=neurite_type,
iterator_type=Tree.ibifurcation_point)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'local_bifurcation_angles'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'neurites'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'neurite_type'}; {'id': '7', 'type': 'attribute', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'NeuriteType'}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'all'}; {'id': '10', 'type': 'block', 'children': ['11']}; {'id': '11', 'type': 'return_statement', 'children': ['12']}; {'id': '12', 'type': 'call', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'map_sections'}; {'id': '14', 'type': 'argument_list', 'children': ['15', '18', '19', '22']}; {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': '_bifurcationfunc'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'local_bifurcation_angle'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'neurites'}; {'id': '19', 'type': 'keyword_argument', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'neurite_type'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'neurite_type'}; {'id': '22', 'type': 'keyword_argument', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'iterator_type'}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'Tree'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'ibifurcation_point'}
|
Get a list of local bifurcation angles in a collection of neurites
|
def validate(self, instance, value):
if isinstance(value, datetime.datetime):
return value
if not isinstance(value, string_types):
self.error(
instance=instance,
value=value,
extra='Cannot convert non-strings to datetime.',
)
try:
return self.from_json(value)
except ValueError:
self.error(
instance=instance,
value=value,
extra='Invalid format for converting to datetime.',
)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'validate'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'instance'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '7', 'type': 'block', 'children': ['8', '19', '42']}; {'id': '8', 'type': 'if_statement', 'children': ['9', '16']}; {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '11', 'type': 'argument_list', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '16', 'type': 'block', 'children': ['17']}; {'id': '17', 'type': 'return_statement', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '19', 'type': 'if_statement', 'children': ['20', '26']}; {'id': '20', 'type': 'not_operator', 'children': ['21']}; {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '23', 'type': 'argument_list', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'string_types'}; {'id': '26', 'type': 'block', 'children': ['27']}; {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'call', 'children': ['29', '32']}; {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '32', 'type': 'argument_list', 'children': ['33', '36', '39']}; {'id': '33', 'type': 'keyword_argument', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'instance'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'instance'}; {'id': '36', 'type': 'keyword_argument', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '39', 'type': 'keyword_argument', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'extra'}; {'id': '41', 'type': 'string', 'children': [], 'value': "'Cannot convert non-strings to datetime.'"}; {'id': '42', 'type': 'try_statement', 'children': ['43', '51']}; {'id': '43', 'type': 'block', 'children': ['44']}; {'id': '44', 'type': 'return_statement', 'children': ['45']}; {'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': 'from_json'}; {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '51', 'type': 'except_clause', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '53', 'type': 'block', 'children': ['54']}; {'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': 'error'}; {'id': '59', 'type': 'argument_list', 'children': ['60', '63', '66']}; {'id': '60', 'type': 'keyword_argument', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'instance'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'instance'}; {'id': '63', 'type': 'keyword_argument', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '66', 'type': 'keyword_argument', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'extra'}; {'id': '68', 'type': 'string', 'children': [], 'value': "'Invalid format for converting to datetime.'"}
|
Check if value is a valid datetime object or JSON datetime string
|
def _SendTerminationMessage(self, status=None):
if not self.runner_args.request_state.session_id:
return
if status is None:
status = rdf_flows.GrrStatus()
client_resources = self.context.client_resources
user_cpu = client_resources.cpu_usage.user_cpu_time
sys_cpu = client_resources.cpu_usage.system_cpu_time
status.cpu_time_used.user_cpu_time = user_cpu
status.cpu_time_used.system_cpu_time = sys_cpu
status.network_bytes_sent = self.context.network_bytes_sent
status.child_session_id = self.session_id
request_state = self.runner_args.request_state
request_state.response_count += 1
msg = rdf_flows.GrrMessage(
session_id=request_state.session_id,
request_id=request_state.id,
response_id=request_state.response_count,
auth_state=rdf_flows.GrrMessage.AuthorizationState.AUTHENTICATED,
type=rdf_flows.GrrMessage.Type.STATUS,
payload=status)
self.queue_manager.QueueResponse(msg)
self.QueueNotification(session_id=request_state.session_id)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_SendTerminationMessage'}; {'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': 'status'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '20', '33', '41', '49', '57', '65', '73', '83', '91', '99', '105', '149', '158']}; {'id': '9', 'type': 'if_statement', 'children': ['10', '18']}; {'id': '10', 'type': 'not_operator', 'children': ['11']}; {'id': '11', 'type': 'attribute', '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': 'runner_args'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'request_state'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'session_id'}; {'id': '18', 'type': 'block', 'children': ['19']}; {'id': '19', 'type': 'return_statement', 'children': []}; {'id': '20', 'type': 'if_statement', 'children': ['21', '24']}; {'id': '21', 'type': 'comparison_operator', 'children': ['22', '23'], 'value': 'is'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'status'}; {'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': 'status'}; {'id': '28', 'type': 'call', 'children': ['29', '32']}; {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'rdf_flows'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'GrrStatus'}; {'id': '32', 'type': 'argument_list', 'children': []}; {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'client_resources'}; {'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': 'context'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'client_resources'}; {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'user_cpu'}; {'id': '44', 'type': 'attribute', 'children': ['45', '48']}; {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'client_resources'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'cpu_usage'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'user_cpu_time'}; {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'sys_cpu'}; {'id': '52', 'type': 'attribute', 'children': ['53', '56']}; {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'client_resources'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'cpu_usage'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'system_cpu_time'}; {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '64']}; {'id': '59', 'type': 'attribute', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'status'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'cpu_time_used'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'user_cpu_time'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'user_cpu'}; {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '72']}; {'id': '67', 'type': 'attribute', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'status'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'cpu_time_used'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'system_cpu_time'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'sys_cpu'}; {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'assignment', 'children': ['75', '78']}; {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'status'}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'network_bytes_sent'}; {'id': '78', 'type': 'attribute', 'children': ['79', '82']}; {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'context'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'network_bytes_sent'}; {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'assignment', 'children': ['85', '88']}; {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'status'}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'child_session_id'}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'session_id'}; {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'request_state'}; {'id': '94', 'type': 'attribute', 'children': ['95', '98']}; {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'runner_args'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'request_state'}; {'id': '99', 'type': 'expression_statement', 'children': ['100']}; {'id': '100', 'type': 'augmented_assignment', 'children': ['101', '104'], 'value': '+='}; {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'request_state'}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'response_count'}; {'id': '104', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'assignment', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '108', 'type': 'call', 'children': ['109', '112']}; {'id': '109', 'type': 'attribute', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'rdf_flows'}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'GrrMessage'}; {'id': '112', 'type': 'argument_list', 'children': ['113', '118', '123', '128', '137', '146']}; {'id': '113', 'type': 'keyword_argument', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'session_id'}; {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'request_state'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'session_id'}; {'id': '118', 'type': 'keyword_argument', 'children': ['119', '120']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'request_id'}; {'id': '120', 'type': 'attribute', 'children': ['121', '122']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'request_state'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '123', 'type': 'keyword_argument', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'response_id'}; {'id': '125', 'type': 'attribute', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'request_state'}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'response_count'}; {'id': '128', 'type': 'keyword_argument', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'auth_state'}; {'id': '130', 'type': 'attribute', 'children': ['131', '136']}; {'id': '131', 'type': 'attribute', 'children': ['132', '135']}; {'id': '132', 'type': 'attribute', 'children': ['133', '134']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'rdf_flows'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'GrrMessage'}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'AuthorizationState'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'AUTHENTICATED'}; {'id': '137', 'type': 'keyword_argument', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '139', 'type': 'attribute', 'children': ['140', '145']}; {'id': '140', 'type': 'attribute', 'children': ['141', '144']}; {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'rdf_flows'}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'GrrMessage'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'Type'}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'STATUS'}; {'id': '146', 'type': 'keyword_argument', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'payload'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'status'}; {'id': '149', 'type': 'expression_statement', 'children': ['150']}; {'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': 'self'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'queue_manager'}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'QueueResponse'}; {'id': '156', 'type': 'argument_list', 'children': ['157']}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '158', 'type': 'expression_statement', 'children': ['159']}; {'id': '159', 'type': 'call', 'children': ['160', '163']}; {'id': '160', 'type': 'attribute', 'children': ['161', '162']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'QueueNotification'}; {'id': '163', 'type': 'argument_list', 'children': ['164']}; {'id': '164', 'type': 'keyword_argument', 'children': ['165', '166']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'session_id'}; {'id': '166', 'type': 'attribute', 'children': ['167', '168']}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'request_state'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'session_id'}
|
This notifies the parent flow of our termination.
|
def read_kioslaverc (kde_config_dir):
data = {}
filename = os.path.join(kde_config_dir, "kioslaverc")
with open(filename) as fd:
for line in fd:
line = line.rstrip()
if line.startswith('['):
in_proxy_settings = line.startswith("[Proxy Settings]")
elif in_proxy_settings:
if '=' not in line:
continue
key, value = line.split('=', 1)
key = key.strip()
value = value.strip()
if not key:
continue
key = loc_ro.sub("", key).strip()
if not key:
continue
add_kde_setting(key, value, data)
resolve_kde_settings(data)
return data
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'read_kioslaverc'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'kde_config_dir'}; {'id': '5', 'type': 'block', 'children': ['6', '10', '22', '130', '135']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '9', 'type': 'dictionary', 'children': []}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}; {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '13', 'type': 'call', 'children': ['14', '19']}; {'id': '14', 'type': 'attribute', 'children': ['15', '18']}; {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '19', 'type': 'argument_list', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'kde_config_dir'}; {'id': '21', 'type': 'string', 'children': [], 'value': '"kioslaverc"'}; {'id': '22', 'type': 'with_statement', 'children': ['23', '32']}; {'id': '23', 'type': 'with_clause', 'children': ['24']}; {'id': '24', 'type': 'with_item', 'children': ['25']}; {'id': '25', 'type': 'as_pattern', 'children': ['26', '30']}; {'id': '26', 'type': 'call', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '30', 'type': 'as_pattern_target', 'children': ['31']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'fd'}; {'id': '32', 'type': 'block', 'children': ['33']}; {'id': '33', 'type': 'for_statement', 'children': ['34', '35', '36']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'fd'}; {'id': '36', 'type': 'block', 'children': ['37', '45']}; {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '40', 'type': 'call', 'children': ['41', '44']}; {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'rstrip'}; {'id': '44', 'type': 'argument_list', 'children': []}; {'id': '45', 'type': 'if_statement', 'children': ['46', '52', '62']}; {'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': 'startswith'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}; {'id': '51', 'type': 'string', 'children': [], 'value': "'['"}; {'id': '52', 'type': 'block', 'children': ['53']}; {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'in_proxy_settings'}; {'id': '56', 'type': 'call', 'children': ['57', '60']}; {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'startswith'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}; {'id': '61', 'type': 'string', 'children': [], 'value': '"[Proxy Settings]"'}; {'id': '62', 'type': 'elif_clause', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'in_proxy_settings'}; {'id': '64', 'type': 'block', 'children': ['65', '71', '83', '91', '99', '104', '118', '123']}; {'id': '65', 'type': 'if_statement', 'children': ['66', '69']}; {'id': '66', 'type': 'comparison_operator', 'children': ['67', '68'], 'value': 'not in'}; {'id': '67', 'type': 'string', 'children': [], 'value': "'='"}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '69', 'type': 'block', 'children': ['70']}; {'id': '70', 'type': 'continue_statement', 'children': []}; {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'assignment', 'children': ['73', '76']}; {'id': '73', 'type': 'pattern_list', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '76', 'type': 'call', 'children': ['77', '80']}; {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '80', 'type': 'argument_list', 'children': ['81', '82']}; {'id': '81', 'type': 'string', 'children': [], 'value': "'='"}; {'id': '82', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'assignment', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '86', 'type': 'call', 'children': ['87', '90']}; {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '90', 'type': 'argument_list', 'children': []}; {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '94', 'type': 'call', 'children': ['95', '98']}; {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '98', 'type': 'argument_list', 'children': []}; {'id': '99', 'type': 'if_statement', 'children': ['100', '102']}; {'id': '100', 'type': 'not_operator', 'children': ['101']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '102', 'type': 'block', 'children': ['103']}; {'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': 'key'}; {'id': '107', 'type': 'call', 'children': ['108', '117']}; {'id': '108', 'type': 'attribute', 'children': ['109', '116']}; {'id': '109', 'type': 'call', 'children': ['110', '113']}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'loc_ro'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'sub'}; {'id': '113', 'type': 'argument_list', 'children': ['114', '115']}; {'id': '114', 'type': 'string', 'children': [], 'value': '""'}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '117', 'type': 'argument_list', 'children': []}; {'id': '118', 'type': 'if_statement', 'children': ['119', '121']}; {'id': '119', 'type': 'not_operator', 'children': ['120']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '121', 'type': 'block', 'children': ['122']}; {'id': '122', 'type': 'continue_statement', 'children': []}; {'id': '123', 'type': 'expression_statement', 'children': ['124']}; {'id': '124', 'type': 'call', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'add_kde_setting'}; {'id': '126', 'type': 'argument_list', 'children': ['127', '128', '129']}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '130', 'type': 'expression_statement', 'children': ['131']}; {'id': '131', 'type': 'call', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'resolve_kde_settings'}; {'id': '133', 'type': 'argument_list', 'children': ['134']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '135', 'type': 'return_statement', 'children': ['136']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'data'}
|
Read kioslaverc into data dictionary.
|
def render_to_response(self, form, **kwargs):
page = self.get_page(form)
data = {
'iTotalRecords': page.paginator.count,
'iTotalDisplayRecords': page.paginator.count,
'sEcho': form.cleaned_data['sEcho'],
'aaData': self.get_rows(page.object_list),
}
return self.json_response(data)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'render_to_response'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'form'}; {'id': '6', 'type': 'dictionary_splat_pattern', 'children': ['7']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '8', 'type': 'block', 'children': ['9', '18', '53']}; {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'page'}; {'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': 'get_page'}; {'id': '16', 'type': 'argument_list', 'children': ['17']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'form'}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}; {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '21', 'type': 'dictionary', 'children': ['22', '29', '36', '43']}; {'id': '22', 'type': 'pair', 'children': ['23', '24']}; {'id': '23', 'type': 'string', 'children': [], 'value': "'iTotalRecords'"}; {'id': '24', 'type': 'attribute', 'children': ['25', '28']}; {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'page'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'paginator'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '29', 'type': 'pair', 'children': ['30', '31']}; {'id': '30', 'type': 'string', 'children': [], 'value': "'iTotalDisplayRecords'"}; {'id': '31', 'type': 'attribute', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'page'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'paginator'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '36', 'type': 'pair', 'children': ['37', '38']}; {'id': '37', 'type': 'string', 'children': [], 'value': "'sEcho'"}; {'id': '38', 'type': 'subscript', 'children': ['39', '42']}; {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'form'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'cleaned_data'}; {'id': '42', 'type': 'string', 'children': [], 'value': "'sEcho'"}; {'id': '43', 'type': 'pair', 'children': ['44', '45']}; {'id': '44', 'type': 'string', 'children': [], 'value': "'aaData'"}; {'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': 'get_rows'}; {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'page'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'object_list'}; {'id': '53', 'type': 'return_statement', 'children': ['54']}; {'id': '54', 'type': 'call', 'children': ['55', '58']}; {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'json_response'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'data'}
|
Render Datatables expected JSON format
|
def add_network_to_dhcp_agent(self, dhcp_agent, body=None):
return self.post((self.agent_path + self.DHCP_NETS) % dhcp_agent,
body=body)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'add_network_to_dhcp_agent'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'dhcp_agent'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'body'}; {'id': '8', 'type': 'None', 'children': []}; {'id': '9', 'type': 'block', 'children': ['10']}; {'id': '10', 'type': 'return_statement', 'children': ['11']}; {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'post'}; {'id': '15', 'type': 'argument_list', 'children': ['16', '26']}; {'id': '16', 'type': 'binary_operator', 'children': ['17', '25'], 'value': '%'}; {'id': '17', 'type': '()', 'children': ['18']}; {'id': '18', 'type': 'binary_operator', 'children': ['19', '22'], 'value': '+'}; {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'agent_path'}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'DHCP_NETS'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'dhcp_agent'}; {'id': '26', 'type': 'keyword_argument', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'body'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'body'}
|
Adds a network to dhcp agent.
|
def mean_crossings(X):
X = np.atleast_3d(X)
N = X.shape[0]
D = X.shape[2]
mnx = np.zeros((N, D))
for i in range(D):
pos = X[:, :, i] > 0
npos = ~pos
c = (pos[:, :-1] & npos[:, 1:]) | (npos[:, :-1] & pos[:, 1:])
mnx[:, i] = np.count_nonzero(c, axis=1)
return mnx
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'mean_crossings'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '5', 'type': 'block', 'children': ['6', '15', '23', '31', '42', '120']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '9', 'type': 'call', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'atleast_3d'}; {'id': '13', 'type': 'argument_list', 'children': ['14']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'N'}; {'id': '18', 'type': 'subscript', 'children': ['19', '22']}; {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '22', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'D'}; {'id': '26', 'type': 'subscript', 'children': ['27', '30']}; {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '30', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'mnx'}; {'id': '34', 'type': 'call', 'children': ['35', '38']}; {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'zeros'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}; {'id': '39', 'type': 'tuple', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'N'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'D'}; {'id': '42', 'type': 'for_statement', 'children': ['43', '44', '48']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '44', 'type': 'call', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'D'}; {'id': '48', 'type': 'block', 'children': ['49', '61', '66', '104']}; {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'pos'}; {'id': '52', 'type': 'comparison_operator', 'children': ['53', '60'], 'value': '>'}; {'id': '53', 'type': 'subscript', 'children': ['54', '55', '57', '59']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '55', 'type': 'slice', 'children': ['56']}; {'id': '56', 'type': 'colon', 'children': []}; {'id': '57', 'type': 'slice', 'children': ['58']}; {'id': '58', 'type': 'colon', 'children': []}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'i'}; {'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': 'npos'}; {'id': '64', 'type': 'unary_operator', 'children': ['65'], 'value': '~'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'pos'}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}; {'id': '67', 'type': 'assignment', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '69', 'type': 'binary_operator', 'children': ['70', '87'], 'value': '|'}; {'id': '70', 'type': '()', 'children': ['71']}; {'id': '71', 'type': 'binary_operator', 'children': ['72', '80'], 'value': '&'}; {'id': '72', 'type': 'subscript', 'children': ['73', '74', '76']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'pos'}; {'id': '74', 'type': 'slice', 'children': ['75']}; {'id': '75', 'type': 'colon', 'children': []}; {'id': '76', 'type': 'slice', 'children': ['77', '78']}; {'id': '77', 'type': 'colon', 'children': []}; {'id': '78', 'type': 'unary_operator', 'children': ['79'], 'value': '-'}; {'id': '79', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '80', 'type': 'subscript', 'children': ['81', '82', '84']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'npos'}; {'id': '82', 'type': 'slice', 'children': ['83']}; {'id': '83', 'type': 'colon', 'children': []}; {'id': '84', 'type': 'slice', 'children': ['85', '86']}; {'id': '85', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '86', 'type': 'colon', 'children': []}; {'id': '87', 'type': '()', 'children': ['88']}; {'id': '88', 'type': 'binary_operator', 'children': ['89', '97'], 'value': '&'}; {'id': '89', 'type': 'subscript', 'children': ['90', '91', '93']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'npos'}; {'id': '91', 'type': 'slice', 'children': ['92']}; {'id': '92', 'type': 'colon', 'children': []}; {'id': '93', 'type': 'slice', 'children': ['94', '95']}; {'id': '94', 'type': 'colon', 'children': []}; {'id': '95', 'type': 'unary_operator', 'children': ['96'], 'value': '-'}; {'id': '96', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '97', 'type': 'subscript', 'children': ['98', '99', '101']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'pos'}; {'id': '99', 'type': 'slice', 'children': ['100']}; {'id': '100', 'type': 'colon', 'children': []}; {'id': '101', 'type': 'slice', 'children': ['102', '103']}; {'id': '102', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '103', 'type': 'colon', 'children': []}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}; {'id': '105', 'type': 'assignment', 'children': ['106', '111']}; {'id': '106', 'type': 'subscript', 'children': ['107', '108', '110']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'mnx'}; {'id': '108', 'type': 'slice', 'children': ['109']}; {'id': '109', 'type': 'colon', 'children': []}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'i'}; {'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': 'count_nonzero'}; {'id': '115', 'type': 'argument_list', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '117', 'type': 'keyword_argument', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'axis'}; {'id': '119', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '120', 'type': 'return_statement', 'children': ['121']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'mnx'}
|
Computes number of mean crossings for each variable in a segmented time series
|
def can_execute(self):
return not self._disabled and all(dep.status == dep.node.S_OK for dep in self.deps)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'can_execute'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6']}; {'id': '6', 'type': 'return_statement', 'children': ['7']}; {'id': '7', 'type': 'boolean_operator', 'children': ['8', '12'], 'value': 'and'}; {'id': '8', 'type': 'not_operator', 'children': ['9']}; {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': '_disabled'}; {'id': '12', 'type': 'call', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'all'}; {'id': '14', 'type': 'generator_expression', 'children': ['15', '24']}; {'id': '15', 'type': 'comparison_operator', 'children': ['16', '19'], 'value': '=='}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'dep'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'status'}; {'id': '19', 'type': 'attribute', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'dep'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'S_OK'}; {'id': '24', 'type': 'for_in_clause', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'dep'}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'deps'}
|
True if we can execute the callback.
|
def path(self):
out = self.datetime.strftime("%Y-%m-%d")
out += " "
ssm = (
self.datetime - self.datetime.replace(hour=0, minute=0, second=0, microsecond=0)
).total_seconds()
out += str(int(ssm)).zfill(5)
return out
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'path'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '17', '21', '52', '67']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '9', 'type': 'call', 'children': ['10', '15']}; {'id': '10', 'type': 'attribute', 'children': ['11', '14']}; {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'strftime'}; {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'string', 'children': [], 'value': '"%Y-%m-%d"'}; {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'augmented_assignment', 'children': ['19', '20'], 'value': '+='}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '20', 'type': 'string', 'children': [], 'value': '" "'}; {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'ssm'}; {'id': '24', 'type': 'call', 'children': ['25', '51']}; {'id': '25', 'type': 'attribute', 'children': ['26', '50']}; {'id': '26', 'type': '()', 'children': ['27']}; {'id': '27', 'type': 'binary_operator', 'children': ['28', '31'], 'value': '-'}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '31', 'type': 'call', 'children': ['32', '37']}; {'id': '32', 'type': 'attribute', 'children': ['33', '36']}; {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '37', 'type': 'argument_list', 'children': ['38', '41', '44', '47']}; {'id': '38', 'type': 'keyword_argument', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'hour'}; {'id': '40', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '41', 'type': 'keyword_argument', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'minute'}; {'id': '43', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '44', 'type': 'keyword_argument', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'second'}; {'id': '46', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '47', 'type': 'keyword_argument', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'microsecond'}; {'id': '49', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'total_seconds'}; {'id': '51', 'type': 'argument_list', 'children': []}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}; {'id': '53', 'type': 'augmented_assignment', 'children': ['54', '55'], 'value': '+='}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '55', 'type': 'call', 'children': ['56', '65']}; {'id': '56', 'type': 'attribute', 'children': ['57', '64']}; {'id': '57', 'type': 'call', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '59', 'type': 'argument_list', 'children': ['60']}; {'id': '60', 'type': 'call', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'ssm'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'zfill'}; {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'integer', 'children': [], 'value': '5'}; {'id': '67', 'type': 'return_statement', 'children': ['68']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'out'}
|
Timestamp for placing into filepaths.
|
def int32(x):
if x>0xFFFFFFFF:
raise OverflowError
if x>0x7FFFFFFF:
x=int(0x100000000-x)
if x<2147483648:
return -x
else:
return -2147483648
return x
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'int32'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '5', 'type': 'block', 'children': ['6', '13', '40']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '10']}; {'id': '7', 'type': 'comparison_operator', 'children': ['8', '9'], 'value': '>'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '9', 'type': 'integer', 'children': [], 'value': '0xFFFFFFFF'}; {'id': '10', 'type': 'block', 'children': ['11']}; {'id': '11', 'type': 'raise_statement', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'OverflowError'}; {'id': '13', 'type': 'if_statement', 'children': ['14', '17']}; {'id': '14', 'type': 'comparison_operator', 'children': ['15', '16'], 'value': '>'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '16', 'type': 'integer', 'children': [], 'value': '0x7FFFFFFF'}; {'id': '17', 'type': 'block', 'children': ['18', '27']}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}; {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'binary_operator', 'children': ['25', '26'], 'value': '-'}; {'id': '25', 'type': 'integer', 'children': [], 'value': '0x100000000'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '27', 'type': 'if_statement', 'children': ['28', '31', '35']}; {'id': '28', 'type': 'comparison_operator', 'children': ['29', '30'], 'value': '<'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '30', 'type': 'integer', 'children': [], 'value': '2147483648'}; {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'return_statement', 'children': ['33']}; {'id': '33', 'type': 'unary_operator', 'children': ['34'], 'value': '-'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '35', 'type': 'else_clause', 'children': ['36']}; {'id': '36', 'type': 'block', 'children': ['37']}; {'id': '37', 'type': 'return_statement', 'children': ['38']}; {'id': '38', 'type': 'unary_operator', 'children': ['39'], 'value': '-'}; {'id': '39', 'type': 'integer', 'children': [], 'value': '2147483648'}; {'id': '40', 'type': 'return_statement', 'children': ['41']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'x'}
|
Return a signed or unsigned int
|
def clean_slug(self):
source = self.cleaned_data.get('slug', '')
lang_choice = self.language_code
if not source:
source = slugify(self.cleaned_data.get('title', ''))
qs = Post._default_manager.active_translations(lang_choice).language(lang_choice)
used = list(qs.values_list('translations__slug', flat=True))
slug = source
i = 1
while slug in used:
slug = '%s-%s' % (source, i)
i += 1
return slug
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'clean_slug'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '18', '24', '43', '59', '74', '78', '82', '99']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'source'}; {'id': '9', 'type': 'call', 'children': ['10', '15']}; {'id': '10', 'type': 'attribute', 'children': ['11', '14']}; {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'cleaned_data'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '15', 'type': 'argument_list', 'children': ['16', '17']}; {'id': '16', 'type': 'string', 'children': [], 'value': "'slug'"}; {'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': 'lang_choice'}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'language_code'}; {'id': '24', 'type': 'if_statement', 'children': ['25', '27']}; {'id': '25', 'type': 'not_operator', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'source'}; {'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': 'source'}; {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'slugify'}; {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'call', 'children': ['35', '40']}; {'id': '35', 'type': 'attribute', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'cleaned_data'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '40', 'type': 'argument_list', 'children': ['41', '42']}; {'id': '41', 'type': 'string', 'children': [], 'value': "'title'"}; {'id': '42', 'type': 'string', 'children': [], 'value': "''"}; {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'qs'}; {'id': '46', 'type': 'call', 'children': ['47', '57']}; {'id': '47', 'type': 'attribute', 'children': ['48', '56']}; {'id': '48', 'type': 'call', 'children': ['49', '54']}; {'id': '49', 'type': 'attribute', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'Post'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': '_default_manager'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'active_translations'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'lang_choice'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'language'}; {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'lang_choice'}; {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'assignment', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'used'}; {'id': '62', 'type': 'call', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}; {'id': '65', 'type': 'call', 'children': ['66', '69']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'qs'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'values_list'}; {'id': '69', 'type': 'argument_list', 'children': ['70', '71']}; {'id': '70', 'type': 'string', 'children': [], 'value': "'translations__slug'"}; {'id': '71', 'type': 'keyword_argument', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'flat'}; {'id': '73', 'type': 'True', 'children': []}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}; {'id': '75', 'type': 'assignment', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'slug'}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'source'}; {'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', '86']}; {'id': '83', 'type': 'comparison_operator', 'children': ['84', '85'], 'value': 'in'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'slug'}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'used'}; {'id': '86', 'type': 'block', 'children': ['87', '95']}; {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'assignment', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'slug'}; {'id': '90', 'type': 'binary_operator', 'children': ['91', '92'], 'value': '%'}; {'id': '91', 'type': 'string', 'children': [], 'value': "'%s-%s'"}; {'id': '92', 'type': 'tuple', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'source'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'augmented_assignment', 'children': ['97', '98'], 'value': '+='}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '98', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '99', 'type': 'return_statement', 'children': ['100']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'slug'}
|
Generate a valid slug, in case the given one is taken
|
def split_vcf(in_file, ref_file, config, out_dir=None):
if out_dir is None:
out_dir = os.path.join(os.path.dirname(in_file), "split")
out_files = []
with open(ref.fasta_idx(ref_file, config)) as in_handle:
for line in in_handle:
chrom, size = line.split()[:2]
out_file = os.path.join(out_dir,
os.path.basename(replace_suffix(append_stem(in_file, "-%s" % chrom), ".vcf")))
subset_vcf(in_file, (chrom, 0, size), out_file, config)
out_files.append(out_file)
return out_files
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'split_vcf'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'in_file'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'ref_file'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'out_dir'}; {'id': '9', 'type': 'None', 'children': []}; {'id': '10', 'type': 'block', 'children': ['11', '35', '39', '121']}; {'id': '11', 'type': 'if_statement', 'children': ['12', '15']}; {'id': '12', 'type': 'comparison_operator', 'children': ['13', '14'], 'value': 'is'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'out_dir'}; {'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': 'out_dir'}; {'id': '19', 'type': 'call', 'children': ['20', '25']}; {'id': '20', 'type': 'attribute', 'children': ['21', '24']}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '25', 'type': 'argument_list', 'children': ['26', '34']}; {'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': 'os'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'dirname'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'in_file'}; {'id': '34', 'type': 'string', 'children': [], 'value': '"split"'}; {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'out_files'}; {'id': '38', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '39', 'type': 'with_statement', 'children': ['40', '55']}; {'id': '40', 'type': 'with_clause', 'children': ['41']}; {'id': '41', 'type': 'with_item', 'children': ['42']}; {'id': '42', 'type': 'as_pattern', 'children': ['43', '53']}; {'id': '43', 'type': 'call', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'call', 'children': ['47', '50']}; {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'ref'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'fasta_idx'}; {'id': '50', 'type': 'argument_list', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'ref_file'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '53', 'type': 'as_pattern_target', 'children': ['54']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'in_handle'}; {'id': '55', 'type': 'block', 'children': ['56']}; {'id': '56', 'type': 'for_statement', 'children': ['57', '58', '59']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'in_handle'}; {'id': '59', 'type': 'block', 'children': ['60', '74', '103', '114']}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}; {'id': '61', 'type': 'assignment', 'children': ['62', '65']}; {'id': '62', 'type': 'pattern_list', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'chrom'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'size'}; {'id': '65', 'type': 'subscript', 'children': ['66', '71']}; {'id': '66', 'type': 'call', 'children': ['67', '70']}; {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '70', 'type': 'argument_list', 'children': []}; {'id': '71', 'type': 'slice', 'children': ['72', '73']}; {'id': '72', 'type': 'colon', 'children': []}; {'id': '73', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}; {'id': '75', 'type': 'assignment', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'out_file'}; {'id': '77', 'type': 'call', 'children': ['78', '83']}; {'id': '78', 'type': 'attribute', 'children': ['79', '82']}; {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '83', 'type': 'argument_list', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'out_dir'}; {'id': '85', 'type': 'call', 'children': ['86', '91']}; {'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': 'basename'}; {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'call', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'replace_suffix'}; {'id': '94', 'type': 'argument_list', 'children': ['95', '102']}; {'id': '95', 'type': 'call', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'append_stem'}; {'id': '97', 'type': 'argument_list', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'in_file'}; {'id': '99', 'type': 'binary_operator', 'children': ['100', '101'], 'value': '%'}; {'id': '100', 'type': 'string', 'children': [], 'value': '"-%s"'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'chrom'}; {'id': '102', 'type': 'string', 'children': [], 'value': '".vcf"'}; {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'call', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'subset_vcf'}; {'id': '106', 'type': 'argument_list', 'children': ['107', '108', '112', '113']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'in_file'}; {'id': '108', 'type': 'tuple', 'children': ['109', '110', '111']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'chrom'}; {'id': '110', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'size'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'out_file'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}; {'id': '115', 'type': 'call', 'children': ['116', '119']}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'out_files'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '119', 'type': 'argument_list', 'children': ['120']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'out_file'}; {'id': '121', 'type': 'return_statement', 'children': ['122']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'out_files'}
|
Split a VCF file into separate files by chromosome.
|
def next_tzolkin_haab(tzolkin, haab, jd):
haabcount = _haab_count(*to_haab(jd))
haab_desired_count = _haab_count(*haab)
haab_days = (haab_desired_count - haabcount) % 365
possible_haab = set(h + haab_days for h in range(0, 18980, 365))
tzcount = _tzolkin_count(*to_tzolkin(jd))
tz_desired_count = _tzolkin_count(*tzolkin)
tzolkin_days = (tz_desired_count - tzcount) % 260
possible_tz = set(t + tzolkin_days for t in range(0, 18980, 260))
try:
return possible_tz.intersection(possible_haab).pop() + jd
except KeyError:
raise IndexError("That Haab'-Tzolk'in combination isn't possible")
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'next_tzolkin_haab'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'tzolkin'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'haab'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'jd'}; {'id': '7', 'type': 'block', 'children': ['8', '19', '27', '36', '53', '64', '72', '81', '98']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'haabcount'}; {'id': '11', 'type': 'call', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': '_haab_count'}; {'id': '13', 'type': 'argument_list', 'children': ['14']}; {'id': '14', 'type': 'list_splat', 'children': ['15']}; {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'to_haab'}; {'id': '17', 'type': 'argument_list', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'jd'}; {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'haab_desired_count'}; {'id': '22', 'type': 'call', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': '_haab_count'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}; {'id': '25', 'type': 'list_splat', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'haab'}; {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'haab_days'}; {'id': '30', 'type': 'binary_operator', 'children': ['31', '35'], 'value': '%'}; {'id': '31', 'type': '()', 'children': ['32']}; {'id': '32', 'type': 'binary_operator', 'children': ['33', '34'], 'value': '-'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'haab_desired_count'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'haabcount'}; {'id': '35', 'type': 'integer', 'children': [], 'value': '365'}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}; {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'possible_haab'}; {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '41', 'type': 'generator_expression', 'children': ['42', '45']}; {'id': '42', 'type': 'binary_operator', 'children': ['43', '44'], 'value': '+'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'h'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'haab_days'}; {'id': '45', 'type': 'for_in_clause', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'h'}; {'id': '47', 'type': 'call', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '49', 'type': 'argument_list', 'children': ['50', '51', '52']}; {'id': '50', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '51', 'type': 'integer', 'children': [], 'value': '18980'}; {'id': '52', 'type': 'integer', 'children': [], 'value': '365'}; {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'tzcount'}; {'id': '56', 'type': 'call', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': '_tzolkin_count'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}; {'id': '59', 'type': 'list_splat', 'children': ['60']}; {'id': '60', 'type': 'call', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'to_tzolkin'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'jd'}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}; {'id': '65', 'type': 'assignment', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'tz_desired_count'}; {'id': '67', 'type': 'call', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': '_tzolkin_count'}; {'id': '69', 'type': 'argument_list', 'children': ['70']}; {'id': '70', 'type': 'list_splat', 'children': ['71']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'tzolkin'}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}; {'id': '73', 'type': 'assignment', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'tzolkin_days'}; {'id': '75', 'type': 'binary_operator', 'children': ['76', '80'], 'value': '%'}; {'id': '76', 'type': '()', 'children': ['77']}; {'id': '77', 'type': 'binary_operator', 'children': ['78', '79'], 'value': '-'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'tz_desired_count'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'tzcount'}; {'id': '80', 'type': 'integer', 'children': [], 'value': '260'}; {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'assignment', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'possible_tz'}; {'id': '84', 'type': 'call', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '86', 'type': 'generator_expression', 'children': ['87', '90']}; {'id': '87', 'type': 'binary_operator', 'children': ['88', '89'], 'value': '+'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'tzolkin_days'}; {'id': '90', 'type': 'for_in_clause', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '92', 'type': 'call', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '94', 'type': 'argument_list', 'children': ['95', '96', '97']}; {'id': '95', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '96', 'type': 'integer', 'children': [], 'value': '18980'}; {'id': '97', 'type': 'integer', 'children': [], 'value': '260'}; {'id': '98', 'type': 'try_statement', 'children': ['99', '113']}; {'id': '99', 'type': 'block', 'children': ['100']}; {'id': '100', 'type': 'return_statement', 'children': ['101']}; {'id': '101', 'type': 'binary_operator', 'children': ['102', '112'], 'value': '+'}; {'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': 'possible_tz'}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'intersection'}; {'id': '108', 'type': 'argument_list', 'children': ['109']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'possible_haab'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '111', 'type': 'argument_list', 'children': []}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'jd'}; {'id': '113', 'type': 'except_clause', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'KeyError'}; {'id': '115', 'type': 'block', 'children': ['116']}; {'id': '116', 'type': 'raise_statement', 'children': ['117']}; {'id': '117', 'type': 'call', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'IndexError'}; {'id': '119', 'type': 'argument_list', 'children': ['120']}; {'id': '120', 'type': 'string', 'children': [], 'value': '"That Haab\'-Tzolk\'in combination isn\'t possible"'}
|
For a given haab-tzolk'in combination, and a Julian day count, find the next occurrance of the combination after the date
|
def calcTm(seq, mv_conc=50, dv_conc=0, dntp_conc=0.8, dna_conc=50,
max_nn_length=60, tm_method='santalucia',
salt_corrections_method='santalucia'):
tm_meth = _tm_methods.get(tm_method)
if tm_meth is None:
raise ValueError('{} is not a valid tm calculation method'.format(
tm_method))
salt_meth = _salt_corrections_methods.get(salt_corrections_method)
if salt_meth is None:
raise ValueError('{} is not a valid salt correction method'.format(
salt_corrections_method))
args = [pjoin(PRIMER3_HOME, 'oligotm'),
'-mv', str(mv_conc),
'-dv', str(dv_conc),
'-n', str(dntp_conc),
'-d', str(dna_conc),
'-tp', str(tm_meth),
'-sc', str(salt_meth),
seq]
tm = subprocess.check_output(args, stderr=DEV_NULL,
env=os.environ)
return float(tm)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '26']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'calcTm'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'mv_conc'}; {'id': '7', 'type': 'integer', 'children': [], 'value': '50'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'dv_conc'}; {'id': '10', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'dntp_conc'}; {'id': '13', 'type': 'float', 'children': [], 'value': '0.8'}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'dna_conc'}; {'id': '16', 'type': 'integer', 'children': [], 'value': '50'}; {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'max_nn_length'}; {'id': '19', 'type': 'integer', 'children': [], 'value': '60'}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'tm_method'}; {'id': '22', 'type': 'string', 'children': [], 'value': "'santalucia'"}; {'id': '23', 'type': 'default_parameter', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'salt_corrections_method'}; {'id': '25', 'type': 'string', 'children': [], 'value': "'santalucia'"}; {'id': '26', 'type': 'block', 'children': ['27', '36', '51', '60', '75', '115', '132']}; {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'tm_meth'}; {'id': '30', 'type': 'call', 'children': ['31', '34']}; {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': '_tm_methods'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'tm_method'}; {'id': '36', 'type': 'if_statement', 'children': ['37', '40']}; {'id': '37', 'type': 'comparison_operator', 'children': ['38', '39'], 'value': 'is'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'tm_meth'}; {'id': '39', 'type': 'None', 'children': []}; {'id': '40', 'type': 'block', 'children': ['41']}; {'id': '41', 'type': 'raise_statement', 'children': ['42']}; {'id': '42', 'type': 'call', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}; {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}; {'id': '47', 'type': 'string', 'children': [], 'value': "'{} is not a valid tm calculation method'"}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'tm_method'}; {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'salt_meth'}; {'id': '54', 'type': 'call', 'children': ['55', '58']}; {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': '_salt_corrections_methods'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'salt_corrections_method'}; {'id': '60', 'type': 'if_statement', 'children': ['61', '64']}; {'id': '61', 'type': 'comparison_operator', 'children': ['62', '63'], 'value': 'is'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'salt_meth'}; {'id': '63', 'type': 'None', 'children': []}; {'id': '64', 'type': 'block', 'children': ['65']}; {'id': '65', 'type': 'raise_statement', 'children': ['66']}; {'id': '66', 'type': 'call', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}; {'id': '69', 'type': 'call', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}; {'id': '71', 'type': 'string', 'children': [], 'value': "'{} is not a valid salt correction method'"}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'salt_corrections_method'}; {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '78', 'type': 'list', 'children': ['79', '84', '85', '89', '90', '94', '95', '99', '100', '104', '105', '109', '110', '114'], 'value': "[pjoin(PRIMER3_HOME, 'oligotm'),\n '-mv', str(mv_conc),\n '-dv', str(dv_conc),\n '-n', str(dntp_conc),\n '-d', str(dna_conc),\n '-tp', str(tm_meth),\n '-sc', str(salt_meth),\n seq]"}; {'id': '79', 'type': 'call', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'pjoin'}; {'id': '81', 'type': 'argument_list', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'PRIMER3_HOME'}; {'id': '83', 'type': 'string', 'children': [], 'value': "'oligotm'"}; {'id': '84', 'type': 'string', 'children': [], 'value': "'-mv'"}; {'id': '85', 'type': 'call', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '87', 'type': 'argument_list', 'children': ['88']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'mv_conc'}; {'id': '89', 'type': 'string', 'children': [], 'value': "'-dv'"}; {'id': '90', 'type': 'call', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '92', 'type': 'argument_list', 'children': ['93']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'dv_conc'}; {'id': '94', 'type': 'string', 'children': [], 'value': "'-n'"}; {'id': '95', 'type': 'call', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '97', 'type': 'argument_list', 'children': ['98']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'dntp_conc'}; {'id': '99', 'type': 'string', 'children': [], 'value': "'-d'"}; {'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': 'dna_conc'}; {'id': '104', 'type': 'string', 'children': [], 'value': "'-tp'"}; {'id': '105', 'type': 'call', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '107', 'type': 'argument_list', 'children': ['108']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'tm_meth'}; {'id': '109', 'type': 'string', 'children': [], 'value': "'-sc'"}; {'id': '110', 'type': 'call', 'children': ['111', '112']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '112', 'type': 'argument_list', 'children': ['113']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'salt_meth'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'assignment', 'children': ['117', '118']}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'tm'}; {'id': '118', 'type': 'call', 'children': ['119', '122']}; {'id': '119', 'type': 'attribute', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'subprocess'}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'check_output'}; {'id': '122', 'type': 'argument_list', 'children': ['123', '124', '127']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '124', 'type': 'keyword_argument', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'stderr'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'DEV_NULL'}; {'id': '127', 'type': 'keyword_argument', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'env'}; {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'environ'}; {'id': '132', 'type': 'return_statement', 'children': ['133']}; {'id': '133', 'type': 'call', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '135', 'type': 'argument_list', 'children': ['136']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'tm'}
|
Return the tm of `seq` as a float.
|
def authorize(self):
with salt.utils.files.fopen(self.path, 'w+') as fp_:
fp_.write(str(int(time.time())))
return True
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'authorize'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '43']}; {'id': '6', 'type': 'with_statement', 'children': ['7', '25']}; {'id': '7', 'type': 'with_clause', 'children': ['8']}; {'id': '8', 'type': 'with_item', 'children': ['9']}; {'id': '9', 'type': 'as_pattern', 'children': ['10', '23']}; {'id': '10', 'type': 'call', 'children': ['11', '18']}; {'id': '11', 'type': 'attribute', 'children': ['12', '17']}; {'id': '12', 'type': 'attribute', 'children': ['13', '16']}; {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'salt'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'files'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'fopen'}; {'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': 'path'}; {'id': '22', 'type': 'string', 'children': [], 'value': "'w+'"}; {'id': '23', 'type': 'as_pattern_target', 'children': ['24']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'fp_'}; {'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': 'fp_'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'call', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}; {'id': '35', 'type': 'call', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'call', 'children': ['39', '42']}; {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '42', 'type': 'argument_list', 'children': []}; {'id': '43', 'type': 'return_statement', 'children': ['44']}; {'id': '44', 'type': 'True', 'children': []}
|
Prepare the master to expect a signing request
|
def prompt_terminal(path):
def rlinput(prompt_msg, prefill=''):
import readline
readline.set_startup_hook(lambda: readline.insert_text(prefill))
try:
return input(prompt_msg)
finally:
readline.set_startup_hook()
filepath, extension = os.path.splitext(path)
basename = os.path.basename(filepath)
dirname = os.path.dirname(filepath)
new_basename = rlinput('Filename: ', basename)
while os.path.exists(os.path.join(dirname, new_basename + extension)) and \
new_basename != basename:
new_basename = rlinput('Sorry, please try again... Filename: ',
basename)
if new_basename == '':
new_basename = basename
return os.path.join(dirname, new_basename + extension)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'prompt_terminal'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '5', 'type': 'block', 'children': ['6', '45', '58', '69', '80', '88', '121', '130']}; {'id': '6', 'type': 'function_definition', 'children': ['7', '8', '13']}; {'id': '7', 'type': 'function_name', 'children': [], 'value': 'rlinput'}; {'id': '8', 'type': 'parameters', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'prompt_msg'}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'prefill'}; {'id': '12', 'type': 'string', 'children': [], 'value': "''"}; {'id': '13', 'type': 'block', 'children': ['14', '17', '30']}; {'id': '14', 'type': 'import_statement', 'children': ['15']}; {'id': '15', 'type': 'dotted_name', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'readline'}; {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'call', 'children': ['19', '22']}; {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'readline'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'set_startup_hook'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}; {'id': '23', 'type': 'lambda', 'children': ['24']}; {'id': '24', 'type': 'call', 'children': ['25', '28']}; {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'readline'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'insert_text'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'prefill'}; {'id': '30', 'type': 'try_statement', 'children': ['31', '37']}; {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'return_statement', 'children': ['33']}; {'id': '33', 'type': 'call', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'input'}; {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'prompt_msg'}; {'id': '37', 'type': 'finally_clause', 'children': ['38']}; {'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': 'readline'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'set_startup_hook'}; {'id': '44', 'type': 'argument_list', 'children': []}; {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '50']}; {'id': '47', 'type': 'pattern_list', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'filepath'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'extension'}; {'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': 'os'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'splitext'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}; {'id': '59', 'type': 'assignment', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'basename'}; {'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': 'os'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'basename'}; {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'filepath'}; {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'dirname'}; {'id': '72', 'type': 'call', 'children': ['73', '78']}; {'id': '73', 'type': 'attribute', 'children': ['74', '77']}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'dirname'}; {'id': '78', 'type': 'argument_list', 'children': ['79']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'filepath'}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}; {'id': '81', 'type': 'assignment', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'new_basename'}; {'id': '83', 'type': 'call', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'rlinput'}; {'id': '85', 'type': 'argument_list', 'children': ['86', '87']}; {'id': '86', 'type': 'string', 'children': [], 'value': "'Filename: '"}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'basename'}; {'id': '88', 'type': 'while_statement', 'children': ['89', '112']}; {'id': '89', 'type': 'boolean_operator', 'children': ['90', '108', '109'], 'value': 'and'}; {'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': 'os'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'exists'}; {'id': '96', 'type': 'argument_list', 'children': ['97']}; {'id': '97', 'type': 'call', 'children': ['98', '103']}; {'id': '98', 'type': 'attribute', 'children': ['99', '102']}; {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '103', 'type': 'argument_list', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'dirname'}; {'id': '105', 'type': 'binary_operator', 'children': ['106', '107'], 'value': '+'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'new_basename'}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'extension'}; {'id': '108', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '109', 'type': 'comparison_operator', 'children': ['110', '111'], 'value': '!='}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'new_basename'}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'basename'}; {'id': '112', 'type': 'block', 'children': ['113']}; {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'assignment', 'children': ['115', '116']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'new_basename'}; {'id': '116', 'type': 'call', 'children': ['117', '118']}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'rlinput'}; {'id': '118', 'type': 'argument_list', 'children': ['119', '120']}; {'id': '119', 'type': 'string', 'children': [], 'value': "'Sorry, please try again... Filename: '"}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'basename'}; {'id': '121', 'type': 'if_statement', 'children': ['122', '125']}; {'id': '122', 'type': 'comparison_operator', 'children': ['123', '124'], 'value': '=='}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'new_basename'}; {'id': '124', 'type': 'string', 'children': [], 'value': "''"}; {'id': '125', 'type': 'block', 'children': ['126']}; {'id': '126', 'type': 'expression_statement', 'children': ['127']}; {'id': '127', 'type': 'assignment', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'new_basename'}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'basename'}; {'id': '130', 'type': 'return_statement', 'children': ['131']}; {'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': 'os'}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '137', 'type': 'argument_list', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'dirname'}; {'id': '139', 'type': 'binary_operator', 'children': ['140', '141'], 'value': '+'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'new_basename'}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'extension'}
|
Prompt for a new filename via terminal.
|
def _int_size_to_type(size):
if size <= 8:
return ByteType
if size <= 16:
return ShortType
if size <= 32:
return IntegerType
if size <= 64:
return LongType
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_int_size_to_type'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'size'}; {'id': '5', 'type': 'block', 'children': ['6', '13', '20', '27']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '10']}; {'id': '7', 'type': 'comparison_operator', 'children': ['8', '9'], 'value': '<='}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'size'}; {'id': '9', 'type': 'integer', 'children': [], 'value': '8'}; {'id': '10', 'type': 'block', 'children': ['11']}; {'id': '11', 'type': 'return_statement', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'ByteType'}; {'id': '13', 'type': 'if_statement', 'children': ['14', '17']}; {'id': '14', 'type': 'comparison_operator', 'children': ['15', '16'], 'value': '<='}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'size'}; {'id': '16', 'type': 'integer', 'children': [], 'value': '16'}; {'id': '17', 'type': 'block', 'children': ['18']}; {'id': '18', 'type': 'return_statement', 'children': ['19']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'ShortType'}; {'id': '20', 'type': 'if_statement', 'children': ['21', '24']}; {'id': '21', 'type': 'comparison_operator', 'children': ['22', '23'], 'value': '<='}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'size'}; {'id': '23', 'type': 'integer', 'children': [], 'value': '32'}; {'id': '24', 'type': 'block', 'children': ['25']}; {'id': '25', 'type': 'return_statement', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'IntegerType'}; {'id': '27', 'type': 'if_statement', 'children': ['28', '31']}; {'id': '28', 'type': 'comparison_operator', 'children': ['29', '30'], 'value': '<='}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'size'}; {'id': '30', 'type': 'integer', 'children': [], 'value': '64'}; {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'return_statement', 'children': ['33']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'LongType'}
|
Return the Catalyst datatype from the size of integers.
|
def create_workspace(self) -> None:
def create_clicked(text):
if text:
command = Workspace.CreateWorkspaceCommand(self, text)
command.perform()
self.document_controller.push_undo_command(command)
self.pose_get_string_message_box(caption=_("Enter a name for the workspace"), text=_("Workspace"),
accepted_fn=create_clicked, accepted_text=_("Create"),
message_box_id="create_workspace")
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'create_workspace'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'type', 'children': ['6']}; {'id': '6', 'type': 'None', 'children': []}; {'id': '7', 'type': 'block', 'children': ['8', '41']}; {'id': '8', 'type': 'function_definition', 'children': ['9', '10', '12']}; {'id': '9', 'type': 'function_name', 'children': [], 'value': 'create_clicked'}; {'id': '10', 'type': 'parameters', 'children': ['11']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '12', 'type': 'block', 'children': ['13']}; {'id': '13', 'type': 'if_statement', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '15', 'type': 'block', 'children': ['16', '26', '32']}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}; {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'command'}; {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'Workspace'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'CreateWorkspaceCommand'}; {'id': '23', 'type': 'argument_list', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'text'}; {'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': 'command'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'perform'}; {'id': '31', 'type': 'argument_list', 'children': []}; {'id': '32', 'type': 'expression_statement', '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': 'document_controller'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'push_undo_command'}; {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'command'}; {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'call', 'children': ['43', '46']}; {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'pose_get_string_message_box'}; {'id': '46', 'type': 'argument_list', 'children': ['47', '53', '59', '62', '68']}; {'id': '47', 'type': 'keyword_argument', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'caption'}; {'id': '49', 'type': 'call', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'string', 'children': [], 'value': '"Enter a name for the workspace"'}; {'id': '53', 'type': 'keyword_argument', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '55', 'type': 'call', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'string', 'children': [], 'value': '"Workspace"'}; {'id': '59', 'type': 'keyword_argument', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'accepted_fn'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'create_clicked'}; {'id': '62', 'type': 'keyword_argument', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'accepted_text'}; {'id': '64', 'type': 'call', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '66', 'type': 'argument_list', 'children': ['67']}; {'id': '67', 'type': 'string', 'children': [], 'value': '"Create"'}; {'id': '68', 'type': 'keyword_argument', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'message_box_id'}; {'id': '70', 'type': 'string', 'children': [], 'value': '"create_workspace"'}
|
Pose a dialog to name and create a workspace.
|
def print_result_from_timeit(stmt='pass', setup='pass', number=1000000):
units = ["s", "ms", "us", "ns"]
duration = timeit(stmt, setup, number=int(number))
avg_duration = duration / float(number)
thousands = int(math.floor(math.log(avg_duration, 1000)))
print("Total time: %fs. Average run: %.3f%s." % (
duration, avg_duration * (1000 ** -thousands), units[-thousands]))
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'print_result_from_timeit'}; {'id': '3', 'type': 'parameters', 'children': ['4', '7', '10']}; {'id': '4', 'type': 'default_parameter', 'children': ['5', '6']}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '6', 'type': 'string', 'children': [], 'value': "'pass'"}; {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'setup'}; {'id': '9', 'type': 'string', 'children': [], 'value': "'pass'"}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'number'}; {'id': '12', 'type': 'integer', 'children': [], 'value': '1000000'}; {'id': '13', 'type': 'block', 'children': ['14', '22', '36', '45', '63']}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}; {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'units'}; {'id': '17', 'type': 'list', 'children': ['18', '19', '20', '21'], 'value': '["s", "ms", "us", "ns"]'}; {'id': '18', 'type': 'string', 'children': [], 'value': '"s"'}; {'id': '19', 'type': 'string', 'children': [], 'value': '"ms"'}; {'id': '20', 'type': 'string', 'children': [], 'value': '"us"'}; {'id': '21', 'type': 'string', 'children': [], 'value': '"ns"'}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}; {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'duration'}; {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'timeit'}; {'id': '27', 'type': 'argument_list', 'children': ['28', '29', '30']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'setup'}; {'id': '30', 'type': 'keyword_argument', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'number'}; {'id': '32', 'type': 'call', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'number'}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}; {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'avg_duration'}; {'id': '39', 'type': 'binary_operator', 'children': ['40', '41'], 'value': '/'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'duration'}; {'id': '41', 'type': 'call', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'number'}; {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'thousands'}; {'id': '48', 'type': 'call', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}; {'id': '51', 'type': 'call', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'math'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'floor'}; {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'call', 'children': ['57', '60']}; {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'math'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'log'}; {'id': '60', 'type': 'argument_list', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'avg_duration'}; {'id': '62', 'type': 'integer', 'children': [], 'value': '1000'}; {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'call', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '66', 'type': 'argument_list', 'children': ['67']}; {'id': '67', 'type': 'binary_operator', 'children': ['68', '69'], 'value': '%'}; {'id': '68', 'type': 'string', 'children': [], 'value': '"Total time: %fs. Average run: %.3f%s."'}; {'id': '69', 'type': 'tuple', 'children': ['70', '71', '78']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'duration'}; {'id': '71', 'type': 'binary_operator', 'children': ['72', '73'], 'value': '*'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'avg_duration'}; {'id': '73', 'type': '()', 'children': ['74']}; {'id': '74', 'type': 'binary_operator', 'children': ['75', '76'], 'value': '**'}; {'id': '75', 'type': 'integer', 'children': [], 'value': '1000'}; {'id': '76', 'type': 'unary_operator', 'children': ['77'], 'value': '-'}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'thousands'}; {'id': '78', 'type': 'subscript', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'units'}; {'id': '80', 'type': 'unary_operator', 'children': ['81'], 'value': '-'}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'thousands'}
|
Clean function to know how much time took the execution of one statement
|
def setup_logfile_raw(self, logfile, mode='w'):
self.logfile_raw = open(logfile, mode=mode)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'setup_logfile_raw'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'logfile'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '8', 'type': 'string', 'children': [], 'value': "'w'"}; {'id': '9', 'type': 'block', 'children': ['10']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}; {'id': '11', 'type': 'assignment', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'logfile_raw'}; {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '17', 'type': 'argument_list', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'logfile'}; {'id': '19', 'type': 'keyword_argument', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'mode'}
|
start logging raw bytes to the given logfile, without timestamps
|
def salt_api():
import salt.utils.process
salt.utils.process.notify_systemd()
import salt.cli.api
sapi = salt.cli.api.SaltAPI()
sapi.start()
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '4']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'salt_api'}; {'id': '3', 'type': 'parameters', 'children': []}; {'id': '4', 'type': 'block', 'children': ['5', '10', '20', '25', '37']}; {'id': '5', 'type': 'import_statement', 'children': ['6']}; {'id': '6', 'type': 'dotted_name', 'children': ['7', '8', '9']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'salt'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'process'}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}; {'id': '11', 'type': 'call', 'children': ['12', '19']}; {'id': '12', 'type': 'attribute', 'children': ['13', '18']}; {'id': '13', 'type': 'attribute', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'salt'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'process'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'notify_systemd'}; {'id': '19', 'type': 'argument_list', 'children': []}; {'id': '20', 'type': 'import_statement', 'children': ['21']}; {'id': '21', 'type': 'dotted_name', 'children': ['22', '23', '24']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'salt'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'cli'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'api'}; {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'sapi'}; {'id': '28', 'type': 'call', 'children': ['29', '36']}; {'id': '29', 'type': 'attribute', 'children': ['30', '35']}; {'id': '30', 'type': 'attribute', 'children': ['31', '34']}; {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'salt'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'cli'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'api'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'SaltAPI'}; {'id': '36', 'type': 'argument_list', 'children': []}; {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'call', 'children': ['39', '42']}; {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'sapi'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '42', 'type': 'argument_list', 'children': []}
|
The main function for salt-api
|
def params(self):
if self._GETPOST is None:
self._GETPOST = MultiDict(self.GET)
self._GETPOST.update(dict(self.POST))
return self._GETPOST
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'params'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '38']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '12']}; {'id': '7', 'type': 'comparison_operator', 'children': ['8', '11'], 'value': 'is'}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': '_GETPOST'}; {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'block', 'children': ['13', '24']}; {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '18']}; {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': '_GETPOST'}; {'id': '18', 'type': 'call', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'MultiDict'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'GET'}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}; {'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': '_GETPOST'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'call', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}; {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'POST'}; {'id': '38', 'type': 'return_statement', 'children': ['39']}; {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': '_GETPOST'}
|
A combined MultiDict with POST and GET parameters.
|
def conflicts_with(self, section):
"Returns True if the given section conflicts with this time range."
for p in section.periods:
t = (p.int_days, p.start, p.end)
if t in self:
return True
return False
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'conflicts_with'}; {'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', '9', '35']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'string', 'children': [], 'value': '"Returns True if the given section conflicts with this time range."'}; {'id': '9', 'type': 'for_statement', 'children': ['10', '11', '14']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'section'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'periods'}; {'id': '14', 'type': 'block', 'children': ['15', '28']}; {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '18', 'type': 'tuple', 'children': ['19', '22', '25']}; {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'int_days'}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '28', 'type': 'if_statement', 'children': ['29', '32']}; {'id': '29', 'type': 'comparison_operator', 'children': ['30', '31'], 'value': 'in'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '32', 'type': 'block', 'children': ['33']}; {'id': '33', 'type': 'return_statement', 'children': ['34']}; {'id': '34', 'type': 'True', 'children': []}; {'id': '35', 'type': 'return_statement', 'children': ['36']}; {'id': '36', 'type': 'False', 'children': []}
|
Returns True if the given section conflicts with this time range.
|
def _get_tgt_length(self, var):
if var.type == "g" or var.type == "m":
return float("inf")
else:
identity_info = self.hdp.get_tx_identity_info(var.ac)
if not identity_info:
raise HGVSDataNotAvailableError(
"No identity info available for {ac}".format(ac=var.ac))
tgt_len = sum(identity_info["lengths"])
return tgt_len
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_tgt_length'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'var'}; {'id': '6', 'type': 'block', 'children': ['7']}; {'id': '7', 'type': 'if_statement', 'children': ['8', '19', '25']}; {'id': '8', 'type': 'boolean_operator', 'children': ['9', '14'], 'value': 'or'}; {'id': '9', 'type': 'comparison_operator', 'children': ['10', '13'], 'value': '=='}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'var'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '13', 'type': 'string', 'children': [], 'value': '"g"'}; {'id': '14', 'type': 'comparison_operator', 'children': ['15', '18'], 'value': '=='}; {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'var'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '18', 'type': 'string', 'children': [], 'value': '"m"'}; {'id': '19', 'type': 'block', 'children': ['20']}; {'id': '20', 'type': 'return_statement', 'children': ['21']}; {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'string', 'children': [], 'value': '"inf"'}; {'id': '25', 'type': 'else_clause', 'children': ['26']}; {'id': '26', 'type': 'block', 'children': ['27', '40', '58', '67']}; {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'identity_info'}; {'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': 'self'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'hdp'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'get_tx_identity_info'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}; {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'var'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'ac'}; {'id': '40', 'type': 'if_statement', 'children': ['41', '43']}; {'id': '41', 'type': 'not_operator', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'identity_info'}; {'id': '43', 'type': 'block', 'children': ['44']}; {'id': '44', 'type': 'raise_statement', 'children': ['45']}; {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'HGVSDataNotAvailableError'}; {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'call', 'children': ['49', '52']}; {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'string', 'children': [], 'value': '"No identity info available for {ac}"'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}; {'id': '53', 'type': 'keyword_argument', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'ac'}; {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'var'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'ac'}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}; {'id': '59', 'type': 'assignment', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'tgt_len'}; {'id': '61', 'type': 'call', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'sum'}; {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'subscript', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'identity_info'}; {'id': '66', 'type': 'string', 'children': [], 'value': '"lengths"'}; {'id': '67', 'type': 'return_statement', 'children': ['68']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'tgt_len'}
|
Get the total length of the whole reference sequence
|
def _modify_event(self, event_name, method, func):
if event_name not in self.ALL_EVENTS:
raise TypeError(('event_name ("%s") can only be one of the '
'following: %s') % (event_name,
repr(self.ALL_EVENTS)))
if not isinstance(func, collections.Callable):
raise TypeError(('func must be callable to be added as an '
'observer.'))
getattr(self._events[event_name], method)(func)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_modify_event'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'event_name'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '8', 'type': 'block', 'children': ['9', '33', '51']}; {'id': '9', 'type': 'if_statement', 'children': ['10', '15']}; {'id': '10', 'type': 'comparison_operator', 'children': ['11', '12'], 'value': 'not in'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'event_name'}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'ALL_EVENTS'}; {'id': '15', 'type': 'block', 'children': ['16']}; {'id': '16', 'type': 'raise_statement', 'children': ['17']}; {'id': '17', 'type': 'call', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'TypeError'}; {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'binary_operator', 'children': ['21', '25'], 'value': '%'}; {'id': '21', 'type': '()', 'children': ['22']}; {'id': '22', 'type': 'concatenated_string', 'children': ['23', '24']}; {'id': '23', 'type': 'string', 'children': [], 'value': '\'event_name ("%s") can only be one of the \''}; {'id': '24', 'type': 'string', 'children': [], 'value': "'following: %s'"}; {'id': '25', 'type': 'tuple', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'event_name'}; {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'repr'}; {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'ALL_EVENTS'}; {'id': '33', 'type': 'if_statement', 'children': ['34', '42']}; {'id': '34', 'type': 'not_operator', 'children': ['35']}; {'id': '35', 'type': 'call', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '37', 'type': 'argument_list', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'collections'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'Callable'}; {'id': '42', 'type': 'block', 'children': ['43']}; {'id': '43', 'type': 'raise_statement', 'children': ['44']}; {'id': '44', 'type': 'call', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'TypeError'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}; {'id': '47', 'type': '()', 'children': ['48']}; {'id': '48', 'type': 'concatenated_string', 'children': ['49', '50']}; {'id': '49', 'type': 'string', 'children': [], 'value': "'func must be callable to be added as an '"}; {'id': '50', 'type': 'string', 'children': [], 'value': "'observer.'"}; {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'call', 'children': ['53', '62']}; {'id': '53', 'type': 'call', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '55', 'type': 'argument_list', 'children': ['56', '61']}; {'id': '56', 'type': 'subscript', 'children': ['57', '60']}; {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': '_events'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'event_name'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'func'}
|
Wrapper to call a list's method from one of the events
|
def find_identifier(self):
features = self.data['features']
n = len(features)
feature = features[0]
if 'id' in feature and len(set(feat['id'] for feat in features)) == n:
return 'feature.id'
for key in feature.get('properties', []):
if len(set(feat['properties'][key] for feat in features)) == n:
return 'feature.properties.{}'.format(key)
if self.embed:
for i, feature in enumerate(self.data['features']):
feature['id'] = str(i)
return 'feature.id'
raise ValueError(
'There is no unique identifier for each feature and because '
'`embed=False` it cannot be added. Consider adding an `id` '
'field to your geojson data or set `embed=True`. '
)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'find_identifier'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '14', '21', '27', '49', '84', '113']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'features'}; {'id': '9', 'type': 'subscript', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '13', 'type': 'string', 'children': [], 'value': "'features'"}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}; {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '17', 'type': 'call', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'features'}; {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'feature'}; {'id': '24', 'type': 'subscript', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'features'}; {'id': '26', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '27', 'type': 'if_statement', 'children': ['28', '46']}; {'id': '28', 'type': 'boolean_operator', 'children': ['29', '32'], 'value': 'and'}; {'id': '29', 'type': 'comparison_operator', 'children': ['30', '31'], 'value': 'in'}; {'id': '30', 'type': 'string', 'children': [], 'value': "'id'"}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'feature'}; {'id': '32', 'type': 'comparison_operator', 'children': ['33', '45'], 'value': '=='}; {'id': '33', 'type': 'call', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'call', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '38', 'type': 'generator_expression', 'children': ['39', '42']}; {'id': '39', 'type': 'subscript', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'feat'}; {'id': '41', 'type': 'string', 'children': [], 'value': "'id'"}; {'id': '42', 'type': 'for_in_clause', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'feat'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'features'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '46', 'type': 'block', 'children': ['47']}; {'id': '47', 'type': 'return_statement', 'children': ['48']}; {'id': '48', 'type': 'string', 'children': [], 'value': "'feature.id'"}; {'id': '49', 'type': 'for_statement', 'children': ['50', '51', '58']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '51', 'type': 'call', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'feature'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '55', 'type': 'argument_list', 'children': ['56', '57']}; {'id': '56', 'type': 'string', 'children': [], 'value': "'properties'"}; {'id': '57', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '58', 'type': 'block', 'children': ['59']}; {'id': '59', 'type': 'if_statement', 'children': ['60', '76']}; {'id': '60', 'type': 'comparison_operator', 'children': ['61', '75'], 'value': '=='}; {'id': '61', 'type': 'call', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'call', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '66', 'type': 'generator_expression', 'children': ['67', '72']}; {'id': '67', 'type': 'subscript', 'children': ['68', '71']}; {'id': '68', 'type': 'subscript', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'feat'}; {'id': '70', 'type': 'string', 'children': [], 'value': "'properties'"}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '72', 'type': 'for_in_clause', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'feat'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'features'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '76', 'type': 'block', 'children': ['77']}; {'id': '77', 'type': 'return_statement', 'children': ['78']}; {'id': '78', 'type': 'call', 'children': ['79', '82']}; {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'string', 'children': [], 'value': "'feature.properties.{}'"}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '84', 'type': 'if_statement', 'children': ['85', '88']}; {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'embed'}; {'id': '88', 'type': 'block', 'children': ['89', '111']}; {'id': '89', 'type': 'for_statement', 'children': ['90', '93', '101']}; {'id': '90', 'type': 'pattern_list', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'feature'}; {'id': '93', 'type': 'call', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'subscript', 'children': ['97', '100']}; {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '100', 'type': 'string', 'children': [], 'value': "'features'"}; {'id': '101', 'type': 'block', 'children': ['102']}; {'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': 'feature'}; {'id': '106', 'type': 'string', 'children': [], 'value': "'id'"}; {'id': '107', 'type': 'call', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '109', 'type': 'argument_list', 'children': ['110']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '111', 'type': 'return_statement', 'children': ['112']}; {'id': '112', 'type': 'string', 'children': [], 'value': "'feature.id'"}; {'id': '113', 'type': 'raise_statement', 'children': ['114']}; {'id': '114', 'type': 'call', 'children': ['115', '116']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '116', 'type': 'argument_list', 'children': ['117']}; {'id': '117', 'type': 'concatenated_string', 'children': ['118', '119', '120']}; {'id': '118', 'type': 'string', 'children': [], 'value': "'There is no unique identifier for each feature and because '"}; {'id': '119', 'type': 'string', 'children': [], 'value': "'`embed=False` it cannot be added. Consider adding an `id` '"}; {'id': '120', 'type': 'string', 'children': [], 'value': "'field to your geojson data or set `embed=True`. '"}
|
Find a unique identifier for each feature, create it if needed.
|
def write_csv_line(mol, csv_writer, options):
status_field = options.status_field
line = []
id = mol.GetProp('id')
if id is not None:
line.append(id)
else:
line.append('n/a')
line.append(mol.GetProp(status_field))
queryList = mol.properties.keys()
for queryLabel in queryList:
line.append(mol.properties[queryLabel])
csv_writer.writerow(line)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'write_csv_line'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'mol'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'csv_writer'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'options'}; {'id': '7', 'type': 'block', 'children': ['8', '14', '18', '27', '48', '60', '70', '85']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'status_field'}; {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'options'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'status_field'}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}; {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '17', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}; {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '21', 'type': 'call', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'mol'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'GetProp'}; {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'string', 'children': [], 'value': "'id'"}; {'id': '27', 'type': 'if_statement', 'children': ['28', '31', '39']}; {'id': '28', 'type': 'comparison_operator', 'children': ['29', '30'], 'value': 'is not'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '30', 'type': 'None', 'children': []}; {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}; {'id': '33', 'type': 'call', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '39', 'type': 'else_clause', 'children': ['40']}; {'id': '40', 'type': 'block', 'children': ['41']}; {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'call', 'children': ['43', '46']}; {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}; {'id': '47', 'type': 'string', 'children': [], 'value': "'n/a'"}; {'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': 'line'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'call', 'children': ['55', '58']}; {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'mol'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'GetProp'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'status_field'}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}; {'id': '61', 'type': 'assignment', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'queryList'}; {'id': '63', 'type': 'call', 'children': ['64', '69']}; {'id': '64', 'type': 'attribute', 'children': ['65', '68']}; {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'mol'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'properties'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '69', 'type': 'argument_list', 'children': []}; {'id': '70', 'type': 'for_statement', 'children': ['71', '72', '73']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'queryLabel'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'queryList'}; {'id': '73', 'type': 'block', 'children': ['74']}; {'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': 'line'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'subscript', 'children': ['81', '84']}; {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'mol'}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'properties'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'queryLabel'}; {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'call', 'children': ['87', '90']}; {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'csv_writer'}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'writerow'}; {'id': '90', 'type': 'argument_list', 'children': ['91']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'line'}
|
Parse mol object and write a line to the csv file
|
def on_scroll(self):
try:
sw = self.view['sw_scroller']
except KeyError:
return False
vadj = sw.get_vadjustment()
if vadj is None: return False
val = vadj.get_value()
if val >= vadj.upper - vadj.page_size:
self.view.show_vscrollbar()
return False
vadj.set_value(val+0.5)
return True
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'on_scroll'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '21', '29', '36', '44', '65', '74']}; {'id': '6', 'type': 'try_statement', 'children': ['7', '16']}; {'id': '7', 'type': 'block', 'children': ['8']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'sw'}; {'id': '11', 'type': 'subscript', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'view'}; {'id': '15', 'type': 'string', 'children': [], 'value': "'sw_scroller'"}; {'id': '16', 'type': 'except_clause', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'KeyError'}; {'id': '18', 'type': 'block', 'children': ['19']}; {'id': '19', 'type': 'return_statement', 'children': ['20']}; {'id': '20', 'type': 'False', 'children': []}; {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'vadj'}; {'id': '24', 'type': 'call', 'children': ['25', '28']}; {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'sw'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'get_vadjustment'}; {'id': '28', 'type': 'argument_list', 'children': []}; {'id': '29', 'type': 'if_statement', 'children': ['30', '33']}; {'id': '30', 'type': 'comparison_operator', 'children': ['31', '32'], 'value': 'is'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'vadj'}; {'id': '32', 'type': 'None', 'children': []}; {'id': '33', 'type': 'block', 'children': ['34']}; {'id': '34', 'type': 'return_statement', 'children': ['35']}; {'id': '35', 'type': 'False', 'children': []}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}; {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '39', 'type': 'call', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'vadj'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'get_value'}; {'id': '43', 'type': 'argument_list', 'children': []}; {'id': '44', 'type': 'if_statement', 'children': ['45', '54']}; {'id': '45', 'type': 'comparison_operator', 'children': ['46', '47'], 'value': '>='}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '47', 'type': 'binary_operator', 'children': ['48', '51'], 'value': '-'}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'vadj'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'upper'}; {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'vadj'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'page_size'}; {'id': '54', 'type': 'block', 'children': ['55', '63']}; {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'call', 'children': ['57', '62']}; {'id': '57', 'type': 'attribute', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'view'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'show_vscrollbar'}; {'id': '62', 'type': 'argument_list', 'children': []}; {'id': '63', 'type': 'return_statement', 'children': ['64']}; {'id': '64', 'type': 'False', 'children': []}; {'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': 'vadj'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'set_value'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}; {'id': '71', 'type': 'binary_operator', 'children': ['72', '73'], 'value': '+'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '73', 'type': 'float', 'children': [], 'value': '0.5'}; {'id': '74', 'type': 'return_statement', 'children': ['75']}; {'id': '75', 'type': 'True', 'children': []}
|
Called to scroll text
|
def until_state(self, state, timeout=None):
if state not in self._valid_states:
raise ValueError('State must be one of {0}, not {1}'
.format(self._valid_states, state))
if state != self._state:
if timeout:
return with_timeout(self._ioloop.time() + timeout,
self._waiting_futures[state],
self._ioloop)
else:
return self._waiting_futures[state]
else:
f = tornado_Future()
f.set_result(True)
return f
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'until_state'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'state'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'timeout'}; {'id': '8', 'type': 'None', 'children': []}; {'id': '9', 'type': 'block', 'children': ['10', '30']}; {'id': '10', 'type': 'if_statement', 'children': ['11', '16']}; {'id': '11', 'type': 'comparison_operator', 'children': ['12', '13'], 'value': 'not in'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'state'}; {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': '_valid_states'}; {'id': '16', 'type': 'block', 'children': ['17']}; {'id': '17', 'type': 'raise_statement', 'children': ['18']}; {'id': '18', 'type': 'call', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}; {'id': '21', 'type': 'call', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'string', 'children': [], 'value': "'State must be one of {0}, not {1}'"}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '25', 'type': 'argument_list', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': '_valid_states'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'state'}; {'id': '30', 'type': 'if_statement', 'children': ['31', '36', '69']}; {'id': '31', 'type': 'comparison_operator', 'children': ['32', '33'], 'value': '!='}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'state'}; {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': '_state'}; {'id': '36', 'type': 'block', 'children': ['37']}; {'id': '37', 'type': 'if_statement', 'children': ['38', '39', '61']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'timeout'}; {'id': '39', 'type': 'block', 'children': ['40']}; {'id': '40', 'type': 'return_statement', 'children': ['41']}; {'id': '41', 'type': 'call', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'with_timeout'}; {'id': '43', 'type': 'argument_list', 'children': ['44', '53', '58']}; {'id': '44', 'type': 'binary_operator', 'children': ['45', '52'], 'value': '+'}; {'id': '45', 'type': 'call', 'children': ['46', '51']}; {'id': '46', 'type': 'attribute', 'children': ['47', '50']}; {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': '_ioloop'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '51', 'type': 'argument_list', 'children': []}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'timeout'}; {'id': '53', 'type': 'subscript', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': '_waiting_futures'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'state'}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': '_ioloop'}; {'id': '61', 'type': 'else_clause', 'children': ['62']}; {'id': '62', 'type': 'block', 'children': ['63']}; {'id': '63', 'type': 'return_statement', 'children': ['64']}; {'id': '64', 'type': 'subscript', 'children': ['65', '68']}; {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': '_waiting_futures'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'state'}; {'id': '69', 'type': 'else_clause', 'children': ['70']}; {'id': '70', 'type': 'block', 'children': ['71', '77', '84']}; {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'assignment', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '74', 'type': 'call', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'tornado_Future'}; {'id': '76', 'type': 'argument_list', 'children': []}; {'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': 'f'}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'set_result'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}; {'id': '83', 'type': 'True', 'children': []}; {'id': '84', 'type': 'return_statement', 'children': ['85']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'f'}
|
Return a tornado Future that will resolve when the requested state is set
|
def enqueue_jobs(self):
self.log.debug('Checking for scheduled jobs')
jobs = self.get_jobs_to_queue()
for job in jobs:
self.enqueue_job(job)
self.connection.expire(self.scheduler_key, int(self._interval) + 10)
return jobs
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'enqueue_jobs'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '15', '23', '34', '53']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'call', 'children': ['8', '13']}; {'id': '8', 'type': 'attribute', 'children': ['9', '12']}; {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'}; {'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': "'Checking for scheduled jobs'"}; {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'jobs'}; {'id': '18', 'type': 'call', 'children': ['19', '22']}; {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'get_jobs_to_queue'}; {'id': '22', 'type': 'argument_list', 'children': []}; {'id': '23', 'type': 'for_statement', 'children': ['24', '25', '26']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'job'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'jobs'}; {'id': '26', 'type': 'block', 'children': ['27']}; {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'call', 'children': ['29', '32']}; {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'enqueue_job'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'job'}; {'id': '34', 'type': 'expression_statement', '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': 'connection'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'expire'}; {'id': '41', 'type': 'argument_list', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'scheduler_key'}; {'id': '45', 'type': 'binary_operator', 'children': ['46', '52'], 'value': '+'}; {'id': '46', 'type': 'call', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}; {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': '_interval'}; {'id': '52', 'type': 'integer', 'children': [], 'value': '10'}; {'id': '53', 'type': 'return_statement', 'children': ['54']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'jobs'}
|
Move scheduled jobs into queues.
|
def validate_model_specification_file(file_path: str) -> str:
if not os.path.isfile(file_path):
raise ConfigurationError('If you provide a model specification file, it must be a file. '
f'You provided {file_path}')
extension = file_path.split('.')[-1]
if extension not in ['yaml', 'yml']:
raise ConfigurationError(f'Model specification files must be in a yaml format. You provided {extension}')
yaml.full_load(file_path)
return file_path
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'validate_model_specification_file'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'file_path'}; {'id': '6', 'type': 'type', 'children': ['7']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '8', 'type': 'type', 'children': ['9']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '10', 'type': 'block', 'children': ['11', '29', '41', '53', '60']}; {'id': '11', 'type': 'if_statement', 'children': ['12', '21']}; {'id': '12', 'type': 'not_operator', 'children': ['13']}; {'id': '13', 'type': 'call', 'children': ['14', '19']}; {'id': '14', 'type': 'attribute', 'children': ['15', '18']}; {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'isfile'}; {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'file_path'}; {'id': '21', 'type': 'block', 'children': ['22']}; {'id': '22', 'type': 'raise_statement', 'children': ['23']}; {'id': '23', 'type': 'call', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'ConfigurationError'}; {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'concatenated_string', 'children': ['27', '28']}; {'id': '27', 'type': 'string', 'children': [], 'value': "'If you provide a model specification file, it must be a file. '"}; {'id': '28', 'type': 'string', 'children': [], 'value': "f'You provided {file_path}'"}; {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'extension'}; {'id': '32', 'type': 'subscript', 'children': ['33', '39']}; {'id': '33', 'type': 'call', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'file_path'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'string', 'children': [], 'value': "'.'"}; {'id': '39', 'type': 'unary_operator', 'children': ['40'], 'value': '-'}; {'id': '40', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '41', 'type': 'if_statement', 'children': ['42', '47']}; {'id': '42', 'type': 'comparison_operator', 'children': ['43', '44'], 'value': 'not in'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'extension'}; {'id': '44', 'type': 'list', 'children': ['45', '46'], 'value': "['yaml', 'yml']"}; {'id': '45', 'type': 'string', 'children': [], 'value': "'yaml'"}; {'id': '46', 'type': 'string', 'children': [], 'value': "'yml'"}; {'id': '47', 'type': 'block', 'children': ['48']}; {'id': '48', 'type': 'raise_statement', 'children': ['49']}; {'id': '49', 'type': 'call', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'ConfigurationError'}; {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'string', 'children': [], 'value': "f'Model specification files must be in a yaml format. You provided {extension}'"}; {'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': 'yaml'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'full_load'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'file_path'}; {'id': '60', 'type': 'return_statement', 'children': ['61']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'file_path'}
|
Ensures the provided file is a yaml file
|
def write_data_to_file(data, filepath):
try:
os.makedirs(os.path.dirname(filepath), 0o700)
except OSError:
pass
write_to_disk(filepath, content=data)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'write_data_to_file'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'filepath'}; {'id': '6', 'type': 'block', 'children': ['7', '28']}; {'id': '7', 'type': 'try_statement', 'children': ['8', '24']}; {'id': '8', 'type': 'block', 'children': ['9']}; {'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': 'os'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'makedirs'}; {'id': '14', 'type': 'argument_list', 'children': ['15', '23']}; {'id': '15', 'type': 'call', 'children': ['16', '21']}; {'id': '16', 'type': 'attribute', 'children': ['17', '20']}; {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'dirname'}; {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'filepath'}; {'id': '23', 'type': 'integer', 'children': [], 'value': '0o700'}; {'id': '24', 'type': 'except_clause', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'OSError'}; {'id': '26', 'type': 'block', 'children': ['27']}; {'id': '27', 'type': 'pass_statement', 'children': []}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}; {'id': '29', 'type': 'call', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'write_to_disk'}; {'id': '31', 'type': 'argument_list', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'filepath'}; {'id': '33', 'type': 'keyword_argument', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'content'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'data'}
|
Write data to file
|
def iter_ROOT_classes():
class_index = "http://root.cern.ch/root/html/ClassIndex.html"
for s in minidom.parse(urlopen(class_index)).getElementsByTagName("span"):
if ("class", "typename") in s.attributes.items():
class_name = s.childNodes[0].nodeValue
try:
yield getattr(QROOT, class_name)
except AttributeError:
pass
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '4']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'iter_ROOT_classes'}; {'id': '3', 'type': 'parameters', 'children': []}; {'id': '4', 'type': 'block', 'children': ['5', '9']}; {'id': '5', 'type': 'expression_statement', 'children': ['6']}; {'id': '6', 'type': 'assignment', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'class_index'}; {'id': '8', 'type': 'string', 'children': [], 'value': '"http://root.cern.ch/root/html/ClassIndex.html"'}; {'id': '9', 'type': 'for_statement', 'children': ['10', '11', '25']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '11', 'type': 'call', 'children': ['12', '23']}; {'id': '12', 'type': 'attribute', 'children': ['13', '22']}; {'id': '13', 'type': 'call', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'minidom'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'parse'}; {'id': '17', 'type': 'argument_list', 'children': ['18']}; {'id': '18', 'type': 'call', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'urlopen'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'class_index'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'getElementsByTagName'}; {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'string', 'children': [], 'value': '"span"'}; {'id': '25', 'type': 'block', 'children': ['26']}; {'id': '26', 'type': 'if_statement', 'children': ['27', '38']}; {'id': '27', 'type': 'comparison_operator', 'children': ['28', '31'], 'value': 'in'}; {'id': '28', 'type': 'tuple', 'children': ['29', '30']}; {'id': '29', 'type': 'string', 'children': [], 'value': '"class"'}; {'id': '30', 'type': 'string', 'children': [], 'value': '"typename"'}; {'id': '31', 'type': 'call', 'children': ['32', '37']}; {'id': '32', 'type': 'attribute', 'children': ['33', '36']}; {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'attributes'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '37', 'type': 'argument_list', 'children': []}; {'id': '38', 'type': 'block', 'children': ['39', '49']}; {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'class_name'}; {'id': '42', 'type': 'attribute', 'children': ['43', '48']}; {'id': '43', 'type': 'subscript', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'childNodes'}; {'id': '47', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'nodeValue'}; {'id': '49', 'type': 'try_statement', 'children': ['50', '58']}; {'id': '50', 'type': 'block', 'children': ['51']}; {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'yield', 'children': ['53']}; {'id': '53', 'type': 'call', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '55', 'type': 'argument_list', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'QROOT'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'class_name'}; {'id': '58', 'type': 'except_clause', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'AttributeError'}; {'id': '60', 'type': 'block', 'children': ['61']}; {'id': '61', 'type': 'pass_statement', 'children': []}
|
Iterator over all available ROOT classes
|
def DropTables(self):
rows, _ = self.ExecuteQuery(
"SELECT table_name FROM information_schema.tables "
"WHERE table_schema='%s'" % self.database_name)
for row in rows:
self.ExecuteQuery("DROP TABLE `%s`" % row["table_name"])
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'DropTables'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '23']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '11']}; {'id': '8', 'type': 'pattern_list', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'rows'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'ExecuteQuery'}; {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'binary_operator', 'children': ['17', '20'], 'value': '%'}; {'id': '17', 'type': 'concatenated_string', 'children': ['18', '19']}; {'id': '18', 'type': 'string', 'children': [], 'value': '"SELECT table_name FROM information_schema.tables "'}; {'id': '19', 'type': 'string', 'children': [], 'value': '"WHERE table_schema=\'%s\'"'}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'database_name'}; {'id': '23', 'type': 'for_statement', 'children': ['24', '25', '26']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'rows'}; {'id': '26', 'type': 'block', 'children': ['27']}; {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'call', 'children': ['29', '32']}; {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'ExecuteQuery'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}; {'id': '33', 'type': 'binary_operator', 'children': ['34', '35'], 'value': '%'}; {'id': '34', 'type': 'string', 'children': [], 'value': '"DROP TABLE `%s`"'}; {'id': '35', 'type': 'subscript', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '37', 'type': 'string', 'children': [], 'value': '"table_name"'}
|
Drop all existing tables.
|
def delta_stream(self, target='HEAD', limit=None,
sort=pygit2.GIT_SORT_TIME | pygit2.GIT_SORT_REVERSE,
after=None, before=None):
if target == 'HEAD':
target = self.repo.head.target
commits = []
for commit in self.repo.walk(target, sort):
cdate = commit_date(commit)
log.debug(
"processing commit id:%s date:%s parents:%d msg:%s",
str(commit.id)[:6], cdate.isoformat(),
len(commit.parents), commit.message)
if after and cdate > after:
continue
if before and cdate < before:
continue
commits.append(commit)
if limit and len(commits) > limit:
break
if limit:
self.initialize_tree(commits[limit].tree)
commits.pop(-1)
for commit in commits:
for policy_change in self._process_stream_commit(commit):
yield policy_change
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '26']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'delta_stream'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '20', '23']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'target'}; {'id': '7', 'type': 'string', 'children': [], 'value': "'HEAD'"}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '10', 'type': 'None', 'children': []}; {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '13', 'type': 'binary_operator', 'children': ['14', '17'], 'value': '|'}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'pygit2'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'GIT_SORT_TIME'}; {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'pygit2'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'GIT_SORT_REVERSE'}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'after'}; {'id': '22', 'type': 'None', 'children': []}; {'id': '23', 'type': 'default_parameter', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'before'}; {'id': '25', 'type': 'None', 'children': []}; {'id': '26', 'type': 'block', 'children': ['27', '42', '46', '130', '152']}; {'id': '27', 'type': 'if_statement', 'children': ['28', '31']}; {'id': '28', 'type': 'comparison_operator', 'children': ['29', '30'], 'value': '=='}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'target'}; {'id': '30', 'type': 'string', 'children': [], 'value': "'HEAD'"}; {'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': 'target'}; {'id': '35', 'type': 'attribute', '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': 'repo'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'head'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'target'}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}; {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'commits'}; {'id': '45', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '46', 'type': 'for_statement', 'children': ['47', '48', '57']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'commit'}; {'id': '48', 'type': 'call', 'children': ['49', '54']}; {'id': '49', 'type': 'attribute', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'repo'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'walk'}; {'id': '54', 'type': 'argument_list', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'target'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '57', 'type': 'block', 'children': ['58', '65', '96', '104', '112', '119']}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}; {'id': '59', 'type': 'assignment', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'cdate'}; {'id': '61', 'type': 'call', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'commit_date'}; {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'commit'}; {'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', '72', '82', '87', '93']}; {'id': '71', 'type': 'string', 'children': [], 'value': '"processing commit id:%s date:%s parents:%d msg:%s"'}; {'id': '72', 'type': 'subscript', 'children': ['73', '79']}; {'id': '73', 'type': 'call', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'commit'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '79', 'type': 'slice', 'children': ['80', '81']}; {'id': '80', 'type': 'colon', 'children': []}; {'id': '81', 'type': 'integer', 'children': [], 'value': '6'}; {'id': '82', 'type': 'call', 'children': ['83', '86']}; {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'cdate'}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'isoformat'}; {'id': '86', 'type': 'argument_list', 'children': []}; {'id': '87', 'type': 'call', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'commit'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'parents'}; {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'commit'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '96', 'type': 'if_statement', 'children': ['97', '102']}; {'id': '97', 'type': 'boolean_operator', 'children': ['98', '99'], 'value': 'and'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'after'}; {'id': '99', 'type': 'comparison_operator', 'children': ['100', '101'], 'value': '>'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'cdate'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'after'}; {'id': '102', 'type': 'block', 'children': ['103']}; {'id': '103', 'type': 'continue_statement', 'children': []}; {'id': '104', 'type': 'if_statement', 'children': ['105', '110']}; {'id': '105', 'type': 'boolean_operator', 'children': ['106', '107'], 'value': 'and'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'before'}; {'id': '107', 'type': 'comparison_operator', 'children': ['108', '109'], 'value': '<'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'cdate'}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'before'}; {'id': '110', 'type': 'block', 'children': ['111']}; {'id': '111', 'type': 'continue_statement', 'children': []}; {'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': 'commits'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '117', 'type': 'argument_list', 'children': ['118']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'commit'}; {'id': '119', 'type': 'if_statement', 'children': ['120', '128']}; {'id': '120', 'type': 'boolean_operator', 'children': ['121', '122'], 'value': 'and'}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '122', 'type': 'comparison_operator', 'children': ['123', '127'], 'value': '>'}; {'id': '123', 'type': 'call', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '125', 'type': 'argument_list', 'children': ['126']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'commits'}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '128', 'type': 'block', 'children': ['129']}; {'id': '129', 'type': 'break_statement', 'children': []}; {'id': '130', 'type': 'if_statement', 'children': ['131', '132']}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '132', 'type': 'block', 'children': ['133', '144']}; {'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': 'self'}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'initialize_tree'}; {'id': '138', 'type': 'argument_list', 'children': ['139']}; {'id': '139', 'type': 'attribute', 'children': ['140', '143']}; {'id': '140', 'type': 'subscript', 'children': ['141', '142']}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'commits'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'tree'}; {'id': '144', 'type': 'expression_statement', 'children': ['145']}; {'id': '145', 'type': 'call', 'children': ['146', '149']}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'commits'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '149', 'type': 'argument_list', 'children': ['150']}; {'id': '150', 'type': 'unary_operator', 'children': ['151'], 'value': '-'}; {'id': '151', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '152', 'type': 'for_statement', 'children': ['153', '154', '155']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'commit'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'commits'}; {'id': '155', 'type': 'block', 'children': ['156']}; {'id': '156', 'type': 'for_statement', 'children': ['157', '158', '164']}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'policy_change'}; {'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': '_process_stream_commit'}; {'id': '162', 'type': 'argument_list', 'children': ['163']}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'commit'}; {'id': '164', 'type': 'block', 'children': ['165']}; {'id': '165', 'type': 'expression_statement', 'children': ['166']}; {'id': '166', 'type': 'yield', 'children': ['167']}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'policy_change'}
|
Return an iterator of policy changes along a commit lineage in a repo.
|
def file_matches_regexps(filename, patterns):
return any(re.match(pat, filename) for pat in patterns)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'file_matches_regexps'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'patterns'}; {'id': '6', 'type': 'block', 'children': ['7']}; {'id': '7', 'type': 'return_statement', 'children': ['8']}; {'id': '8', 'type': 'call', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'any'}; {'id': '10', 'type': 'generator_expression', 'children': ['11', '18']}; {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '15', 'type': 'argument_list', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'pat'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '18', 'type': 'for_in_clause', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'pat'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'patterns'}
|
Does this filename match any of the regular expressions?
|
def version():
namespace = {}
with open(os.path.join('mrcfile', 'version.py')) as f:
exec(f.read(), namespace)
return namespace['__version__']
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '4']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'version'}; {'id': '3', 'type': 'parameters', 'children': []}; {'id': '4', 'type': 'block', 'children': ['5', '9', '38']}; {'id': '5', 'type': 'expression_statement', 'children': ['6']}; {'id': '6', 'type': 'assignment', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'namespace'}; {'id': '8', 'type': 'dictionary', 'children': []}; {'id': '9', 'type': 'with_statement', 'children': ['10', '27']}; {'id': '10', 'type': 'with_clause', 'children': ['11']}; {'id': '11', 'type': 'with_item', 'children': ['12']}; {'id': '12', 'type': 'as_pattern', 'children': ['13', '25']}; {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '15', 'type': 'argument_list', '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': 'os'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '22', 'type': 'argument_list', 'children': ['23', '24']}; {'id': '23', 'type': 'string', 'children': [], 'value': "'mrcfile'"}; {'id': '24', 'type': 'string', 'children': [], 'value': "'version.py'"}; {'id': '25', 'type': 'as_pattern_target', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '27', 'type': 'block', 'children': ['28']}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}; {'id': '29', 'type': 'call', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'exec'}; {'id': '31', 'type': 'argument_list', 'children': ['32', '37']}; {'id': '32', 'type': 'call', 'children': ['33', '36']}; {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'read'}; {'id': '36', 'type': 'argument_list', 'children': []}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'namespace'}; {'id': '38', 'type': 'return_statement', 'children': ['39']}; {'id': '39', 'type': 'subscript', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'namespace'}; {'id': '41', 'type': 'string', 'children': [], 'value': "'__version__'"}
|
Get the version number without importing the mrcfile package.
|
def add(self, client_id, email_address, name, access_level, password):
body = {
"EmailAddress": email_address,
"Name": name,
"AccessLevel": access_level,
"Password": password}
response = self._post("/clients/%s/people.json" %
client_id, json.dumps(body))
return json_to_py(response)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'add'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'client_id'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'email_address'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'access_level'}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'password'}; {'id': '10', 'type': 'block', 'children': ['11', '27', '44']}; {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'body'}; {'id': '14', 'type': 'dictionary', 'children': ['15', '18', '21', '24']}; {'id': '15', 'type': 'pair', 'children': ['16', '17']}; {'id': '16', 'type': 'string', 'children': [], 'value': '"EmailAddress"'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'email_address'}; {'id': '18', 'type': 'pair', 'children': ['19', '20']}; {'id': '19', 'type': 'string', 'children': [], 'value': '"Name"'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '21', 'type': 'pair', 'children': ['22', '23']}; {'id': '22', 'type': 'string', 'children': [], 'value': '"AccessLevel"'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'access_level'}; {'id': '24', 'type': 'pair', 'children': ['25', '26']}; {'id': '25', 'type': 'string', 'children': [], 'value': '"Password"'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'password'}; {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '30', 'type': 'call', 'children': ['31', '34']}; {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': '_post'}; {'id': '34', 'type': 'argument_list', 'children': ['35', '38']}; {'id': '35', 'type': 'binary_operator', 'children': ['36', '37'], 'value': '%'}; {'id': '36', 'type': 'string', 'children': [], 'value': '"/clients/%s/people.json"'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'client_id'}; {'id': '38', 'type': 'call', 'children': ['39', '42']}; {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'dumps'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'body'}; {'id': '44', 'type': 'return_statement', 'children': ['45']}; {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'json_to_py'}; {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'response'}
|
Adds a person to a client. Password is optional and if not supplied, an invitation will be emailed to the person
|
def write_nginx_config(self):
log = logging.getLogger('ipsv.models.sites.site')
if not os.path.exists(self.root):
log.debug('Creating HTTP root directory: %s', self.root)
os.makedirs(self.root, 0o755)
server_block = ServerBlock(self)
server_config_path = os.path.join(_cfg.get('Paths', 'NginxSitesAvailable'), self.domain.name)
if not os.path.exists(server_config_path):
log.debug('Creating new configuration path: %s', server_config_path)
os.makedirs(server_config_path, 0o755)
server_config_path = os.path.join(server_config_path, '{fn}.conf'.format(fn=self.slug))
if os.path.exists(server_config_path):
log.info('Server block configuration file already exists, overwriting: %s', server_config_path)
os.remove(server_config_path)
log.info('Writing Nginx server block configuration file')
with open(server_config_path, 'w') as f:
f.write(server_block.template)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'write_nginx_config'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '15', '48', '55', '77', '104', '125', '150', '157']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'log'}; {'id': '9', 'type': 'call', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'getLogger'}; {'id': '13', 'type': 'argument_list', 'children': ['14']}; {'id': '14', 'type': 'string', 'children': [], 'value': "'ipsv.models.sites.site'"}; {'id': '15', 'type': 'if_statement', 'children': ['16', '27']}; {'id': '16', 'type': 'not_operator', 'children': ['17']}; {'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': 'os'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'exists'}; {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '27', 'type': 'block', 'children': ['28', '38']}; {'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': 'log'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '33', 'type': 'argument_list', 'children': ['34', '35']}; {'id': '34', 'type': 'string', 'children': [], 'value': "'Creating HTTP root directory: %s'"}; {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}; {'id': '39', 'type': 'call', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'makedirs'}; {'id': '43', 'type': 'argument_list', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '47', 'type': 'integer', 'children': [], 'value': '0o755'}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}; {'id': '49', 'type': 'assignment', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'server_block'}; {'id': '51', 'type': 'call', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'ServerBlock'}; {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'server_config_path'}; {'id': '58', 'type': 'call', 'children': ['59', '64']}; {'id': '59', 'type': 'attribute', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '64', 'type': 'argument_list', 'children': ['65', '72']}; {'id': '65', 'type': 'call', 'children': ['66', '69']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': '_cfg'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '69', 'type': 'argument_list', 'children': ['70', '71']}; {'id': '70', 'type': 'string', 'children': [], 'value': "'Paths'"}; {'id': '71', 'type': 'string', 'children': [], 'value': "'NginxSitesAvailable'"}; {'id': '72', 'type': 'attribute', 'children': ['73', '76']}; {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'domain'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '77', 'type': 'if_statement', 'children': ['78', '87']}; {'id': '78', 'type': 'not_operator', 'children': ['79']}; {'id': '79', 'type': 'call', 'children': ['80', '85']}; {'id': '80', 'type': 'attribute', 'children': ['81', '84']}; {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'exists'}; {'id': '85', 'type': 'argument_list', 'children': ['86']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'server_config_path'}; {'id': '87', 'type': 'block', 'children': ['88', '96']}; {'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': 'log'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '93', 'type': 'argument_list', 'children': ['94', '95']}; {'id': '94', 'type': 'string', 'children': [], 'value': "'Creating new configuration path: %s'"}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'server_config_path'}; {'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': 'os'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'makedirs'}; {'id': '101', 'type': 'argument_list', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'server_config_path'}; {'id': '103', 'type': 'integer', 'children': [], 'value': '0o755'}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}; {'id': '105', 'type': 'assignment', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'server_config_path'}; {'id': '107', 'type': 'call', 'children': ['108', '113']}; {'id': '108', 'type': 'attribute', 'children': ['109', '112']}; {'id': '109', 'type': 'attribute', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '113', 'type': 'argument_list', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'server_config_path'}; {'id': '115', 'type': 'call', 'children': ['116', '119']}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}; {'id': '117', 'type': 'string', 'children': [], 'value': "'{fn}.conf'"}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '119', 'type': 'argument_list', 'children': ['120']}; {'id': '120', 'type': 'keyword_argument', 'children': ['121', '122']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'fn'}; {'id': '122', 'type': 'attribute', 'children': ['123', '124']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'slug'}; {'id': '125', 'type': 'if_statement', 'children': ['126', '134']}; {'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': 'os'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'exists'}; {'id': '132', 'type': 'argument_list', 'children': ['133']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'server_config_path'}; {'id': '134', 'type': 'block', 'children': ['135', '143']}; {'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': 'log'}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '140', 'type': 'argument_list', 'children': ['141', '142']}; {'id': '141', 'type': 'string', 'children': [], 'value': "'Server block configuration file already exists, overwriting: %s'"}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'server_config_path'}; {'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': 'os'}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'remove'}; {'id': '148', 'type': 'argument_list', 'children': ['149']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'server_config_path'}; {'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': 'log'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '155', 'type': 'argument_list', 'children': ['156']}; {'id': '156', 'type': 'string', 'children': [], 'value': "'Writing Nginx server block configuration file'"}; {'id': '157', 'type': 'with_statement', 'children': ['158', '168']}; {'id': '158', 'type': 'with_clause', 'children': ['159']}; {'id': '159', 'type': 'with_item', 'children': ['160']}; {'id': '160', 'type': 'as_pattern', 'children': ['161', '166']}; {'id': '161', 'type': 'call', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '163', 'type': 'argument_list', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'server_config_path'}; {'id': '165', 'type': 'string', 'children': [], 'value': "'w'"}; {'id': '166', 'type': 'as_pattern_target', 'children': ['167']}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'f'}; {'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': 'f'}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '174', 'type': 'argument_list', 'children': ['175']}; {'id': '175', 'type': 'attribute', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'server_block'}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'template'}
|
Write the Nginx configuration file for this Site
|
def validate(self):
for client in self.clients:
for key in REQUIRED_KEYS:
if key not in client:
raise MissingConfigValue(key)
if 'revision_file' not in client:
client.revision_file = DEFAULT_REVISION_FILEPATH.format(
client.key
)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'validate'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6']}; {'id': '6', 'type': 'for_statement', 'children': ['7', '8', '11']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'client'}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'clients'}; {'id': '11', 'type': 'block', 'children': ['12', '26']}; {'id': '12', 'type': 'for_statement', 'children': ['13', '14', '15']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'REQUIRED_KEYS'}; {'id': '15', 'type': 'block', 'children': ['16']}; {'id': '16', 'type': 'if_statement', 'children': ['17', '20']}; {'id': '17', 'type': 'comparison_operator', 'children': ['18', '19'], 'value': 'not in'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'client'}; {'id': '20', 'type': 'block', 'children': ['21']}; {'id': '21', 'type': 'raise_statement', 'children': ['22']}; {'id': '22', 'type': 'call', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'MissingConfigValue'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '26', 'type': 'if_statement', 'children': ['27', '30']}; {'id': '27', 'type': 'comparison_operator', 'children': ['28', '29'], 'value': 'not in'}; {'id': '28', 'type': 'string', 'children': [], 'value': "'revision_file'"}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'client'}; {'id': '30', 'type': 'block', 'children': ['31']}; {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '36']}; {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'client'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'revision_file'}; {'id': '36', 'type': 'call', 'children': ['37', '40']}; {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'DEFAULT_REVISION_FILEPATH'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}; {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'client'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'key'}
|
Check the value of the config attributes.
|
def find_data(path, warn=True):
full_path = os.path.join(get_data_dir(), path)
if warn and not os.path.isfile(full_path):
for package in PACKAGES:
if path == package.path:
log.warn('%s doesn\'t exist. Run `cde data download` to get it.' % path)
break
return full_path
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'find_data'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'warn'}; {'id': '7', 'type': 'True', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '23', '57']}; {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'full_path'}; {'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': 'os'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '18', 'type': 'argument_list', 'children': ['19', '22']}; {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'get_data_dir'}; {'id': '21', 'type': 'argument_list', 'children': []}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '23', 'type': 'if_statement', 'children': ['24', '35']}; {'id': '24', 'type': 'boolean_operator', 'children': ['25', '26'], 'value': 'and'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'warn'}; {'id': '26', 'type': 'not_operator', 'children': ['27']}; {'id': '27', 'type': 'call', 'children': ['28', '33']}; {'id': '28', 'type': 'attribute', 'children': ['29', '32']}; {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'isfile'}; {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'full_path'}; {'id': '35', 'type': 'block', 'children': ['36']}; {'id': '36', 'type': 'for_statement', 'children': ['37', '38', '39']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'package'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'PACKAGES'}; {'id': '39', 'type': 'block', 'children': ['40']}; {'id': '40', 'type': 'if_statement', 'children': ['41', '46']}; {'id': '41', 'type': 'comparison_operator', 'children': ['42', '43'], 'value': '=='}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'package'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '46', 'type': 'block', 'children': ['47', '56']}; {'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': 'log'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'warn'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}; {'id': '53', 'type': 'binary_operator', 'children': ['54', '55'], 'value': '%'}; {'id': '54', 'type': 'string', 'children': [], 'value': "'%s doesn\\'t exist. Run `cde data download` to get it.'"}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '56', 'type': 'break_statement', 'children': []}; {'id': '57', 'type': 'return_statement', 'children': ['58']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'full_path'}
|
Return the absolute path to a data file within the data directory.
|
def clone(self, date=None, data=None, name=None):
name = name or self.name
data = data if data is not None else self.values()
ts = self.__class__(name)
ts._dtype = self._dtype
if date is None:
ts.make(self.keys(), data, raw=True)
else:
ts.make(date, data)
return ts
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'clone'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'date'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '10', 'type': 'None', 'children': []}; {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15', '23', '36', '45', '53', '83']}; {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '18', 'type': 'boolean_operator', 'children': ['19', '20'], 'value': 'or'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '26', 'type': 'conditional_expression', 'children': ['27', '28', '31'], 'value': 'if'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '28', 'type': 'comparison_operator', 'children': ['29', '30'], 'value': 'is not'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '30', 'type': 'None', 'children': []}; {'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': 'values'}; {'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': 'ts'}; {'id': '39', 'type': 'call', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': '__class__'}; {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '50']}; {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'ts'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': '_dtype'}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': '_dtype'}; {'id': '53', 'type': 'if_statement', 'children': ['54', '57', '73']}; {'id': '54', 'type': 'comparison_operator', 'children': ['55', '56'], 'value': 'is'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'date'}; {'id': '56', 'type': 'None', 'children': []}; {'id': '57', 'type': 'block', 'children': ['58']}; {'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': 'ts'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'make'}; {'id': '63', 'type': 'argument_list', 'children': ['64', '69', '70']}; {'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': 'keys'}; {'id': '68', 'type': 'argument_list', 'children': []}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '70', 'type': 'keyword_argument', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'raw'}; {'id': '72', 'type': 'True', 'children': []}; {'id': '73', 'type': 'else_clause', 'children': ['74']}; {'id': '74', 'type': 'block', 'children': ['75']}; {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'call', 'children': ['77', '80']}; {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'ts'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'make'}; {'id': '80', 'type': 'argument_list', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'date'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '83', 'type': 'return_statement', 'children': ['84']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'ts'}
|
Create a clone of timeseries
|
def eval(self, script, keys=[], args=[]):
return self.execute(b'EVAL', script, len(keys), *(keys + args))
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'eval'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'script'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '8', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '11', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '12', 'type': 'block', 'children': ['13']}; {'id': '13', 'type': 'return_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': 'execute'}; {'id': '18', 'type': 'argument_list', 'children': ['19', '20', '21', '25']}; {'id': '19', 'type': 'string', 'children': [], 'value': "b'EVAL'"}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'script'}; {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '25', 'type': 'list_splat', 'children': ['26']}; {'id': '26', 'type': '()', 'children': ['27']}; {'id': '27', 'type': 'binary_operator', 'children': ['28', '29'], 'value': '+'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'args'}
|
Execute a Lua script server side.
|
async def connect(self, connection):
if self._user_connected:
self._log.info('User is already connected!')
return
self._connection = connection
await self._connect()
self._user_connected = True
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'connect'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'connection'}; {'id': '6', 'type': 'block', 'children': ['7', '22', '28', '35']}; {'id': '7', 'type': 'if_statement', 'children': ['8', '11']}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': '_user_connected'}; {'id': '11', 'type': 'block', 'children': ['12', '21']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}; {'id': '13', 'type': 'call', 'children': ['14', '19']}; {'id': '14', 'type': 'attribute', 'children': ['15', '18']}; {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': '_log'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'string', 'children': [], 'value': "'User is already connected!'"}; {'id': '21', 'type': 'return_statement', 'children': []}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}; {'id': '23', 'type': 'assignment', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': '_connection'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'connection'}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}; {'id': '29', 'type': 'await', 'children': ['30']}; {'id': '30', 'type': 'call', 'children': ['31', '34']}; {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': '_connect'}; {'id': '34', 'type': 'argument_list', 'children': []}; {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '40']}; {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': '_user_connected'}; {'id': '40', 'type': 'True', 'children': []}
|
Connects to the specified given connection using the given auth key.
|
def do_metric_create_raw(mc, args):
try:
mc.metrics.create(**args.jsonbody)
except (osc_exc.ClientException, k_exc.HttpError) as he:
raise osc_exc.CommandError('%s\n%s' % (he.message, he.details))
else:
print('Successfully created metric')
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'do_metric_create_raw'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'mc'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '6', 'type': 'block', 'children': ['7']}; {'id': '7', 'type': 'try_statement', 'children': ['8', '21', '48']}; {'id': '8', 'type': 'block', 'children': ['9']}; {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'call', 'children': ['11', '16']}; {'id': '11', 'type': 'attribute', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'mc'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'metrics'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'create'}; {'id': '16', 'type': 'argument_list', 'children': ['17']}; {'id': '17', 'type': 'dictionary_splat', 'children': ['18']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'jsonbody'}; {'id': '21', 'type': 'except_clause', 'children': ['22', '32']}; {'id': '22', 'type': 'as_pattern', 'children': ['23', '30']}; {'id': '23', 'type': 'tuple', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'osc_exc'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'ClientException'}; {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'k_exc'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'HttpError'}; {'id': '30', 'type': 'as_pattern_target', 'children': ['31']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'he'}; {'id': '32', 'type': 'block', 'children': ['33']}; {'id': '33', 'type': 'raise_statement', 'children': ['34']}; {'id': '34', 'type': 'call', 'children': ['35', '38']}; {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'osc_exc'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'CommandError'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}; {'id': '39', 'type': 'binary_operator', 'children': ['40', '41'], 'value': '%'}; {'id': '40', 'type': 'string', 'children': [], 'value': "'%s\\n%s'"}; {'id': '41', 'type': 'tuple', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'he'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'he'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'details'}; {'id': '48', 'type': 'else_clause', 'children': ['49']}; {'id': '49', 'type': 'block', 'children': ['50']}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}; {'id': '51', 'type': 'call', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'string', 'children': [], 'value': "'Successfully created metric'"}
|
Create metric from raw json body.
|
def send_unsubscribe(self, dup, topics):
pkt = MqttPkt()
pktlen = 2 + sum([2+len(topic) for topic in topics])
pkt.command = NC.CMD_UNSUBSCRIBE | (dup << 3) | (1 << 1)
pkt.remaining_length = pktlen
ret = pkt.alloc()
if ret != NC.ERR_SUCCESS:
return ret
mid = self.mid_generate()
pkt.write_uint16(mid)
for topic in topics:
pkt.write_string(topic)
return self.packet_queue(pkt)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'send_unsubscribe'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'dup'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'topics'}; {'id': '7', 'type': 'block', 'children': ['8', '14', '32', '50', '56', '64', '73', '81', '88', '99']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'pkt'}; {'id': '11', 'type': 'call', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'MqttPkt'}; {'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': 'pktlen'}; {'id': '17', 'type': 'binary_operator', 'children': ['18', '19'], 'value': '+'}; {'id': '18', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'sum'}; {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'list_comprehension', 'children': ['23', '29']}; {'id': '23', 'type': 'binary_operator', 'children': ['24', '25'], 'value': '+'}; {'id': '24', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'topic'}; {'id': '29', 'type': 'for_in_clause', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'topic'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'topics'}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}; {'id': '33', 'type': 'assignment', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'pkt'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'command'}; {'id': '37', 'type': 'binary_operator', 'children': ['38', '46'], 'value': '|'}; {'id': '38', 'type': 'binary_operator', 'children': ['39', '42'], 'value': '|'}; {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'NC'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'CMD_UNSUBSCRIBE'}; {'id': '42', 'type': '()', 'children': ['43']}; {'id': '43', 'type': 'binary_operator', 'children': ['44', '45'], 'value': '<<'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'dup'}; {'id': '45', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '46', 'type': '()', 'children': ['47']}; {'id': '47', 'type': 'binary_operator', 'children': ['48', '49'], 'value': '<<'}; {'id': '48', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '49', 'type': 'integer', 'children': [], 'value': '1'}; {'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': 'pkt'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'remaining_length'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'pktlen'}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}; {'id': '57', 'type': 'assignment', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '59', 'type': 'call', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'pkt'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'alloc'}; {'id': '63', 'type': 'argument_list', 'children': []}; {'id': '64', 'type': 'if_statement', 'children': ['65', '70']}; {'id': '65', 'type': 'comparison_operator', 'children': ['66', '67'], 'value': '!='}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'NC'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'ERR_SUCCESS'}; {'id': '70', 'type': 'block', 'children': ['71']}; {'id': '71', 'type': 'return_statement', 'children': ['72']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'assignment', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'mid'}; {'id': '76', 'type': 'call', 'children': ['77', '80']}; {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'mid_generate'}; {'id': '80', 'type': 'argument_list', 'children': []}; {'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': 'pkt'}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'write_uint16'}; {'id': '86', 'type': 'argument_list', 'children': ['87']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'mid'}; {'id': '88', 'type': 'for_statement', 'children': ['89', '90', '91']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'topic'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'topics'}; {'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': 'pkt'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'write_string'}; {'id': '97', 'type': 'argument_list', 'children': ['98']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'topic'}; {'id': '99', 'type': 'return_statement', 'children': ['100']}; {'id': '100', 'type': 'call', 'children': ['101', '104']}; {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'packet_queue'}; {'id': '104', 'type': 'argument_list', 'children': ['105']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'pkt'}
|
Send unsubscribe COMMAND to server.
|
def run(self) -> None:
while not self.cleanup:
try:
result, test, additional_info = self.result_queue.get(timeout=1)
except queue.Empty:
continue
self.result_queue.task_done()
if result == TestState.serialization_failure:
test = self.tests[test]
warnings.warn("Serialization error: {} on test {}".format(
additional_info, test), SerializationWarning)
test(self)
else:
self.testsRun += 1
if result == TestState.success:
self.addSuccess(test)
elif result == TestState.failure:
self.addFailure(test, additional_info)
elif result == TestState.error:
self.addError(test, additional_info)
elif result == TestState.skipped:
self.addSkip(test, additional_info)
elif result == TestState.expected_failure:
self.addExpectedFailure(test, additional_info)
elif result == TestState.unexpected_success:
self.addUnexpectedSuccess(test)
else:
raise Exception("This is not a valid test type :", result)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'run'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'type', 'children': ['6']}; {'id': '6', 'type': 'None', 'children': []}; {'id': '7', 'type': 'block', 'children': ['8']}; {'id': '8', 'type': 'while_statement', 'children': ['9', '13']}; {'id': '9', 'type': 'not_operator', 'children': ['10']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'cleanup'}; {'id': '13', 'type': 'block', 'children': ['14', '38', '46']}; {'id': '14', 'type': 'try_statement', 'children': ['15', '32']}; {'id': '15', 'type': 'block', 'children': ['16']}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}; {'id': '17', 'type': 'assignment', 'children': ['18', '22']}; {'id': '18', 'type': 'pattern_list', 'children': ['19', '20', '21']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'test'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'additional_info'}; {'id': '22', 'type': 'call', 'children': ['23', '28']}; {'id': '23', 'type': 'attribute', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'result_queue'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}; {'id': '29', 'type': 'keyword_argument', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'timeout'}; {'id': '31', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '32', 'type': 'except_clause', 'children': ['33', '36']}; {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'queue'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'Empty'}; {'id': '36', 'type': 'block', 'children': ['37']}; {'id': '37', 'type': 'continue_statement', 'children': []}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}; {'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': 'result_queue'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'task_done'}; {'id': '45', 'type': 'argument_list', 'children': []}; {'id': '46', 'type': 'if_statement', 'children': ['47', '52', '80']}; {'id': '47', 'type': 'comparison_operator', 'children': ['48', '49'], 'value': '=='}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'TestState'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'serialization_failure'}; {'id': '52', 'type': 'block', 'children': ['53', '61', '75']}; {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'test'}; {'id': '56', 'type': 'subscript', 'children': ['57', '60']}; {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'tests'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'test'}; {'id': '61', 'type': 'expression_statement', 'children': ['62']}; {'id': '62', 'type': 'call', 'children': ['63', '66']}; {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'warnings'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'warn'}; {'id': '66', 'type': 'argument_list', 'children': ['67', '74']}; {'id': '67', 'type': 'call', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}; {'id': '69', 'type': 'string', 'children': [], 'value': '"Serialization error: {} on test {}"'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '71', 'type': 'argument_list', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'additional_info'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'test'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'SerializationWarning'}; {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'call', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'test'}; {'id': '78', 'type': 'argument_list', 'children': ['79']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '80', 'type': 'else_clause', 'children': ['81']}; {'id': '81', 'type': 'block', 'children': ['82', '88']}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}; {'id': '83', 'type': 'augmented_assignment', 'children': ['84', '87'], 'value': '+='}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'testsRun'}; {'id': '87', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '88', 'type': 'if_statement', 'children': ['89', '94', '102', '117', '132', '147', '162', '176']}; {'id': '89', 'type': 'comparison_operator', 'children': ['90', '91'], 'value': '=='}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'TestState'}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'success'}; {'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': 'self'}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'addSuccess'}; {'id': '100', 'type': 'argument_list', 'children': ['101']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'test'}; {'id': '102', 'type': 'elif_clause', 'children': ['103', '108']}; {'id': '103', 'type': 'comparison_operator', 'children': ['104', '105'], 'value': '=='}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'TestState'}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'failure'}; {'id': '108', 'type': 'block', 'children': ['109']}; {'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': 'self'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'addFailure'}; {'id': '114', 'type': 'argument_list', 'children': ['115', '116']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'test'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'additional_info'}; {'id': '117', 'type': 'elif_clause', 'children': ['118', '123']}; {'id': '118', 'type': 'comparison_operator', 'children': ['119', '120'], 'value': '=='}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '120', 'type': 'attribute', 'children': ['121', '122']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'TestState'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'error'}; {'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': 'self'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'addError'}; {'id': '129', 'type': 'argument_list', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'test'}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'additional_info'}; {'id': '132', 'type': 'elif_clause', 'children': ['133', '138']}; {'id': '133', 'type': 'comparison_operator', 'children': ['134', '135'], 'value': '=='}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '135', 'type': 'attribute', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'TestState'}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'skipped'}; {'id': '138', 'type': 'block', 'children': ['139']}; {'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': 'addSkip'}; {'id': '144', 'type': 'argument_list', 'children': ['145', '146']}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'test'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'additional_info'}; {'id': '147', 'type': 'elif_clause', 'children': ['148', '153']}; {'id': '148', 'type': 'comparison_operator', 'children': ['149', '150'], 'value': '=='}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '150', 'type': 'attribute', 'children': ['151', '152']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'TestState'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'expected_failure'}; {'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': 'self'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'addExpectedFailure'}; {'id': '159', 'type': 'argument_list', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'test'}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'additional_info'}; {'id': '162', 'type': 'elif_clause', 'children': ['163', '168']}; {'id': '163', 'type': 'comparison_operator', 'children': ['164', '165'], 'value': '=='}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '165', 'type': 'attribute', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'TestState'}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'unexpected_success'}; {'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': 'self'}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'addUnexpectedSuccess'}; {'id': '174', 'type': 'argument_list', 'children': ['175']}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'test'}; {'id': '176', 'type': 'else_clause', 'children': ['177']}; {'id': '177', 'type': 'block', 'children': ['178']}; {'id': '178', 'type': 'raise_statement', 'children': ['179']}; {'id': '179', 'type': 'call', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '181', 'type': 'argument_list', 'children': ['182', '183']}; {'id': '182', 'type': 'string', 'children': [], 'value': '"This is not a valid test type :"'}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'result'}
|
processes entries in the queue until told to stop
|
def run_track(track,
result_hosts=None,
crate_root=None,
output_fmt=None,
logfile_info=None,
logfile_result=None,
failfast=False,
sample_mode='reservoir'):
with Logger(output_fmt=output_fmt,
logfile_info=logfile_info,
logfile_result=logfile_result) as log:
executor = Executor(
track_dir=os.path.dirname(track),
log=log,
result_hosts=result_hosts,
crate_root=crate_root,
fail_fast=failfast,
sample_mode=sample_mode
)
error = executor.execute(toml.load(track))
if error:
sys.exit(1)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '26']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'run_track'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'track'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'result_hosts'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'crate_root'}; {'id': '10', 'type': 'None', 'children': []}; {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'output_fmt'}; {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'logfile_info'}; {'id': '16', 'type': 'None', 'children': []}; {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'logfile_result'}; {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'failfast'}; {'id': '22', 'type': 'False', 'children': []}; {'id': '23', 'type': 'default_parameter', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'sample_mode'}; {'id': '25', 'type': 'string', 'children': [], 'value': "'reservoir'"}; {'id': '26', 'type': 'block', 'children': ['27']}; {'id': '27', 'type': 'with_statement', 'children': ['28', '45']}; {'id': '28', 'type': 'with_clause', 'children': ['29']}; {'id': '29', 'type': 'with_item', 'children': ['30']}; {'id': '30', 'type': 'as_pattern', 'children': ['31', '43']}; {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'Logger'}; {'id': '33', 'type': 'argument_list', 'children': ['34', '37', '40']}; {'id': '34', 'type': 'keyword_argument', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'output_fmt'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'output_fmt'}; {'id': '37', 'type': 'keyword_argument', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'logfile_info'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'logfile_info'}; {'id': '40', 'type': 'keyword_argument', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'logfile_result'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'logfile_result'}; {'id': '43', 'type': 'as_pattern_target', 'children': ['44']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'log'}; {'id': '45', 'type': 'block', 'children': ['46', '77', '91']}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}; {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'executor'}; {'id': '49', 'type': 'call', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'Executor'}; {'id': '51', 'type': 'argument_list', 'children': ['52', '62', '65', '68', '71', '74']}; {'id': '52', 'type': 'keyword_argument', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'track_dir'}; {'id': '54', 'type': 'call', 'children': ['55', '60']}; {'id': '55', 'type': 'attribute', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'dirname'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'track'}; {'id': '62', 'type': 'keyword_argument', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'log'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'log'}; {'id': '65', 'type': 'keyword_argument', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'result_hosts'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'result_hosts'}; {'id': '68', 'type': 'keyword_argument', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'crate_root'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'crate_root'}; {'id': '71', 'type': 'keyword_argument', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'fail_fast'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'failfast'}; {'id': '74', 'type': 'keyword_argument', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'sample_mode'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'sample_mode'}; {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '80', 'type': 'call', 'children': ['81', '84']}; {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'executor'}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'execute'}; {'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': 'toml'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'load'}; {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'track'}; {'id': '91', 'type': 'if_statement', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'error'}; {'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': 'sys'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'exit'}; {'id': '99', 'type': 'argument_list', 'children': ['100']}; {'id': '100', 'type': 'integer', 'children': [], 'value': '1'}
|
Execute a track file
|
def restart(self, all=False):
if all:
data = {'type': self.type}
else:
data = {'ps': self.process}
r = self._h._http_resource(
method='POST',
resource=('apps', self.app.name, 'ps', 'restart'),
data=data
)
r.raise_for_status()
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'restart'}; {'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': 'all'}; {'id': '7', 'type': 'False', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '32', '59']}; {'id': '9', 'type': 'if_statement', 'children': ['10', '11', '21']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'all'}; {'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': 'data'}; {'id': '15', 'type': 'dictionary', 'children': ['16']}; {'id': '16', 'type': 'pair', 'children': ['17', '18']}; {'id': '17', 'type': 'string', 'children': [], 'value': "'type'"}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '21', 'type': 'else_clause', 'children': ['22']}; {'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': 'data'}; {'id': '26', 'type': 'dictionary', 'children': ['27']}; {'id': '27', 'type': 'pair', 'children': ['28', '29']}; {'id': '28', 'type': 'string', 'children': [], 'value': "'ps'"}; {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'process'}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}; {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'r'}; {'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': '_h'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': '_http_resource'}; {'id': '41', 'type': 'argument_list', 'children': ['42', '45', '56']}; {'id': '42', 'type': 'keyword_argument', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '44', 'type': 'string', 'children': [], 'value': "'POST'"}; {'id': '45', 'type': 'keyword_argument', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'resource'}; {'id': '47', 'type': 'tuple', 'children': ['48', '49', '54', '55']}; {'id': '48', 'type': 'string', 'children': [], 'value': "'apps'"}; {'id': '49', 'type': 'attribute', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'app'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '54', 'type': 'string', 'children': [], 'value': "'ps'"}; {'id': '55', 'type': 'string', 'children': [], 'value': "'restart'"}; {'id': '56', 'type': 'keyword_argument', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'data'}; {'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': 'r'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'raise_for_status'}; {'id': '64', 'type': 'argument_list', 'children': []}
|
Restarts the given process.
|
def set(self, option, value):
if self.config is None:
self.config = {}
self.config[option] = value
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'set'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'option'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '7', 'type': 'block', 'children': ['8', '21']}; {'id': '8', 'type': 'if_statement', 'children': ['9', '14']}; {'id': '9', 'type': 'comparison_operator', 'children': ['10', '13'], 'value': 'is'}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15']}; {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '20']}; {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '20', 'type': 'dictionary', 'children': []}; {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '28']}; {'id': '23', 'type': 'subscript', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'option'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'value'}
|
Sets an option to a value.
|
def remove_group(self, group):
if not isinstance(group, Group):
raise TypeError("group must be Group")
if group not in self.groups:
raise ValueError("Group doesn't exist / is not bound to this database.")
num_entries = len(group.entries)
for i in xrange(num_entries):
self.remove_entry(group.entries[0])
num_children = len(group.children)
for i in xrange(num_children):
self.remove_group(group.children[0])
group.parent.children.remove(group)
self.groups.remove(group)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'remove_group'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '6', 'type': 'block', 'children': ['7', '20', '32', '41', '59', '68', '86', '97']}; {'id': '7', 'type': 'if_statement', 'children': ['8', '14']}; {'id': '8', 'type': 'not_operator', 'children': ['9']}; {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '11', 'type': 'argument_list', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'Group'}; {'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': 'TypeError'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}; {'id': '19', 'type': 'string', 'children': [], 'value': '"group must be Group"'}; {'id': '20', 'type': 'if_statement', 'children': ['21', '26']}; {'id': '21', 'type': 'comparison_operator', 'children': ['22', '23'], 'value': 'not in'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'groups'}; {'id': '26', 'type': 'block', 'children': ['27']}; {'id': '27', 'type': 'raise_statement', 'children': ['28']}; {'id': '28', 'type': 'call', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}; {'id': '31', 'type': 'string', 'children': [], 'value': '"Group doesn\'t exist / is not bound to this database."'}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}; {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'num_entries'}; {'id': '35', 'type': 'call', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'entries'}; {'id': '41', 'type': 'for_statement', 'children': ['42', '43', '47']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '43', 'type': 'call', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'xrange'}; {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'num_entries'}; {'id': '47', 'type': 'block', 'children': ['48']}; {'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': 'self'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'remove_entry'}; {'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': 'group'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'entries'}; {'id': '58', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'assignment', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'num_children'}; {'id': '62', 'type': 'call', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}; {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'children'}; {'id': '68', 'type': 'for_statement', 'children': ['69', '70', '74']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '70', 'type': 'call', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'xrange'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'num_children'}; {'id': '74', 'type': 'block', 'children': ['75']}; {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'call', 'children': ['77', '80']}; {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'remove_group'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}; {'id': '81', 'type': 'subscript', 'children': ['82', '85']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'children'}; {'id': '85', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}; {'id': '87', 'type': 'call', 'children': ['88', '95']}; {'id': '88', 'type': 'attribute', 'children': ['89', '94']}; {'id': '89', 'type': 'attribute', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'children'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'remove'}; {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'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': 'self'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'groups'}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'remove'}; {'id': '104', 'type': 'argument_list', 'children': ['105']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'group'}
|
Remove the specified group.
|
def _custom_icon(self, name, **kwargs):
options = dict(_default_options, **kwargs)
if name in self.painters:
painter = self.painters[name]
return self._icon_by_painter(painter, options)
else:
return QIcon()
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_custom_icon'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '6', 'type': 'dictionary_splat_pattern', 'children': ['7']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '8', 'type': 'block', 'children': ['9', '18']}; {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'options'}; {'id': '12', 'type': 'call', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '14', 'type': 'argument_list', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': '_default_options'}; {'id': '16', 'type': 'dictionary_splat', 'children': ['17']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '18', 'type': 'if_statement', 'children': ['19', '24', '41']}; {'id': '19', 'type': 'comparison_operator', 'children': ['20', '21'], 'value': 'in'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'painters'}; {'id': '24', 'type': 'block', 'children': ['25', '33']}; {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'painter'}; {'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': 'painters'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '33', 'type': 'return_statement', 'children': ['34']}; {'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': '_icon_by_painter'}; {'id': '38', 'type': 'argument_list', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'painter'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'options'}; {'id': '41', 'type': 'else_clause', 'children': ['42']}; {'id': '42', 'type': 'block', 'children': ['43']}; {'id': '43', 'type': 'return_statement', 'children': ['44']}; {'id': '44', 'type': 'call', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'QIcon'}; {'id': '46', 'type': 'argument_list', 'children': []}
|
Return the custom icon corresponding to the given name.
|
def error(self, msg):
self._error = True
self._progress.printMsg('XML parse error: %s' % msg, error=True)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'error'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '6', 'type': 'block', 'children': ['7', '13']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '12']}; {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': '_error'}; {'id': '12', 'type': 'True', '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': 'self'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': '_progress'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'printMsg'}; {'id': '20', 'type': 'argument_list', 'children': ['21', '24']}; {'id': '21', 'type': 'binary_operator', 'children': ['22', '23'], 'value': '%'}; {'id': '22', 'type': 'string', 'children': [], 'value': "'XML parse error: %s'"}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '24', 'type': 'keyword_argument', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '26', 'type': 'True', 'children': []}
|
Callback run when a recoverable parsing error occurs
|
def fmt_cell(self, value, width, cell_formating, **text_formating):
strptrn = " {:" + '{:s}{:d}'.format(cell_formating.get('align', '<'), width) + "s} "
strptrn = self.fmt_text(strptrn, **text_formating)
return strptrn.format(value)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'fmt_cell'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'width'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'cell_formating'}; {'id': '8', 'type': 'dictionary_splat_pattern', 'children': ['9']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'text_formating'}; {'id': '10', 'type': 'block', 'children': ['11', '31', '42']}; {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'strptrn'}; {'id': '14', 'type': 'binary_operator', 'children': ['15', '30'], 'value': '+'}; {'id': '15', 'type': 'binary_operator', 'children': ['16', '17'], 'value': '+'}; {'id': '16', 'type': 'string', 'children': [], 'value': '" {:"'}; {'id': '17', 'type': 'call', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}; {'id': '19', 'type': 'string', 'children': [], 'value': "'{:s}{:d}'"}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '21', 'type': 'argument_list', 'children': ['22', '29']}; {'id': '22', 'type': 'call', 'children': ['23', '26']}; {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'cell_formating'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '26', 'type': 'argument_list', 'children': ['27', '28']}; {'id': '27', 'type': 'string', 'children': [], 'value': "'align'"}; {'id': '28', 'type': 'string', 'children': [], 'value': "'<'"}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'width'}; {'id': '30', 'type': 'string', 'children': [], 'value': '"s} "'}; {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'strptrn'}; {'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': 'fmt_text'}; {'id': '38', 'type': 'argument_list', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'strptrn'}; {'id': '40', 'type': 'dictionary_splat', 'children': ['41']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'text_formating'}; {'id': '42', 'type': 'return_statement', 'children': ['43']}; {'id': '43', 'type': 'call', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'strptrn'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'value'}
|
Format sigle table cell.
|
def _handle_template(self, token):
params = []
default = 1
self._push()
while self._tokens:
token = self._tokens.pop()
if isinstance(token, tokens.TemplateParamSeparator):
if not params:
name = self._pop()
param = self._handle_parameter(default)
params.append(param)
if not param.showkey:
default += 1
elif isinstance(token, tokens.TemplateClose):
if not params:
name = self._pop()
return Template(name, params)
else:
self._write(self._handle_token(token))
raise ParserError("_handle_template() missed a close token")
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_handle_template'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'token'}; {'id': '6', 'type': 'block', 'children': ['7', '11', '15', '21', '124']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '10', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '14', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'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': '_push'}; {'id': '20', 'type': 'argument_list', 'children': []}; {'id': '21', 'type': 'while_statement', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': '_tokens'}; {'id': '25', 'type': 'block', 'children': ['26', '36']}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}; {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'token'}; {'id': '29', 'type': 'call', 'children': ['30', '35']}; {'id': '30', 'type': 'attribute', 'children': ['31', '34']}; {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': '_tokens'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '35', 'type': 'argument_list', 'children': []}; {'id': '36', 'type': 'if_statement', 'children': ['37', '44', '83', '110']}; {'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': 'token'}; {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'tokens'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'TemplateParamSeparator'}; {'id': '44', 'type': 'block', 'children': ['45', '57', '66', '73']}; {'id': '45', 'type': 'if_statement', 'children': ['46', '48']}; {'id': '46', 'type': 'not_operator', 'children': ['47']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'params'}; {'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': 'name'}; {'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': '_pop'}; {'id': '56', 'type': 'argument_list', 'children': []}; {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'param'}; {'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': '_handle_parameter'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}; {'id': '67', 'type': 'call', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'param'}; {'id': '73', 'type': 'if_statement', 'children': ['74', '78']}; {'id': '74', 'type': 'not_operator', 'children': ['75']}; {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'param'}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'showkey'}; {'id': '78', 'type': 'block', 'children': ['79']}; {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'augmented_assignment', 'children': ['81', '82'], 'value': '+='}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '82', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '83', 'type': 'elif_clause', 'children': ['84', '91']}; {'id': '84', 'type': 'call', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '86', 'type': 'argument_list', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'token'}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'tokens'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'TemplateClose'}; {'id': '91', 'type': 'block', 'children': ['92', '104']}; {'id': '92', 'type': 'if_statement', 'children': ['93', '95']}; {'id': '93', 'type': 'not_operator', 'children': ['94']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'params'}; {'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': 'name'}; {'id': '99', 'type': 'call', 'children': ['100', '103']}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': '_pop'}; {'id': '103', 'type': 'argument_list', 'children': []}; {'id': '104', 'type': 'return_statement', 'children': ['105']}; {'id': '105', 'type': 'call', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'Template'}; {'id': '107', 'type': 'argument_list', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '110', 'type': 'else_clause', 'children': ['111']}; {'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': 'self'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': '_write'}; {'id': '117', 'type': 'argument_list', 'children': ['118']}; {'id': '118', 'type': 'call', 'children': ['119', '122']}; {'id': '119', 'type': 'attribute', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '121', 'type': 'identifier', 'children': [], 'value': '_handle_token'}; {'id': '122', 'type': 'argument_list', 'children': ['123']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'token'}; {'id': '124', 'type': 'raise_statement', 'children': ['125']}; {'id': '125', 'type': 'call', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'ParserError'}; {'id': '127', 'type': 'argument_list', 'children': ['128']}; {'id': '128', 'type': 'string', 'children': [], 'value': '"_handle_template() missed a close token"'}
|
Handle a case where a template is at the head of the tokens.
|
def htmlize_list(items):
out = ["<ul>"]
for item in items:
out.append("<li>" + htmlize(item) + "</li>")
out.append("</ul>")
return "\n".join(out)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'htmlize_list'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '5', 'type': 'block', 'children': ['6', '11', '29', '36']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '9', 'type': 'list', 'children': ['10'], 'value': '["<ul>"]'}; {'id': '10', 'type': 'string', 'children': [], 'value': '"<ul>"'}; {'id': '11', 'type': 'for_statement', 'children': ['12', '13', '14']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '14', 'type': 'block', 'children': ['15']}; {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'call', 'children': ['17', '20']}; {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}; {'id': '21', 'type': 'binary_operator', 'children': ['22', '28'], 'value': '+'}; {'id': '22', 'type': 'binary_operator', 'children': ['23', '24'], 'value': '+'}; {'id': '23', 'type': 'string', 'children': [], 'value': '"<li>"'}; {'id': '24', 'type': 'call', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'htmlize'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '28', 'type': 'string', 'children': [], 'value': '"</li>"'}; {'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': 'out'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}; {'id': '35', 'type': 'string', 'children': [], 'value': '"</ul>"'}; {'id': '36', 'type': 'return_statement', 'children': ['37']}; {'id': '37', 'type': 'call', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}; {'id': '39', 'type': 'string', 'children': [], 'value': '"\\n"'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'out'}
|
Turn a python list into an html list.
|
def _dequantize(q, params):
if not params.quantize:
return q
return tf.to_float(tf.bitcast(q, tf.int16)) * params.quantization_scale
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_dequantize'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'q'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '6', 'type': 'block', 'children': ['7', '15']}; {'id': '7', 'type': 'if_statement', 'children': ['8', '12']}; {'id': '8', 'type': 'not_operator', 'children': ['9']}; {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'quantize'}; {'id': '12', 'type': 'block', 'children': ['13']}; {'id': '13', 'type': 'return_statement', 'children': ['14']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'q'}; {'id': '15', 'type': 'return_statement', 'children': ['16']}; {'id': '16', 'type': 'binary_operator', 'children': ['17', '31'], 'value': '*'}; {'id': '17', 'type': 'call', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'tf'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'to_float'}; {'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': 'tf'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'bitcast'}; {'id': '26', 'type': 'argument_list', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'q'}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'tf'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'int16'}; {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'quantization_scale'}
|
Dequantize q according to params.
|
def create_with_virtualenv(self, interpreter, virtualenv_options):
args = ['virtualenv', '--python', interpreter, self.env_path]
args.extend(virtualenv_options)
if not self.pip_installed:
args.insert(3, '--no-pip')
try:
helpers.logged_exec(args)
self.env_bin_path = os.path.join(self.env_path, 'bin')
except FileNotFoundError as error:
logger.error('Virtualenv is not installed. It is needed to create a virtualenv with '
'a different python version than fades (got {})'.format(error))
raise FadesError('virtualenv not found')
except helpers.ExecutionError as error:
error.dump_to_log(logger)
raise FadesError('virtualenv could not be run')
except Exception as error:
logger.exception("Error creating virtualenv: %s", error)
raise FadesError('General error while running virtualenv')
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'create_with_virtualenv'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'interpreter'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'virtualenv_options'}; {'id': '7', 'type': 'block', 'children': ['8', '18', '25', '39']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '11', 'type': 'list', 'children': ['12', '13', '14', '15'], 'value': "['virtualenv', '--python', interpreter, self.env_path]"}; {'id': '12', 'type': 'string', 'children': [], 'value': "'virtualenv'"}; {'id': '13', 'type': 'string', 'children': [], 'value': "'--python'"}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'interpreter'}; {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'env_path'}; {'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': 'args'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'extend'}; {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'virtualenv_options'}; {'id': '25', 'type': 'if_statement', 'children': ['26', '30']}; {'id': '26', 'type': 'not_operator', 'children': ['27']}; {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'pip_installed'}; {'id': '30', 'type': 'block', 'children': ['31']}; {'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': 'args'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'insert'}; {'id': '36', 'type': 'argument_list', 'children': ['37', '38']}; {'id': '37', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '38', 'type': 'string', 'children': [], 'value': "'--no-pip'"}; {'id': '39', 'type': 'try_statement', 'children': ['40', '64', '89', '109']}; {'id': '40', 'type': 'block', 'children': ['41', '48']}; {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'call', 'children': ['43', '46']}; {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'helpers'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'logged_exec'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}; {'id': '49', 'type': 'assignment', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'env_bin_path'}; {'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': 'join'}; {'id': '59', 'type': 'argument_list', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'env_path'}; {'id': '63', 'type': 'string', 'children': [], 'value': "'bin'"}; {'id': '64', 'type': 'except_clause', 'children': ['65', '69']}; {'id': '65', 'type': 'as_pattern', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'FileNotFoundError'}; {'id': '67', 'type': 'as_pattern_target', 'children': ['68']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '69', 'type': 'block', 'children': ['70', '84']}; {'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': 'logger'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'call', 'children': ['77', '82']}; {'id': '77', 'type': 'attribute', 'children': ['78', '81']}; {'id': '78', 'type': 'concatenated_string', 'children': ['79', '80']}; {'id': '79', 'type': 'string', 'children': [], 'value': "'Virtualenv is not installed. It is needed to create a virtualenv with '"}; {'id': '80', 'type': 'string', 'children': [], 'value': "'a different python version than fades (got {})'"}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '84', 'type': 'raise_statement', 'children': ['85']}; {'id': '85', 'type': 'call', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'FadesError'}; {'id': '87', 'type': 'argument_list', 'children': ['88']}; {'id': '88', 'type': 'string', 'children': [], 'value': "'virtualenv not found'"}; {'id': '89', 'type': 'except_clause', 'children': ['90', '96']}; {'id': '90', 'type': 'as_pattern', 'children': ['91', '94']}; {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'helpers'}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'ExecutionError'}; {'id': '94', 'type': 'as_pattern_target', 'children': ['95']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '96', 'type': 'block', 'children': ['97', '104']}; {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'call', 'children': ['99', '102']}; {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'dump_to_log'}; {'id': '102', 'type': 'argument_list', 'children': ['103']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '104', 'type': 'raise_statement', 'children': ['105']}; {'id': '105', 'type': 'call', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'FadesError'}; {'id': '107', 'type': 'argument_list', 'children': ['108']}; {'id': '108', 'type': 'string', 'children': [], 'value': "'virtualenv could not be run'"}; {'id': '109', 'type': 'except_clause', 'children': ['110', '114']}; {'id': '110', 'type': 'as_pattern', 'children': ['111', '112']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '112', 'type': 'as_pattern_target', 'children': ['113']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '114', 'type': 'block', 'children': ['115', '123']}; {'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': 'logger'}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'exception'}; {'id': '120', 'type': 'argument_list', 'children': ['121', '122']}; {'id': '121', 'type': 'string', 'children': [], 'value': '"Error creating virtualenv: %s"'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '123', 'type': 'raise_statement', 'children': ['124']}; {'id': '124', 'type': 'call', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'FadesError'}; {'id': '126', 'type': 'argument_list', 'children': ['127']}; {'id': '127', 'type': 'string', 'children': [], 'value': "'General error while running virtualenv'"}
|
Create a virtualenv using the virtualenv lib.
|
def cyan(cls):
"Make the text foreground color cyan."
wAttributes = cls._get_text_attributes()
wAttributes &= ~win32.FOREGROUND_MASK
wAttributes |= win32.FOREGROUND_CYAN
cls._set_text_attributes(wAttributes)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'cyan'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '5', 'type': 'block', 'children': ['6', '8', '16', '23', '29']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'string', 'children': [], 'value': '"Make the text foreground color cyan."'}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'wAttributes'}; {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': '_get_text_attributes'}; {'id': '15', 'type': 'argument_list', 'children': []}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}; {'id': '17', 'type': 'augmented_assignment', 'children': ['18', '19'], 'value': '&='}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'wAttributes'}; {'id': '19', 'type': 'unary_operator', 'children': ['20'], 'value': '~'}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'win32'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'FOREGROUND_MASK'}; {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'augmented_assignment', 'children': ['25', '26'], 'value': '|='}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'wAttributes'}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'win32'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'FOREGROUND_CYAN'}; {'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': 'cls'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': '_set_text_attributes'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'wAttributes'}
|
Make the text foreground color cyan.
|
def restore_initial_state(self):
self.list.clear()
self.is_visible = False
widgets = self.widgets_by_path
if not self.edit.clicked_outside:
for path in self.initial_cursors:
cursor = self.initial_cursors[path]
if path in widgets:
self.set_editor_cursor(widgets[path], cursor)
if self.initial_widget in self.paths_by_widget:
index = self.paths.index(self.initial_path)
self.sig_goto_file.emit(index)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'restore_initial_state'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '14', '20', '26']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'call', 'children': ['8', '13']}; {'id': '8', 'type': 'attribute', 'children': ['9', '12']}; {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'clear'}; {'id': '13', 'type': 'argument_list', 'children': []}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}; {'id': '15', 'type': 'assignment', 'children': ['16', '19']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'is_visible'}; {'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': 'widgets'}; {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'widgets_by_path'}; {'id': '26', 'type': 'if_statement', 'children': ['27', '33']}; {'id': '27', 'type': 'not_operator', 'children': ['28']}; {'id': '28', 'type': 'attribute', 'children': ['29', '32']}; {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'edit'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'clicked_outside'}; {'id': '33', 'type': 'block', 'children': ['34', '63']}; {'id': '34', 'type': 'for_statement', 'children': ['35', '36', '39']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'initial_cursors'}; {'id': '39', 'type': 'block', 'children': ['40', '48']}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}; {'id': '41', 'type': 'assignment', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'cursor'}; {'id': '43', 'type': 'subscript', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'initial_cursors'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '48', 'type': 'if_statement', 'children': ['49', '52']}; {'id': '49', 'type': 'comparison_operator', 'children': ['50', '51'], 'value': 'in'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'widgets'}; {'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': 'self'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'set_editor_cursor'}; {'id': '58', 'type': 'argument_list', 'children': ['59', '62']}; {'id': '59', 'type': 'subscript', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'widgets'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'cursor'}; {'id': '63', 'type': 'if_statement', 'children': ['64', '71']}; {'id': '64', 'type': 'comparison_operator', 'children': ['65', '68'], 'value': 'in'}; {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'initial_widget'}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'paths_by_widget'}; {'id': '71', 'type': 'block', 'children': ['72', '85']}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}; {'id': '73', 'type': 'assignment', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '75', 'type': 'call', 'children': ['76', '81']}; {'id': '76', 'type': 'attribute', 'children': ['77', '80']}; {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'paths'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'initial_path'}; {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'call', 'children': ['87', '92']}; {'id': '87', 'type': 'attribute', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'sig_goto_file'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'emit'}; {'id': '92', 'type': 'argument_list', 'children': ['93']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'index'}
|
Restores initial cursors and initial active editor.
|
def _stop_process(p, name):
if p.poll() is not None:
print("{} is already stopped.".format(name))
return
p.terminate()
time.sleep(0.1)
if p.poll() is not None:
print("{} is terminated.".format(name))
return
p.kill()
print("{} is killed.".format(name))
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_stop_process'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '6', 'type': 'block', 'children': ['7', '27', '33', '40', '60', '66']}; {'id': '7', 'type': 'if_statement', 'children': ['8', '15']}; {'id': '8', 'type': 'comparison_operator', 'children': ['9', '14'], 'value': 'is not'}; {'id': '9', 'type': 'call', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'poll'}; {'id': '13', 'type': 'argument_list', 'children': []}; {'id': '14', 'type': 'None', 'children': []}; {'id': '15', 'type': 'block', 'children': ['16', '26']}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}; {'id': '17', 'type': 'call', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'call', 'children': ['21', '24']}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'string', 'children': [], 'value': '"{} is already stopped."'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '26', 'type': 'return_statement', 'children': []}; {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'call', 'children': ['29', '32']}; {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'terminate'}; {'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': 'time'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'sleep'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}; {'id': '39', 'type': 'float', 'children': [], 'value': '0.1'}; {'id': '40', 'type': 'if_statement', 'children': ['41', '48']}; {'id': '41', 'type': 'comparison_operator', 'children': ['42', '47'], 'value': 'is not'}; {'id': '42', 'type': 'call', 'children': ['43', '46']}; {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'poll'}; {'id': '46', 'type': 'argument_list', 'children': []}; {'id': '47', 'type': 'None', 'children': []}; {'id': '48', 'type': 'block', 'children': ['49', '59']}; {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'call', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}; {'id': '53', 'type': 'call', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}; {'id': '55', 'type': 'string', 'children': [], 'value': '"{} is terminated."'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '59', 'type': 'return_statement', 'children': []}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}; {'id': '61', 'type': 'call', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'kill'}; {'id': '65', 'type': 'argument_list', 'children': []}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}; {'id': '67', 'type': 'call', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '69', 'type': 'argument_list', 'children': ['70']}; {'id': '70', 'type': 'call', 'children': ['71', '74']}; {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'string', 'children': [], 'value': '"{} is killed."'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '74', 'type': 'argument_list', 'children': ['75']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'name'}
|
Stop process, by applying terminate and kill.
|
def render(self, view, context=None):
return self.runtime.render(self, view, context)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'render'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'view'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'context'}; {'id': '8', 'type': 'None', 'children': []}; {'id': '9', 'type': 'block', 'children': ['10']}; {'id': '10', 'type': 'return_statement', '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': 'runtime'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'render'}; {'id': '17', 'type': 'argument_list', 'children': ['18', '19', '20']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'view'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'context'}
|
Render `view` with this block's runtime and the supplied `context`
|
def _has_bcftools_germline_stats(data):
stats_file = tz.get_in(["summary", "qc"], data)
if isinstance(stats_file, dict):
stats_file = tz.get_in(["variants", "base"], stats_file)
if not stats_file:
stats_file = ""
return stats_file.find("bcftools_stats_germline") > 0
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_has_bcftools_germline_stats'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '5', 'type': 'block', 'children': ['6', '18', '37', '45']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'stats_file'}; {'id': '9', 'type': 'call', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'tz'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'get_in'}; {'id': '13', 'type': 'argument_list', 'children': ['14', '17']}; {'id': '14', 'type': 'list', 'children': ['15', '16'], 'value': '["summary", "qc"]'}; {'id': '15', 'type': 'string', 'children': [], 'value': '"summary"'}; {'id': '16', 'type': 'string', 'children': [], 'value': '"qc"'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '18', 'type': 'if_statement', 'children': ['19', '24']}; {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '21', 'type': 'argument_list', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'stats_file'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'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': 'stats_file'}; {'id': '28', 'type': 'call', 'children': ['29', '32']}; {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'tz'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'get_in'}; {'id': '32', 'type': 'argument_list', 'children': ['33', '36']}; {'id': '33', 'type': 'list', 'children': ['34', '35'], 'value': '["variants", "base"]'}; {'id': '34', 'type': 'string', 'children': [], 'value': '"variants"'}; {'id': '35', 'type': 'string', 'children': [], 'value': '"base"'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'stats_file'}; {'id': '37', 'type': 'if_statement', 'children': ['38', '40']}; {'id': '38', 'type': 'not_operator', 'children': ['39']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'stats_file'}; {'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': 'stats_file'}; {'id': '44', 'type': 'string', 'children': [], 'value': '""'}; {'id': '45', 'type': 'return_statement', 'children': ['46']}; {'id': '46', 'type': 'comparison_operator', 'children': ['47', '53'], 'value': '>'}; {'id': '47', 'type': 'call', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'stats_file'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'find'}; {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'string', 'children': [], 'value': '"bcftools_stats_germline"'}; {'id': '53', 'type': 'integer', 'children': [], 'value': '0'}
|
Check for the presence of a germline stats file, CWL compatible.
|
def delete(self, key):
validate_is_bytes(key)
self.root_hash = self._set(self.root_hash, encode_to_bin(key), b'')
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'delete'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '6', 'type': 'block', 'children': ['7', '12']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'call', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'validate_is_bytes'}; {'id': '10', 'type': 'argument_list', 'children': ['11']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}; {'id': '13', 'type': 'assignment', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'root_hash'}; {'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': '_set'}; {'id': '21', 'type': 'argument_list', 'children': ['22', '25', '29']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'root_hash'}; {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'encode_to_bin'}; {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '29', 'type': 'string', 'children': [], 'value': "b''"}
|
Equals to setting the value to None
|
def map(self, fn, *seq):
"Perform a map operation distributed among the workers. Will "
"block until done."
results = Queue()
args = zip(*seq)
for seq in args:
j = SimpleJob(results, fn, seq)
self.put(j)
r = []
for i in range(len(list(args))):
r.append(results.get())
return r
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'map'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'fn'}; {'id': '6', 'type': 'list_splat_pattern', 'children': ['7']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '8', 'type': 'block', 'children': ['9', '11', '13', '19', '27', '47', '51', '75']}; {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'string', 'children': [], 'value': '"Perform a map operation distributed among the workers. Will "'}; {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'string', 'children': [], 'value': '"block until done."'}; {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '16', 'type': 'call', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'Queue'}; {'id': '18', 'type': 'argument_list', 'children': []}; {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '22', 'type': 'call', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}; {'id': '25', 'type': 'list_splat', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '27', 'type': 'for_statement', 'children': ['28', '29', '30']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '30', 'type': 'block', 'children': ['31', '40']}; {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '34', 'type': 'call', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'SimpleJob'}; {'id': '36', 'type': 'argument_list', 'children': ['37', '38', '39']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'fn'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'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': 'self'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'put'}; {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'assignment', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '50', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '51', 'type': 'for_statement', 'children': ['52', '53', '63']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '53', 'type': 'call', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'call', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}; {'id': '59', 'type': 'call', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '61', 'type': 'argument_list', 'children': ['62']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '63', 'type': 'block', 'children': ['64']}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}; {'id': '65', 'type': 'call', 'children': ['66', '69']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '69', 'type': 'argument_list', 'children': ['70']}; {'id': '70', 'type': 'call', 'children': ['71', '74']}; {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '74', 'type': 'argument_list', 'children': []}; {'id': '75', 'type': 'return_statement', 'children': ['76']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'r'}
|
Perform a map operation distributed among the workers. Will
|
def _processDDL(self):
sql_statements = self._generateDDL()
logging.info('Generating sqllite tables')
for stmt in sql_statements:
c = self.conn.cursor()
c.execute(stmt)
self.conn.commit()
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_processDDL'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '14', '21']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'sql_statements'}; {'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': '_generateDDL'}; {'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': 'logging'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'string', 'children': [], 'value': "'Generating sqllite tables'"}; {'id': '21', 'type': 'for_statement', 'children': ['22', '23', '24']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'sql_statements'}; {'id': '24', 'type': 'block', 'children': ['25', '35', '42']}; {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '28', 'type': 'call', 'children': ['29', '34']}; {'id': '29', 'type': 'attribute', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'conn'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'cursor'}; {'id': '34', 'type': 'argument_list', 'children': []}; {'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': 'c'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'execute'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'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': 'conn'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'commit'}; {'id': '49', 'type': 'argument_list', 'children': []}
|
Generate and process table SQL, SQLLite version
|
def relevant_rules_for_match(self, action, subject):
matches = []
for rule in self.rules:
rule.expanded_actions = self.expand_actions(rule.actions)
if rule.is_relevant(action, subject):
matches.append(rule)
return self.optimize(matches[::-1])
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'relevant_rules_for_match'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'subject'}; {'id': '7', 'type': 'block', 'children': ['8', '12', '47']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'matches'}; {'id': '11', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '12', 'type': 'for_statement', 'children': ['13', '14', '17']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'rule'}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'rules'}; {'id': '17', 'type': 'block', 'children': ['18', '31']}; {'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': 'rule'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'expanded_actions'}; {'id': '23', 'type': 'call', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'expand_actions'}; {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'rule'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'actions'}; {'id': '31', 'type': 'if_statement', 'children': ['32', '39']}; {'id': '32', 'type': 'call', 'children': ['33', '36']}; {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'rule'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'is_relevant'}; {'id': '36', 'type': 'argument_list', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'subject'}; {'id': '39', 'type': 'block', 'children': ['40']}; {'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': 'matches'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'rule'}; {'id': '47', 'type': 'return_statement', 'children': ['48']}; {'id': '48', 'type': 'call', 'children': ['49', '52']}; {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'optimize'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}; {'id': '53', 'type': 'subscript', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'matches'}; {'id': '55', 'type': 'slice', 'children': ['56', '57', '58']}; {'id': '56', 'type': 'colon', 'children': []}; {'id': '57', 'type': 'colon', 'children': []}; {'id': '58', 'type': 'unary_operator', 'children': ['59'], 'value': '-'}; {'id': '59', 'type': 'integer', 'children': [], 'value': '1'}
|
retrive match action and subject
|
def _calculate_dispersion(X: Union[pd.DataFrame, np.ndarray], labels: np.ndarray, centroids: np.ndarray) -> float:
disp = np.sum(np.sum([np.abs(inst - centroids[label]) ** 2 for inst, label in zip(X, labels)]))
return disp
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '30', '32']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_calculate_dispersion'}; {'id': '3', 'type': 'parameters', 'children': ['4', '18', '24']}; {'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '6', 'type': 'type', 'children': ['7']}; {'id': '7', 'type': 'generic_type', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'Union'}; {'id': '9', 'type': 'type_parameter', 'children': ['10', '14']}; {'id': '10', 'type': 'type', 'children': ['11']}; {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'pd'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'DataFrame'}; {'id': '14', 'type': 'type', 'children': ['15']}; {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'ndarray'}; {'id': '18', 'type': 'typed_parameter', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'labels'}; {'id': '20', 'type': 'type', 'children': ['21']}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'ndarray'}; {'id': '24', 'type': 'typed_parameter', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'centroids'}; {'id': '26', 'type': 'type', 'children': ['27']}; {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'ndarray'}; {'id': '30', 'type': 'type', 'children': ['31']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '32', 'type': 'block', 'children': ['33', '68']}; {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'disp'}; {'id': '36', 'type': 'call', 'children': ['37', '40']}; {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'sum'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}; {'id': '41', 'type': 'call', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'sum'}; {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'list_comprehension', 'children': ['47', '59']}; {'id': '47', 'type': 'binary_operator', 'children': ['48', '58'], 'value': '**'}; {'id': '48', 'type': 'call', 'children': ['49', '52']}; {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'abs'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}; {'id': '53', 'type': 'binary_operator', 'children': ['54', '55'], 'value': '-'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'inst'}; {'id': '55', 'type': 'subscript', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'centroids'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '58', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '59', 'type': 'for_in_clause', 'children': ['60', '63']}; {'id': '60', 'type': 'pattern_list', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'inst'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '63', 'type': 'call', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '65', 'type': 'argument_list', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'labels'}; {'id': '68', 'type': 'return_statement', 'children': ['69']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'disp'}
|
Calculate the dispersion between actual points and their assigned centroids
|
def charge(self, data):
token = data.get("token", self._response["token"])
data = {
"token": token,
"confirm_token": data.get("confirm_token")
}
return self._process('opr/charge', data)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'charge'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '6', 'type': 'block', 'children': ['7', '21', '36']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'token'}; {'id': '10', 'type': 'call', 'children': ['11', '14']}; {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '14', 'type': 'argument_list', 'children': ['15', '16']}; {'id': '15', 'type': 'string', 'children': [], 'value': '"token"'}; {'id': '16', 'type': 'subscript', 'children': ['17', '20']}; {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': '_response'}; {'id': '20', 'type': 'string', 'children': [], 'value': '"token"'}; {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '24', 'type': 'dictionary', 'children': ['25', '28']}; {'id': '25', 'type': 'pair', 'children': ['26', '27']}; {'id': '26', 'type': 'string', 'children': [], 'value': '"token"'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'token'}; {'id': '28', 'type': 'pair', 'children': ['29', '30']}; {'id': '29', 'type': 'string', 'children': [], 'value': '"confirm_token"'}; {'id': '30', 'type': 'call', 'children': ['31', '34']}; {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}; {'id': '35', 'type': 'string', 'children': [], 'value': '"confirm_token"'}; {'id': '36', 'type': 'return_statement', 'children': ['37']}; {'id': '37', 'type': 'call', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': '_process'}; {'id': '41', 'type': 'argument_list', 'children': ['42', '43']}; {'id': '42', 'type': 'string', 'children': [], 'value': "'opr/charge'"}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'data'}
|
Second stage of an OPR request
|
def getDefaultParList(self):
if self.filename is None:
self.filename = self.getDefaultSaveFilename(stub=True)
return copy.deepcopy(self.__paramList)
tmpObj = ConfigObjPars(self.filename, associatedPkg=self.__assocPkg,
setAllToDefaults=True, strict=False)
return tmpObj.getParList()
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'getDefaultParList'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '35', '55']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '12']}; {'id': '7', 'type': 'comparison_operator', 'children': ['8', '11'], 'value': 'is'}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'block', 'children': ['13', '26']}; {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '18']}; {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '18', 'type': 'call', 'children': ['19', '22']}; {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'getDefaultSaveFilename'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}; {'id': '23', 'type': 'keyword_argument', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'stub'}; {'id': '25', 'type': 'True', 'children': []}; {'id': '26', 'type': 'return_statement', 'children': ['27']}; {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'deepcopy'}; {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': '__paramList'}; {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'tmpObj'}; {'id': '38', 'type': 'call', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'ConfigObjPars'}; {'id': '40', 'type': 'argument_list', 'children': ['41', '44', '49', '52']}; {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '44', 'type': 'keyword_argument', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'associatedPkg'}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': '__assocPkg'}; {'id': '49', 'type': 'keyword_argument', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'setAllToDefaults'}; {'id': '51', 'type': 'True', 'children': []}; {'id': '52', 'type': 'keyword_argument', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'strict'}; {'id': '54', 'type': 'False', 'children': []}; {'id': '55', 'type': 'return_statement', 'children': ['56']}; {'id': '56', 'type': 'call', 'children': ['57', '60']}; {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'tmpObj'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'getParList'}; {'id': '60', 'type': 'argument_list', 'children': []}
|
Return a par list just like ours, but with all default values.
|
def between_or_equal_to(y, z):
return _combinable(lambda x: (y <= x <= z) or _equal_or_float_equal(x, y) or _equal_or_float_equal(x, z))
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'between_or_equal_to'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'z'}; {'id': '6', 'type': 'block', 'children': ['7']}; {'id': '7', 'type': 'return_statement', 'children': ['8']}; {'id': '8', 'type': 'call', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': '_combinable'}; {'id': '10', 'type': 'argument_list', 'children': ['11']}; {'id': '11', 'type': 'lambda', 'children': ['12', '14']}; {'id': '12', 'type': 'lambda_parameters', 'children': ['13']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '14', 'type': 'boolean_operator', 'children': ['15', '26'], 'value': 'or'}; {'id': '15', 'type': 'boolean_operator', 'children': ['16', '21'], 'value': 'or'}; {'id': '16', 'type': '()', 'children': ['17']}; {'id': '17', 'type': 'comparison_operator', 'children': ['18', '19', '20'], 'value': '<='}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'z'}; {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': '_equal_or_float_equal'}; {'id': '23', 'type': 'argument_list', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '26', 'type': 'call', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': '_equal_or_float_equal'}; {'id': '28', 'type': 'argument_list', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'z'}
|
Greater than or equal to y and less than or equal to z.
|
def load_config(args, config_path=".inlineplz.yml"):
config = {}
try:
with open(config_path) as configfile:
config = yaml.safe_load(configfile) or {}
if config:
print("Loaded config from {}".format(config_path))
pprint.pprint(config)
except (IOError, OSError, yaml.parser.ParserError):
traceback.print_exc()
args = update_from_config(args, config)
args.ignore_paths = args.__dict__.get("ignore_paths") or [
"node_modules",
".git",
".tox",
"godeps",
"vendor",
"site-packages",
"venv",
".env",
"spec",
"migrate",
"bin",
"fixtures",
"cassettes",
".cache",
".idea",
".pytest_cache",
"__pycache__",
"dist",
]
if config_path != ".inlineplz.yml":
return args
if args.config_dir and not config:
new_config_path = os.path.join(args.config_dir, config_path)
if os.path.exists(new_config_path):
return load_config(args, new_config_path)
return args
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'load_config'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'config_path'}; {'id': '7', 'type': 'string', 'children': [], 'value': '".inlineplz.yml"'}; {'id': '8', 'type': 'block', 'children': ['9', '13', '73', '81', '114', '121', '159']}; {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '12', 'type': 'dictionary', 'children': []}; {'id': '13', 'type': 'try_statement', 'children': ['14', '57']}; {'id': '14', 'type': 'block', 'children': ['15']}; {'id': '15', 'type': 'with_statement', 'children': ['16', '25']}; {'id': '16', 'type': 'with_clause', 'children': ['17']}; {'id': '17', 'type': 'with_item', 'children': ['18']}; {'id': '18', 'type': 'as_pattern', 'children': ['19', '23']}; {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'config_path'}; {'id': '23', 'type': 'as_pattern_target', 'children': ['24']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'configfile'}; {'id': '25', 'type': 'block', 'children': ['26', '37']}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}; {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '29', 'type': 'boolean_operator', 'children': ['30', '36'], 'value': 'or'}; {'id': '30', 'type': 'call', 'children': ['31', '34']}; {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'yaml'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'safe_load'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'configfile'}; {'id': '36', 'type': 'dictionary', 'children': []}; {'id': '37', 'type': 'if_statement', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '39', 'type': 'block', 'children': ['40', '50']}; {'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']}; {'id': '44', 'type': 'call', 'children': ['45', '48']}; {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'string', 'children': [], 'value': '"Loaded config from {}"'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'config_path'}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}; {'id': '51', 'type': 'call', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'pprint'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'pprint'}; {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '57', 'type': 'except_clause', 'children': ['58', '66']}; {'id': '58', 'type': 'tuple', 'children': ['59', '60', '61']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'IOError'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'OSError'}; {'id': '61', 'type': 'attribute', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'yaml'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'parser'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'ParserError'}; {'id': '66', 'type': 'block', 'children': ['67']}; {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'call', 'children': ['69', '72']}; {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'traceback'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'print_exc'}; {'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': 'args'}; {'id': '76', 'type': 'call', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'update_from_config'}; {'id': '78', 'type': 'argument_list', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'assignment', 'children': ['83', '86']}; {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'ignore_paths'}; {'id': '86', 'type': 'boolean_operator', 'children': ['87', '95'], 'value': 'or'}; {'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': 'args'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': '__dict__'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '93', 'type': 'argument_list', 'children': ['94']}; {'id': '94', 'type': 'string', 'children': [], 'value': '"ignore_paths"'}; {'id': '95', 'type': 'list', 'children': ['96', '97', '98', '99', '100', '101', '102', '103', '104', '105', '106', '107', '108', '109', '110', '111', '112', '113'], 'value': '[\n "node_modules",\n ".git",\n ".tox",\n "godeps",\n "vendor",\n "site-packages",\n "venv",\n ".env",\n "spec",\n "migrate",\n "bin",\n "fixtures",\n "cassettes",\n ".cache",\n ".idea",\n ".pytest_cache",\n "__pycache__",\n "dist",\n ]'}; {'id': '96', 'type': 'string', 'children': [], 'value': '"node_modules"'}; {'id': '97', 'type': 'string', 'children': [], 'value': '".git"'}; {'id': '98', 'type': 'string', 'children': [], 'value': '".tox"'}; {'id': '99', 'type': 'string', 'children': [], 'value': '"godeps"'}; {'id': '100', 'type': 'string', 'children': [], 'value': '"vendor"'}; {'id': '101', 'type': 'string', 'children': [], 'value': '"site-packages"'}; {'id': '102', 'type': 'string', 'children': [], 'value': '"venv"'}; {'id': '103', 'type': 'string', 'children': [], 'value': '".env"'}; {'id': '104', 'type': 'string', 'children': [], 'value': '"spec"'}; {'id': '105', 'type': 'string', 'children': [], 'value': '"migrate"'}; {'id': '106', 'type': 'string', 'children': [], 'value': '"bin"'}; {'id': '107', 'type': 'string', 'children': [], 'value': '"fixtures"'}; {'id': '108', 'type': 'string', 'children': [], 'value': '"cassettes"'}; {'id': '109', 'type': 'string', 'children': [], 'value': '".cache"'}; {'id': '110', 'type': 'string', 'children': [], 'value': '".idea"'}; {'id': '111', 'type': 'string', 'children': [], 'value': '".pytest_cache"'}; {'id': '112', 'type': 'string', 'children': [], 'value': '"__pycache__"'}; {'id': '113', 'type': 'string', 'children': [], 'value': '"dist"'}; {'id': '114', 'type': 'if_statement', 'children': ['115', '118']}; {'id': '115', 'type': 'comparison_operator', 'children': ['116', '117'], 'value': '!='}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'config_path'}; {'id': '117', 'type': 'string', 'children': [], 'value': '".inlineplz.yml"'}; {'id': '118', 'type': 'block', 'children': ['119']}; {'id': '119', 'type': 'return_statement', 'children': ['120']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '121', 'type': 'if_statement', 'children': ['122', '128']}; {'id': '122', 'type': 'boolean_operator', 'children': ['123', '126'], 'value': 'and'}; {'id': '123', 'type': 'attribute', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'config_dir'}; {'id': '126', 'type': 'not_operator', 'children': ['127']}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '128', 'type': 'block', 'children': ['129', '143']}; {'id': '129', 'type': 'expression_statement', 'children': ['130']}; {'id': '130', 'type': 'assignment', 'children': ['131', '132']}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'new_config_path'}; {'id': '132', 'type': 'call', 'children': ['133', '138']}; {'id': '133', 'type': 'attribute', 'children': ['134', '137']}; {'id': '134', 'type': 'attribute', 'children': ['135', '136']}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '138', 'type': 'argument_list', 'children': ['139', '142']}; {'id': '139', 'type': 'attribute', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'config_dir'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'config_path'}; {'id': '143', 'type': 'if_statement', 'children': ['144', '152']}; {'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': 'exists'}; {'id': '150', 'type': 'argument_list', 'children': ['151']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'new_config_path'}; {'id': '152', 'type': 'block', 'children': ['153']}; {'id': '153', 'type': 'return_statement', 'children': ['154']}; {'id': '154', 'type': 'call', 'children': ['155', '156']}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'load_config'}; {'id': '156', 'type': 'argument_list', 'children': ['157', '158']}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'new_config_path'}; {'id': '159', 'type': 'return_statement', 'children': ['160']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'args'}
|
Load inline-plz config from yaml config file with reasonable defaults.
|
def process_save(X, y, tokenizer, proc_data_path, max_len=400, train=False, ngrams=None, limit_top_tokens=None):
if train and limit_top_tokens is not None:
tokenizer.apply_encoding_options(limit_top_tokens=limit_top_tokens)
X_encoded = tokenizer.encode_texts(X)
if ngrams is not None:
X_encoded = tokenizer.add_ngrams(X_encoded, n=ngrams, train=train)
X_padded = tokenizer.pad_sequences(
X_encoded, fixed_token_seq_length=max_len)
if train:
ds = Dataset(X_padded,
y, tokenizer=tokenizer)
else:
ds = Dataset(X_padded, y)
ds.save(proc_data_path)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'process_save'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '11', '14', '17']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'tokenizer'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'proc_data_path'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'max_len'}; {'id': '10', 'type': 'integer', 'children': [], 'value': '400'}; {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'train'}; {'id': '13', 'type': 'False', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'ngrams'}; {'id': '16', 'type': 'None', 'children': []}; {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'limit_top_tokens'}; {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'block', 'children': ['21', '37', '46', '66', '78', '102']}; {'id': '21', 'type': 'if_statement', 'children': ['22', '27']}; {'id': '22', 'type': 'boolean_operator', 'children': ['23', '24'], 'value': 'and'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'train'}; {'id': '24', 'type': 'comparison_operator', 'children': ['25', '26'], 'value': 'is not'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'limit_top_tokens'}; {'id': '26', 'type': 'None', 'children': []}; {'id': '27', 'type': 'block', 'children': ['28']}; {'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': 'tokenizer'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'apply_encoding_options'}; {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'keyword_argument', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'limit_top_tokens'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'limit_top_tokens'}; {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'X_encoded'}; {'id': '40', 'type': 'call', 'children': ['41', '44']}; {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'tokenizer'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'encode_texts'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '46', 'type': 'if_statement', 'children': ['47', '50']}; {'id': '47', 'type': 'comparison_operator', 'children': ['48', '49'], 'value': 'is not'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'ngrams'}; {'id': '49', 'type': 'None', 'children': []}; {'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': 'X_encoded'}; {'id': '54', 'type': 'call', 'children': ['55', '58']}; {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'tokenizer'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'add_ngrams'}; {'id': '58', 'type': 'argument_list', 'children': ['59', '60', '63']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'X_encoded'}; {'id': '60', 'type': 'keyword_argument', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'ngrams'}; {'id': '63', 'type': 'keyword_argument', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'train'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'train'}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}; {'id': '67', 'type': 'assignment', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'X_padded'}; {'id': '69', 'type': 'call', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'tokenizer'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'pad_sequences'}; {'id': '73', 'type': 'argument_list', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'X_encoded'}; {'id': '75', 'type': 'keyword_argument', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'fixed_token_seq_length'}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'max_len'}; {'id': '78', 'type': 'if_statement', 'children': ['79', '80', '92']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'train'}; {'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': 'ds'}; {'id': '84', 'type': 'call', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'Dataset'}; {'id': '86', 'type': 'argument_list', 'children': ['87', '88', '89']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'X_padded'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '89', 'type': 'keyword_argument', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'tokenizer'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'tokenizer'}; {'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': 'ds'}; {'id': '97', 'type': 'call', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'Dataset'}; {'id': '99', 'type': 'argument_list', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'X_padded'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'y'}; {'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': 'ds'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'save'}; {'id': '107', 'type': 'argument_list', 'children': ['108']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'proc_data_path'}
|
Process text and save as Dataset
|
def construct_mapping(self, node, deep=False):
mapping = ODict()
for key_node, value_node in node.value:
key = self.construct_object(key_node, deep=deep)
value = self.construct_object(value_node, deep=deep)
mapping[key] = value
return mapping
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'construct_mapping'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'deep'}; {'id': '8', 'type': 'False', 'children': []}; {'id': '9', 'type': 'block', 'children': ['10', '16', '54']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}; {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'mapping'}; {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'ODict'}; {'id': '15', 'type': 'argument_list', 'children': []}; {'id': '16', 'type': 'for_statement', 'children': ['17', '20', '23']}; {'id': '17', 'type': 'pattern_list', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'key_node'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'value_node'}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '23', 'type': 'block', 'children': ['24', '36', '48']}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}; {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'key'}; {'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': 'construct_object'}; {'id': '31', 'type': 'argument_list', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'key_node'}; {'id': '33', 'type': 'keyword_argument', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'deep'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'deep'}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}; {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '39', 'type': 'call', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'construct_object'}; {'id': '43', 'type': 'argument_list', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'value_node'}; {'id': '45', 'type': 'keyword_argument', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'deep'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'deep'}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}; {'id': '49', 'type': 'assignment', 'children': ['50', '53']}; {'id': '50', 'type': 'subscript', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'mapping'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '54', 'type': 'return_statement', 'children': ['55']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'mapping'}
|
Use ODict for maps
|
def newDocPI(self, name, content):
ret = libxml2mod.xmlNewDocPI(self._o, name, content)
if ret is None:raise treeError('xmlNewDocPI() failed')
__tmp = xmlNode(_obj=ret)
return __tmp
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'newDocPI'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'content'}; {'id': '7', 'type': 'block', 'children': ['8', '21', '31', '40']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'libxml2mod'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'xmlNewDocPI'}; {'id': '15', 'type': 'argument_list', 'children': ['16', '19', '20']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': '_o'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'content'}; {'id': '21', 'type': 'if_statement', 'children': ['22', '25']}; {'id': '22', 'type': 'comparison_operator', 'children': ['23', '24'], 'value': 'is'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '24', 'type': 'None', 'children': []}; {'id': '25', 'type': 'block', 'children': ['26']}; {'id': '26', 'type': 'raise_statement', 'children': ['27']}; {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'treeError'}; {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'string', 'children': [], 'value': "'xmlNewDocPI() failed'"}; {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': '__tmp'}; {'id': '34', 'type': 'call', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'xmlNode'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}; {'id': '37', 'type': 'keyword_argument', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': '_obj'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '40', 'type': 'return_statement', 'children': ['41']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': '__tmp'}
|
Creation of a processing instruction element.
|
def batch(input_iter, batch_size=32):
input_iter = iter(input_iter)
next_ = list(itertools.islice(input_iter, batch_size))
while next_:
yield next_
next_ = list(itertools.islice(input_iter, batch_size))
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'batch'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'input_iter'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'batch_size'}; {'id': '7', 'type': 'integer', 'children': [], 'value': '32'}; {'id': '8', 'type': 'block', 'children': ['9', '16', '29']}; {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'input_iter'}; {'id': '12', 'type': 'call', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'iter'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'input_iter'}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}; {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'next_'}; {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'list'}; {'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': 'itertools'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'islice'}; {'id': '26', 'type': 'argument_list', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'input_iter'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'batch_size'}; {'id': '29', 'type': 'while_statement', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'next_'}; {'id': '31', 'type': 'block', 'children': ['32', '35']}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}; {'id': '33', 'type': 'yield', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'next_'}; {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'next_'}; {'id': '38', 'type': 'call', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}; {'id': '41', 'type': 'call', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'itertools'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'islice'}; {'id': '45', 'type': 'argument_list', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'input_iter'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'batch_size'}
|
Batches data from an iterator that returns single items at a time.
|
def __set_log_file_name(self):
dir, _ = os.path.split(self.__logFileBasename)
if len(dir) and not os.path.exists(dir):
os.makedirs(dir)
self.__logFileName = self.__logFileBasename+"."+self.__logFileExtension
number = 0
while os.path.isfile(self.__logFileName):
if os.stat(self.__logFileName).st_size/1e6 < self.__maxlogFileSize:
break
number += 1
self.__logFileName = self.__logFileBasename+"_"+str(number)+"."+self.__logFileExtension
self.__logFileStream = None
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '__set_log_file_name'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '21', '44', '58', '62', '118']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '11']}; {'id': '8', 'type': 'pattern_list', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'dir'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': '_'}; {'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': 'os'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '17', 'type': 'argument_list', 'children': ['18']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': '__logFileBasename'}; {'id': '21', 'type': 'if_statement', 'children': ['22', '36']}; {'id': '22', 'type': 'boolean_operator', 'children': ['23', '27'], 'value': 'and'}; {'id': '23', 'type': 'call', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'dir'}; {'id': '27', 'type': 'not_operator', 'children': ['28']}; {'id': '28', 'type': 'call', 'children': ['29', '34']}; {'id': '29', 'type': 'attribute', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'exists'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'dir'}; {'id': '36', 'type': 'block', 'children': ['37']}; {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'call', 'children': ['39', '42']}; {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'makedirs'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'dir'}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}; {'id': '45', 'type': 'assignment', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': '__logFileName'}; {'id': '49', 'type': 'binary_operator', 'children': ['50', '55'], 'value': '+'}; {'id': '50', 'type': 'binary_operator', 'children': ['51', '54'], 'value': '+'}; {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': '__logFileBasename'}; {'id': '54', 'type': 'string', 'children': [], 'value': '"."'}; {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': '__logFileExtension'}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}; {'id': '59', 'type': 'assignment', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'number'}; {'id': '61', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '62', 'type': 'while_statement', 'children': ['63', '73']}; {'id': '63', 'type': 'call', 'children': ['64', '69']}; {'id': '64', 'type': 'attribute', 'children': ['65', '68']}; {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'isfile'}; {'id': '69', 'type': 'argument_list', 'children': ['70']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': '__logFileName'}; {'id': '73', 'type': 'block', 'children': ['74', '93', '97']}; {'id': '74', 'type': 'if_statement', 'children': ['75', '91']}; {'id': '75', 'type': 'comparison_operator', 'children': ['76', '88'], 'value': '<'}; {'id': '76', 'type': 'binary_operator', 'children': ['77', '87'], 'value': '/'}; {'id': '77', 'type': 'attribute', 'children': ['78', '86']}; {'id': '78', 'type': 'call', 'children': ['79', '82']}; {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'stat'}; {'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': '__logFileName'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'st_size'}; {'id': '87', 'type': 'float', 'children': [], 'value': '1e6'}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': '__maxlogFileSize'}; {'id': '91', 'type': 'block', 'children': ['92']}; {'id': '92', 'type': 'break_statement', 'children': []}; {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'augmented_assignment', 'children': ['95', '96'], 'value': '+='}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'number'}; {'id': '96', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'assignment', 'children': ['99', '102']}; {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': '__logFileName'}; {'id': '102', 'type': 'binary_operator', 'children': ['103', '115'], 'value': '+'}; {'id': '103', 'type': 'binary_operator', 'children': ['104', '114'], 'value': '+'}; {'id': '104', 'type': 'binary_operator', 'children': ['105', '110'], 'value': '+'}; {'id': '105', 'type': 'binary_operator', 'children': ['106', '109'], 'value': '+'}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': '__logFileBasename'}; {'id': '109', 'type': 'string', 'children': [], 'value': '"_"'}; {'id': '110', 'type': 'call', 'children': ['111', '112']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '112', 'type': 'argument_list', 'children': ['113']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'number'}; {'id': '114', 'type': 'string', 'children': [], 'value': '"."'}; {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': '__logFileExtension'}; {'id': '118', 'type': 'expression_statement', 'children': ['119']}; {'id': '119', 'type': 'assignment', 'children': ['120', '123']}; {'id': '120', 'type': 'attribute', 'children': ['121', '122']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': '__logFileStream'}; {'id': '123', 'type': 'None', 'children': []}
|
Automatically set logFileName attribute
|
def sorted(cls, items, orders):
return sorted(items, cmp=cls.multipleOrderComparison(orders))
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sorted'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'orders'}; {'id': '7', 'type': 'block', 'children': ['8']}; {'id': '8', 'type': 'return_statement', 'children': ['9']}; {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '11', 'type': 'argument_list', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '13', 'type': 'keyword_argument', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'cmp'}; {'id': '15', 'type': 'call', 'children': ['16', '19']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'multipleOrderComparison'}; {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'orders'}
|
Returns the elements in `items` sorted according to `orders`
|
def from_memdb_file(path):
path = to_bytes(path)
return View._from_ptr(rustcall(_lib.lsm_view_from_memdb_file, path))
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'from_memdb_file'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '5', 'type': 'block', 'children': ['6', '13']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'to_bytes'}; {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '13', 'type': 'return_statement', 'children': ['14']}; {'id': '14', 'type': 'call', 'children': ['15', '18']}; {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'View'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': '_from_ptr'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}; {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'rustcall'}; {'id': '21', 'type': 'argument_list', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': '_lib'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'lsm_view_from_memdb_file'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'path'}
|
Creates a sourcemap view from MemDB at a given file.
|
def _check_realign(data):
if "gatk4" not in data["algorithm"].get("tools_off", []) and not "gatk4" == data["algorithm"].get("tools_off"):
if data["algorithm"].get("realign"):
raise ValueError("In sample %s, realign specified but it is not supported for GATK4. "
"Realignment is generally not necessary for most variant callers." %
(dd.get_sample_name(data)))
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_check_realign'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '5', 'type': 'block', 'children': ['6']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '30']}; {'id': '7', 'type': 'boolean_operator', 'children': ['8', '19'], 'value': 'and'}; {'id': '8', 'type': 'comparison_operator', 'children': ['9', '10'], 'value': 'not in'}; {'id': '9', 'type': 'string', 'children': [], 'value': '"gatk4"'}; {'id': '10', 'type': 'call', 'children': ['11', '16']}; {'id': '11', 'type': 'attribute', 'children': ['12', '15']}; {'id': '12', 'type': 'subscript', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '14', 'type': 'string', 'children': [], 'value': '"algorithm"'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '16', 'type': 'argument_list', 'children': ['17', '18']}; {'id': '17', 'type': 'string', 'children': [], 'value': '"tools_off"'}; {'id': '18', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '19', 'type': 'not_operator', 'children': ['20']}; {'id': '20', 'type': 'comparison_operator', 'children': ['21', '22'], 'value': '=='}; {'id': '21', 'type': 'string', 'children': [], 'value': '"gatk4"'}; {'id': '22', 'type': 'call', 'children': ['23', '28']}; {'id': '23', 'type': 'attribute', 'children': ['24', '27']}; {'id': '24', 'type': 'subscript', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '26', 'type': 'string', 'children': [], 'value': '"algorithm"'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}; {'id': '29', 'type': 'string', 'children': [], 'value': '"tools_off"'}; {'id': '30', 'type': 'block', 'children': ['31']}; {'id': '31', 'type': 'if_statement', 'children': ['32', '40']}; {'id': '32', 'type': 'call', 'children': ['33', '38']}; {'id': '33', 'type': 'attribute', 'children': ['34', '37']}; {'id': '34', 'type': 'subscript', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '36', 'type': 'string', 'children': [], 'value': '"algorithm"'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}; {'id': '39', 'type': 'string', 'children': [], 'value': '"realign"'}; {'id': '40', 'type': 'block', 'children': ['41']}; {'id': '41', 'type': 'raise_statement', 'children': ['42']}; {'id': '42', 'type': 'call', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}; {'id': '45', 'type': 'binary_operator', 'children': ['46', '49'], 'value': '%'}; {'id': '46', 'type': 'concatenated_string', 'children': ['47', '48']}; {'id': '47', 'type': 'string', 'children': [], 'value': '"In sample %s, realign specified but it is not supported for GATK4. "'}; {'id': '48', 'type': 'string', 'children': [], 'value': '"Realignment is generally not necessary for most variant callers."'}; {'id': '49', 'type': '()', 'children': ['50']}; {'id': '50', 'type': 'call', 'children': ['51', '54']}; {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'dd'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'get_sample_name'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'data'}
|
Check for realignment, which is not supported in GATK4
|
def _create_entry(entry: dict, source: Source = None) -> dict:
entry["package_name"] = entry["package"].pop("package_name")
entry["package_version"] = entry["package"].pop("installed_version")
if source:
entry["index_url"] = source.url
entry["sha256"] = []
for item in source.get_package_hashes(entry["package_name"], entry["package_version"]):
entry["sha256"].append(item["sha256"])
entry.pop("package")
for dependency in entry["dependencies"]:
dependency.pop("key", None)
dependency.pop("installed_version", None)
return entry
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13', '15']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_create_entry'}; {'id': '3', 'type': 'parameters', 'children': ['4', '8']}; {'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '6', 'type': 'type', 'children': ['7']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '8', 'type': 'typed_default_parameter', 'children': ['9', '10', '12']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'source'}; {'id': '10', 'type': 'type', 'children': ['11']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'Source'}; {'id': '12', 'type': 'None', 'children': []}; {'id': '13', 'type': 'type', 'children': ['14']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '15', 'type': 'block', 'children': ['16', '29', '42', '84', '91', '113']}; {'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': 'entry'}; {'id': '20', 'type': 'string', 'children': [], 'value': '"package_name"'}; {'id': '21', 'type': 'call', 'children': ['22', '27']}; {'id': '22', 'type': 'attribute', 'children': ['23', '26']}; {'id': '23', 'type': 'subscript', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '25', 'type': 'string', 'children': [], 'value': '"package"'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'string', 'children': [], 'value': '"package_name"'}; {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '34']}; {'id': '31', 'type': 'subscript', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '33', 'type': 'string', 'children': [], 'value': '"package_version"'}; {'id': '34', 'type': 'call', 'children': ['35', '40']}; {'id': '35', 'type': 'attribute', 'children': ['36', '39']}; {'id': '36', 'type': 'subscript', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '38', 'type': 'string', 'children': [], 'value': '"package"'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}; {'id': '41', 'type': 'string', 'children': [], 'value': '"installed_version"'}; {'id': '42', 'type': 'if_statement', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'source'}; {'id': '44', 'type': 'block', 'children': ['45', '53', '59']}; {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '50']}; {'id': '47', 'type': 'subscript', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '49', 'type': 'string', 'children': [], 'value': '"index_url"'}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'source'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '58']}; {'id': '55', 'type': 'subscript', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '57', 'type': 'string', 'children': [], 'value': '"sha256"'}; {'id': '58', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '59', 'type': 'for_statement', 'children': ['60', '61', '72']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '61', 'type': 'call', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'source'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'get_package_hashes'}; {'id': '65', 'type': 'argument_list', 'children': ['66', '69']}; {'id': '66', 'type': 'subscript', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '68', 'type': 'string', 'children': [], 'value': '"package_name"'}; {'id': '69', 'type': 'subscript', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '71', 'type': 'string', 'children': [], 'value': '"package_version"'}; {'id': '72', 'type': 'block', 'children': ['73']}; {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'call', 'children': ['75', '80']}; {'id': '75', 'type': 'attribute', 'children': ['76', '79']}; {'id': '76', 'type': 'subscript', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '78', 'type': 'string', 'children': [], 'value': '"sha256"'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}; {'id': '81', 'type': 'subscript', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '83', 'type': 'string', 'children': [], 'value': '"sha256"'}; {'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': 'entry'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'string', 'children': [], 'value': '"package"'}; {'id': '91', 'type': 'for_statement', 'children': ['92', '93', '96']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'dependency'}; {'id': '93', 'type': 'subscript', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '95', 'type': 'string', 'children': [], 'value': '"dependencies"'}; {'id': '96', 'type': 'block', 'children': ['97', '105']}; {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'call', 'children': ['99', '102']}; {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'dependency'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '102', 'type': 'argument_list', 'children': ['103', '104']}; {'id': '103', 'type': 'string', 'children': [], 'value': '"key"'}; {'id': '104', 'type': 'None', 'children': []}; {'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': 'dependency'}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '110', 'type': 'argument_list', 'children': ['111', '112']}; {'id': '111', 'type': 'string', 'children': [], 'value': '"installed_version"'}; {'id': '112', 'type': 'None', 'children': []}; {'id': '113', 'type': 'return_statement', 'children': ['114']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'entry'}
|
Filter and normalize the output of pipdeptree entry.
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.