code
stringlengths 51
2.34k
| sequence
stringlengths 1.16k
13.1k
| docstring
stringlengths 11
171
|
|---|---|---|
def months_ago(date, nb_months=1):
nb_years = nb_months // 12
nb_months = nb_months % 12
month_diff = date.month - nb_months
if month_diff > 0:
new_month = month_diff
else:
new_month = 12 + month_diff
nb_years += 1
return date.replace(day=1, month=new_month, year=date.year - nb_years)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'months_ago'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'date'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'nb_months'}; {'id': '7', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '8', 'type': 'block', 'children': ['9', '15', '21', '29', '50']}; {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'nb_years'}; {'id': '12', 'type': 'binary_operator', 'children': ['13', '14'], 'value': '//'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'nb_months'}; {'id': '14', 'type': 'integer', 'children': [], 'value': '12'}; {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'nb_months'}; {'id': '18', 'type': 'binary_operator', 'children': ['19', '20'], 'value': '%'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'nb_months'}; {'id': '20', 'type': 'integer', 'children': [], 'value': '12'}; {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'month_diff'}; {'id': '24', 'type': 'binary_operator', 'children': ['25', '28'], 'value': '-'}; {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'date'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'month'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'nb_months'}; {'id': '29', 'type': 'if_statement', 'children': ['30', '33', '38']}; {'id': '30', 'type': 'comparison_operator', 'children': ['31', '32'], 'value': '>'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'month_diff'}; {'id': '32', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '33', 'type': 'block', 'children': ['34']}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}; {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'new_month'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'month_diff'}; {'id': '38', 'type': 'else_clause', 'children': ['39']}; {'id': '39', 'type': 'block', 'children': ['40', '46']}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}; {'id': '41', 'type': 'assignment', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'new_month'}; {'id': '43', 'type': 'binary_operator', 'children': ['44', '45'], 'value': '+'}; {'id': '44', 'type': 'integer', 'children': [], 'value': '12'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'month_diff'}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}; {'id': '47', 'type': 'augmented_assignment', 'children': ['48', '49'], 'value': '+='}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'nb_years'}; {'id': '49', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '50', 'type': 'return_statement', 'children': ['51']}; {'id': '51', 'type': 'call', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'date'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '55', 'type': 'argument_list', 'children': ['56', '59', '62']}; {'id': '56', 'type': 'keyword_argument', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'day'}; {'id': '58', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '59', 'type': 'keyword_argument', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'month'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'new_month'}; {'id': '62', 'type': 'keyword_argument', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'year'}; {'id': '64', 'type': 'binary_operator', 'children': ['65', '68'], 'value': '-'}; {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'date'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'year'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'nb_years'}
|
Return the given `date` with `nb_months` substracted from it.
|
def _fill_argparser(self, parser):
for key, val in self._options.items():
add_argument(parser, key, val)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_fill_argparser'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'parser'}; {'id': '6', 'type': 'block', 'children': ['7']}; {'id': '7', 'type': 'for_statement', 'children': ['8', '11', '18']}; {'id': '8', 'type': 'pattern_list', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'val'}; {'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': '_options'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '17', 'type': 'argument_list', 'children': []}; {'id': '18', 'type': 'block', 'children': ['19']}; {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'call', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'add_argument'}; {'id': '22', 'type': 'argument_list', 'children': ['23', '24', '25']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'parser'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'val'}
|
Fill an `argparser.ArgumentParser` with the options from this chain
|
def callHook(self, hookname, *args, **kwargs):
'Call all functions registered with `addHook` for the given hookname.'
r = []
for f in self.hooks[hookname]:
try:
r.append(f(*args, **kwargs))
except Exception as e:
exceptionCaught(e)
return r
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'callHook'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'hookname'}; {'id': '6', 'type': 'list_splat_pattern', 'children': ['7']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '8', 'type': 'dictionary_splat_pattern', 'children': ['9']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '10', 'type': 'block', 'children': ['11', '13', '17', '51']}; {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'string', 'children': [], 'value': "'Call all functions registered with `addHook` for the given hookname.'"}; {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '16', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '17', 'type': 'for_statement', 'children': ['18', '19', '24']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '19', 'type': 'subscript', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'hooks'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'hookname'}; {'id': '24', 'type': 'block', 'children': ['25']}; {'id': '25', 'type': 'try_statement', 'children': ['26', '40']}; {'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': 'r'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}; {'id': '33', 'type': 'call', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '35', 'type': 'argument_list', 'children': ['36', '38']}; {'id': '36', 'type': 'list_splat', 'children': ['37']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '38', 'type': 'dictionary_splat', 'children': ['39']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '40', 'type': 'except_clause', 'children': ['41', '45']}; {'id': '41', 'type': 'as_pattern', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '43', 'type': 'as_pattern_target', 'children': ['44']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '45', 'type': 'block', 'children': ['46']}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}; {'id': '47', 'type': 'call', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'exceptionCaught'}; {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '51', 'type': 'return_statement', 'children': ['52']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'r'}
|
Call all functions registered with `addHook` for the given hookname.
|
def get(self):
if self.bucket.get() < 1:
return None
now = time.time()
self.mutex.acquire()
try:
task = self.priority_queue.get_nowait()
self.bucket.desc()
except Queue.Empty:
self.mutex.release()
return None
task.exetime = now + self.processing_timeout
self.processing.put(task)
self.mutex.release()
return task.taskid
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '19', '27', '35', '70', '80', '89', '97']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '16']}; {'id': '7', 'type': 'comparison_operator', 'children': ['8', '15'], 'value': '<'}; {'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': 'self'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'bucket'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '14', 'type': 'argument_list', 'children': []}; {'id': '15', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '16', 'type': 'block', 'children': ['17']}; {'id': '17', 'type': 'return_statement', 'children': ['18']}; {'id': '18', 'type': 'None', 'children': []}; {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'now'}; {'id': '22', 'type': 'call', 'children': ['23', '26']}; {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '26', 'type': 'argument_list', 'children': []}; {'id': '27', 'type': 'expression_statement', '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': 'self'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'mutex'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'acquire'}; {'id': '34', 'type': 'argument_list', 'children': []}; {'id': '35', 'type': 'try_statement', 'children': ['36', '55']}; {'id': '36', 'type': 'block', 'children': ['37', '47']}; {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'task'}; {'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': 'self'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'priority_queue'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'get_nowait'}; {'id': '46', 'type': 'argument_list', 'children': []}; {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'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': 'bucket'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'desc'}; {'id': '54', 'type': 'argument_list', 'children': []}; {'id': '55', 'type': 'except_clause', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'Queue'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'Empty'}; {'id': '59', 'type': 'block', 'children': ['60', '68']}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}; {'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': 'self'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'mutex'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'release'}; {'id': '67', 'type': 'argument_list', 'children': []}; {'id': '68', 'type': 'return_statement', 'children': ['69']}; {'id': '69', 'type': 'None', 'children': []}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}; {'id': '71', 'type': 'assignment', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'task'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'exetime'}; {'id': '75', 'type': 'binary_operator', 'children': ['76', '77'], 'value': '+'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'now'}; {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'processing_timeout'}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}; {'id': '81', 'type': 'call', 'children': ['82', '87']}; {'id': '82', 'type': 'attribute', 'children': ['83', '86']}; {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'processing'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'put'}; {'id': '87', 'type': 'argument_list', 'children': ['88']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'task'}; {'id': '89', 'type': 'expression_statement', 'children': ['90']}; {'id': '90', 'type': 'call', 'children': ['91', '96']}; {'id': '91', 'type': 'attribute', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'mutex'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'release'}; {'id': '96', 'type': 'argument_list', 'children': []}; {'id': '97', 'type': 'return_statement', 'children': ['98']}; {'id': '98', 'type': 'attribute', 'children': ['99', '100']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'task'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'taskid'}
|
Get a task from queue when bucket available
|
def recursively_resume_states(self):
super(ContainerState, self).recursively_resume_states()
for state in self.states.values():
state.recursively_resume_states()
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'recursively_resume_states'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '16']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'call', 'children': ['8', '15']}; {'id': '8', 'type': 'attribute', 'children': ['9', '14']}; {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'super'}; {'id': '11', 'type': 'argument_list', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'ContainerState'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'recursively_resume_states'}; {'id': '15', 'type': 'argument_list', 'children': []}; {'id': '16', 'type': 'for_statement', 'children': ['17', '18', '25']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'state'}; {'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': 'self'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'states'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '24', 'type': 'argument_list', 'children': []}; {'id': '25', 'type': 'block', 'children': ['26']}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}; {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'state'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'recursively_resume_states'}; {'id': '31', 'type': 'argument_list', 'children': []}
|
Resume the state and all of it child states.
|
def toListInt(value):
if TypeConverters._can_convert_to_list(value):
value = TypeConverters.toList(value)
if all(map(lambda v: TypeConverters._is_integer(v), value)):
return [int(v) for v in value]
raise TypeError("Could not convert %s to list of ints" % value)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'toListInt'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '5', 'type': 'block', 'children': ['6', '50']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '13']}; {'id': '7', 'type': 'call', 'children': ['8', '11']}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'TypeConverters'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': '_can_convert_to_list'}; {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '13', 'type': 'block', 'children': ['14', '23']}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}; {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '17', 'type': 'call', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'TypeConverters'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'toList'}; {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '23', 'type': 'if_statement', 'children': ['24', '40']}; {'id': '24', 'type': 'call', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'all'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}; {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'map'}; {'id': '29', 'type': 'argument_list', 'children': ['30', '39']}; {'id': '30', 'type': 'lambda', 'children': ['31', '33']}; {'id': '31', 'type': 'lambda_parameters', 'children': ['32']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '33', 'type': 'call', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'TypeConverters'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': '_is_integer'}; {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '40', 'type': 'block', 'children': ['41']}; {'id': '41', 'type': 'return_statement', 'children': ['42']}; {'id': '42', 'type': 'list_comprehension', 'children': ['43', '47']}; {'id': '43', 'type': 'call', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '47', 'type': 'for_in_clause', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '50', 'type': 'raise_statement', 'children': ['51']}; {'id': '51', 'type': 'call', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'TypeError'}; {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'binary_operator', 'children': ['55', '56'], 'value': '%'}; {'id': '55', 'type': 'string', 'children': [], 'value': '"Could not convert %s to list of ints"'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'value'}
|
Convert a value to list of ints, if possible.
|
def delete_name(name):
session = create_session()
try:
user = session.query(User).filter_by(name=name).first()
session.delete(user)
session.commit()
except SQLAlchemyError, e:
session.rollback()
raise bottle.HTTPError(500, "Database Error", e)
finally:
session.close()
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'delete_name'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '5', 'type': 'block', 'children': ['6', '12']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'session'}; {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'create_session'}; {'id': '11', 'type': 'argument_list', 'children': []}; {'id': '12', 'type': 'try_statement', 'children': ['13', '47', '66']}; {'id': '13', 'type': 'block', 'children': ['14', '34', '41']}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}; {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'user'}; {'id': '17', 'type': 'call', 'children': ['18', '33']}; {'id': '18', 'type': 'attribute', 'children': ['19', '32']}; {'id': '19', 'type': 'call', 'children': ['20', '28']}; {'id': '20', 'type': 'attribute', 'children': ['21', '27']}; {'id': '21', 'type': 'call', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'session'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'User'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'filter_by'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}; {'id': '29', 'type': 'keyword_argument', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'first'}; {'id': '33', 'type': 'argument_list', 'children': []}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}; {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'session'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'delete'}; {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'user'}; {'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': 'session'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'commit'}; {'id': '46', 'type': 'argument_list', 'children': []}; {'id': '47', 'type': 'except_clause', 'children': ['48', '49', '50']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'SQLAlchemyError'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '50', 'type': 'block', 'children': ['51', '57']}; {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'call', 'children': ['53', '56']}; {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'session'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'rollback'}; {'id': '56', 'type': 'argument_list', 'children': []}; {'id': '57', 'type': 'raise_statement', 'children': ['58']}; {'id': '58', 'type': 'call', 'children': ['59', '62']}; {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'bottle'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'HTTPError'}; {'id': '62', 'type': 'argument_list', 'children': ['63', '64', '65']}; {'id': '63', 'type': 'integer', 'children': [], 'value': '500'}; {'id': '64', 'type': 'string', 'children': [], 'value': '"Database Error"'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '66', 'type': 'finally_clause', 'children': ['67']}; {'id': '67', 'type': 'block', 'children': ['68']}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}; {'id': '69', 'type': 'call', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'session'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'close'}; {'id': '73', 'type': 'argument_list', 'children': []}
|
This function don't use the plugin.
|
def contour_mask(self, contour):
new_data = np.zeros(self.data.shape)
num_boundary = contour.boundary_pixels.shape[0]
boundary_px_ij_swapped = np.zeros([num_boundary, 1, 2])
boundary_px_ij_swapped[:, 0, 0] = contour.boundary_pixels[:, 1]
boundary_px_ij_swapped[:, 0, 1] = contour.boundary_pixels[:, 0]
cv2.fillPoly(
new_data, pts=[
boundary_px_ij_swapped.astype(
np.int32)], color=(
BINARY_IM_MAX_VAL, BINARY_IM_MAX_VAL, BINARY_IM_MAX_VAL))
orig_zeros = np.where(self.data == 0)
new_data[orig_zeros[0], orig_zeros[1]] = 0
return BinaryImage(new_data.astype(np.uint8), frame=self._frame)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'contour_mask'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'contour'}; {'id': '6', 'type': 'block', 'children': ['7', '20', '30', '42', '57', '72', '96', '109', '120']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'new_data'}; {'id': '10', 'type': 'call', 'children': ['11', '14']}; {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'zeros'}; {'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': 'data'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}; {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'num_boundary'}; {'id': '23', 'type': 'subscript', 'children': ['24', '29']}; {'id': '24', 'type': 'attribute', 'children': ['25', '28']}; {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'contour'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'boundary_pixels'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '29', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}; {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'boundary_px_ij_swapped'}; {'id': '33', 'type': 'call', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'zeros'}; {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'list', 'children': ['39', '40', '41'], 'value': '[num_boundary, 1, 2]'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'num_boundary'}; {'id': '40', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '41', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}; {'id': '43', 'type': 'assignment', 'children': ['44', '50']}; {'id': '44', 'type': 'subscript', 'children': ['45', '46', '48', '49']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'boundary_px_ij_swapped'}; {'id': '46', 'type': 'slice', 'children': ['47']}; {'id': '47', 'type': 'colon', 'children': []}; {'id': '48', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '49', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '50', 'type': 'subscript', 'children': ['51', '54', '56']}; {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'contour'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'boundary_pixels'}; {'id': '54', 'type': 'slice', 'children': ['55']}; {'id': '55', 'type': 'colon', 'children': []}; {'id': '56', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '65']}; {'id': '59', 'type': 'subscript', 'children': ['60', '61', '63', '64']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'boundary_px_ij_swapped'}; {'id': '61', 'type': 'slice', 'children': ['62']}; {'id': '62', 'type': 'colon', 'children': []}; {'id': '63', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '64', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '65', 'type': 'subscript', 'children': ['66', '69', '71']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'contour'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'boundary_pixels'}; {'id': '69', 'type': 'slice', 'children': ['70']}; {'id': '70', 'type': 'colon', 'children': []}; {'id': '71', 'type': 'integer', 'children': [], 'value': '0'}; {'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': 'cv2'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'fillPoly'}; {'id': '77', 'type': 'argument_list', 'children': ['78', '79', '90']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'new_data'}; {'id': '79', 'type': 'keyword_argument', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'pts'}; {'id': '81', 'type': 'list', 'children': ['82'], 'value': '[\n boundary_px_ij_swapped.astype(\n np.int32)]'}; {'id': '82', 'type': 'call', 'children': ['83', '86']}; {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'boundary_px_ij_swapped'}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'astype'}; {'id': '86', 'type': 'argument_list', 'children': ['87']}; {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'int32'}; {'id': '90', 'type': 'keyword_argument', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'color'}; {'id': '92', 'type': 'tuple', 'children': ['93', '94', '95']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'BINARY_IM_MAX_VAL'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'BINARY_IM_MAX_VAL'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'BINARY_IM_MAX_VAL'}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}; {'id': '97', 'type': 'assignment', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'orig_zeros'}; {'id': '99', 'type': 'call', 'children': ['100', '103']}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'where'}; {'id': '103', 'type': 'argument_list', 'children': ['104']}; {'id': '104', 'type': 'comparison_operator', 'children': ['105', '108'], 'value': '=='}; {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '108', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '109', 'type': 'expression_statement', 'children': ['110']}; {'id': '110', 'type': 'assignment', 'children': ['111', '119']}; {'id': '111', 'type': 'subscript', 'children': ['112', '113', '116']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'new_data'}; {'id': '113', 'type': 'subscript', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'orig_zeros'}; {'id': '115', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '116', 'type': 'subscript', 'children': ['117', '118']}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'orig_zeros'}; {'id': '118', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '119', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '120', 'type': 'return_statement', 'children': ['121']}; {'id': '121', 'type': 'call', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'BinaryImage'}; {'id': '123', 'type': 'argument_list', 'children': ['124', '132']}; {'id': '124', 'type': 'call', 'children': ['125', '128']}; {'id': '125', 'type': 'attribute', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'new_data'}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'astype'}; {'id': '128', 'type': 'argument_list', 'children': ['129']}; {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'uint8'}; {'id': '132', 'type': 'keyword_argument', 'children': ['133', '134']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'frame'}; {'id': '134', 'type': 'attribute', 'children': ['135', '136']}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': '_frame'}
|
Generates a binary image with only the given contour filled in.
|
def verify_email(self, action_token, signed_data):
try:
action = "verify-email"
user = get_user_by_action_token(action, action_token)
if not user or not user.signed_data_match(signed_data, action):
raise mocha_exc.AppError("Verification Invalid!")
else:
user.set_email_verified(True)
flash_success("Account verified. You can now login")
username = user.username
if user.login_method == "email":
username = user.email
return redirect(self.login, username=username)
except Exception as e:
logging.exception(e)
flash_error("Verification Failed!")
return redirect(self.login)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'verify_email'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'action_token'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'signed_data'}; {'id': '7', 'type': 'block', 'children': ['8', '103']}; {'id': '8', 'type': 'try_statement', 'children': ['9', '85']}; {'id': '9', 'type': 'block', 'children': ['10', '14', '22']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}; {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '13', 'type': 'string', 'children': [], 'value': '"verify-email"'}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}; {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'user'}; {'id': '17', 'type': 'call', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'get_user_by_action_token'}; {'id': '19', 'type': 'argument_list', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'action_token'}; {'id': '22', 'type': 'if_statement', 'children': ['23', '34', '42']}; {'id': '23', 'type': 'boolean_operator', 'children': ['24', '26'], 'value': 'or'}; {'id': '24', 'type': 'not_operator', 'children': ['25']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'user'}; {'id': '26', 'type': 'not_operator', 'children': ['27']}; {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'user'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'signed_data_match'}; {'id': '31', 'type': 'argument_list', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'signed_data'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '34', 'type': 'block', 'children': ['35']}; {'id': '35', 'type': 'raise_statement', 'children': ['36']}; {'id': '36', 'type': 'call', 'children': ['37', '40']}; {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'mocha_exc'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'AppError'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}; {'id': '41', 'type': 'string', 'children': [], 'value': '"Verification Invalid!"'}; {'id': '42', 'type': 'else_clause', 'children': ['43']}; {'id': '43', 'type': 'block', 'children': ['44', '51', '56', '62', '75']}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}; {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'user'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'set_email_verified'}; {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'True', 'children': []}; {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'call', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'flash_success'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}; {'id': '55', 'type': 'string', 'children': [], 'value': '"Account verified. You can now login"'}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}; {'id': '57', 'type': 'assignment', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'username'}; {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'user'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'username'}; {'id': '62', 'type': 'if_statement', 'children': ['63', '68']}; {'id': '63', 'type': 'comparison_operator', 'children': ['64', '67'], 'value': '=='}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'user'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'login_method'}; {'id': '67', 'type': 'string', 'children': [], 'value': '"email"'}; {'id': '68', 'type': 'block', 'children': ['69']}; {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'username'}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'user'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'email'}; {'id': '75', 'type': 'return_statement', 'children': ['76']}; {'id': '76', 'type': 'call', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'redirect'}; {'id': '78', 'type': 'argument_list', 'children': ['79', '82']}; {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'login'}; {'id': '82', 'type': 'keyword_argument', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'username'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'username'}; {'id': '85', 'type': 'except_clause', 'children': ['86', '90']}; {'id': '86', 'type': 'as_pattern', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '88', 'type': 'as_pattern_target', 'children': ['89']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '90', 'type': 'block', 'children': ['91', '98']}; {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'call', 'children': ['93', '96']}; {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'exception'}; {'id': '96', 'type': 'argument_list', 'children': ['97']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}; {'id': '99', 'type': 'call', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'flash_error'}; {'id': '101', 'type': 'argument_list', 'children': ['102']}; {'id': '102', 'type': 'string', 'children': [], 'value': '"Verification Failed!"'}; {'id': '103', 'type': 'return_statement', 'children': ['104']}; {'id': '104', 'type': 'call', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'redirect'}; {'id': '106', 'type': 'argument_list', 'children': ['107']}; {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'login'}
|
Verify email account, in which a link was sent to
|
def stop(self, sig=signal.SIGINT):
for cpid in self.sandboxes:
logger.warn('Stopping %i...' % cpid)
try:
os.kill(cpid, sig)
except OSError:
logger.exception('Error stopping %s...' % cpid)
for cpid in list(self.sandboxes):
try:
logger.info('Waiting for %i...' % cpid)
pid, status = os.waitpid(cpid, 0)
logger.warn('%i stopped with status %i' % (pid, status >> 8))
except OSError:
logger.exception('Error waiting for %i...' % cpid)
finally:
self.sandboxes.pop(cpid, None)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'stop'}; {'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': 'sig'}; {'id': '7', 'type': 'attribute', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'signal'}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'SIGINT'}; {'id': '10', 'type': 'block', 'children': ['11', '48']}; {'id': '11', 'type': 'for_statement', 'children': ['12', '13', '16']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'cpid'}; {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'sandboxes'}; {'id': '16', 'type': 'block', 'children': ['17', '26']}; {'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': 'logger'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'warn'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}; {'id': '23', 'type': 'binary_operator', 'children': ['24', '25'], 'value': '%'}; {'id': '24', 'type': 'string', 'children': [], 'value': "'Stopping %i...'"}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'cpid'}; {'id': '26', 'type': 'try_statement', 'children': ['27', '36']}; {'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': 'os'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'kill'}; {'id': '33', 'type': 'argument_list', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'cpid'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'sig'}; {'id': '36', 'type': 'except_clause', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'OSError'}; {'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': 'logger'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'exception'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}; {'id': '45', 'type': 'binary_operator', 'children': ['46', '47'], 'value': '%'}; {'id': '46', 'type': 'string', 'children': [], 'value': "'Error stopping %s...'"}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'cpid'}; {'id': '48', 'type': 'for_statement', 'children': ['49', '50', '56']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'cpid'}; {'id': '50', 'type': 'call', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}; {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'sandboxes'}; {'id': '56', 'type': 'block', 'children': ['57']}; {'id': '57', 'type': 'try_statement', 'children': ['58', '93', '105']}; {'id': '58', 'type': 'block', 'children': ['59', '68', '80']}; {'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': 'logger'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}; {'id': '65', 'type': 'binary_operator', 'children': ['66', '67'], 'value': '%'}; {'id': '66', 'type': 'string', 'children': [], 'value': "'Waiting for %i...'"}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'cpid'}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}; {'id': '69', 'type': 'assignment', 'children': ['70', '73']}; {'id': '70', 'type': 'pattern_list', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'pid'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'status'}; {'id': '73', 'type': 'call', 'children': ['74', '77']}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'waitpid'}; {'id': '77', 'type': 'argument_list', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'cpid'}; {'id': '79', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}; {'id': '81', 'type': 'call', 'children': ['82', '85']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'warn'}; {'id': '85', 'type': 'argument_list', 'children': ['86']}; {'id': '86', 'type': 'binary_operator', 'children': ['87', '88'], 'value': '%'}; {'id': '87', 'type': 'string', 'children': [], 'value': "'%i stopped with status %i'"}; {'id': '88', 'type': 'tuple', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'pid'}; {'id': '90', 'type': 'binary_operator', 'children': ['91', '92'], 'value': '>>'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'status'}; {'id': '92', 'type': 'integer', 'children': [], 'value': '8'}; {'id': '93', 'type': 'except_clause', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'OSError'}; {'id': '95', 'type': 'block', 'children': ['96']}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}; {'id': '97', 'type': 'call', 'children': ['98', '101']}; {'id': '98', 'type': 'attribute', 'children': ['99', '100']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'exception'}; {'id': '101', 'type': 'argument_list', 'children': ['102']}; {'id': '102', 'type': 'binary_operator', 'children': ['103', '104'], 'value': '%'}; {'id': '103', 'type': 'string', 'children': [], 'value': "'Error waiting for %i...'"}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'cpid'}; {'id': '105', 'type': 'finally_clause', 'children': ['106']}; {'id': '106', 'type': 'block', 'children': ['107']}; {'id': '107', 'type': 'expression_statement', 'children': ['108']}; {'id': '108', 'type': 'call', 'children': ['109', '114']}; {'id': '109', 'type': 'attribute', 'children': ['110', '113']}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'sandboxes'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '114', 'type': 'argument_list', 'children': ['115', '116']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'cpid'}; {'id': '116', 'type': 'None', 'children': []}
|
Stop all the workers, and then wait for them
|
def generate_ngrams(args, parser):
store = utils.get_data_store(args)
corpus = utils.get_corpus(args)
if args.catalogue:
catalogue = utils.get_catalogue(args)
else:
catalogue = None
store.add_ngrams(corpus, args.min_size, args.max_size, catalogue)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'generate_ngrams'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'parser'}; {'id': '6', 'type': 'block', 'children': ['7', '16', '25', '45']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'store'}; {'id': '10', 'type': 'call', 'children': ['11', '14']}; {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'get_data_store'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}; {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'corpus'}; {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'get_corpus'}; {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '25', 'type': 'if_statement', 'children': ['26', '29', '39']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'catalogue'}; {'id': '29', 'type': 'block', 'children': ['30']}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}; {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'catalogue'}; {'id': '33', 'type': 'call', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'get_catalogue'}; {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '39', 'type': 'else_clause', 'children': ['40']}; {'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': 'catalogue'}; {'id': '44', 'type': 'None', 'children': []}; {'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': 'store'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'add_ngrams'}; {'id': '50', 'type': 'argument_list', 'children': ['51', '52', '55', '58']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'corpus'}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'min_size'}; {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'max_size'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'catalogue'}
|
Adds n-grams data to the data store.
|
def load(config_file):
with open(config_file, "r") as f:
def env_get():
return dict(os.environ)
tmpl = Template(f.read())
return Config(yaml.load(tmpl.render(**env_get())))
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'load'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'config_file'}; {'id': '5', 'type': 'block', 'children': ['6']}; {'id': '6', 'type': 'with_statement', 'children': ['7', '17']}; {'id': '7', 'type': 'with_clause', 'children': ['8']}; {'id': '8', 'type': 'with_item', 'children': ['9']}; {'id': '9', 'type': 'as_pattern', 'children': ['10', '15']}; {'id': '10', 'type': 'call', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '12', 'type': 'argument_list', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'config_file'}; {'id': '14', 'type': 'string', 'children': [], 'value': '"r"'}; {'id': '15', 'type': 'as_pattern_target', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '17', 'type': 'block', 'children': ['18', '29', '40']}; {'id': '18', 'type': 'function_definition', 'children': ['19', '20', '21']}; {'id': '19', 'type': 'function_name', 'children': [], 'value': 'env_get'}; {'id': '20', 'type': 'parameters', 'children': []}; {'id': '21', 'type': 'block', 'children': ['22']}; {'id': '22', 'type': 'return_statement', 'children': ['23']}; {'id': '23', 'type': 'call', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'environ'}; {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'tmpl'}; {'id': '32', 'type': 'call', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'Template'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}; {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'read'}; {'id': '39', 'type': 'argument_list', 'children': []}; {'id': '40', 'type': 'return_statement', 'children': ['41']}; {'id': '41', 'type': 'call', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'Config'}; {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'call', 'children': ['45', '48']}; {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'yaml'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'load'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}; {'id': '49', 'type': 'call', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'tmpl'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'render'}; {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'dictionary_splat', 'children': ['55']}; {'id': '55', 'type': 'call', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'env_get'}; {'id': '57', 'type': 'argument_list', 'children': []}
|
Processes and loads config file.
|
def crop_to_sheet(self,sheet_coord_system):
"Crop the slice to the SheetCoordinateSystem's bounds."
maxrow,maxcol = sheet_coord_system.shape
self[0] = max(0,self[0])
self[1] = min(maxrow,self[1])
self[2] = max(0,self[2])
self[3] = min(maxcol,self[3])
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'crop_to_sheet'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'sheet_coord_system'}; {'id': '6', 'type': 'block', 'children': ['7', '9', '17', '29', '41', '53']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'string', 'children': [], 'value': '"Crop the slice to the SheetCoordinateSystem\'s bounds."'}; {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '14']}; {'id': '11', 'type': 'pattern_list', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'maxrow'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'maxcol'}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'sheet_coord_system'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '22']}; {'id': '19', 'type': 'subscript', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '21', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '22', 'type': 'call', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '24', 'type': 'argument_list', 'children': ['25', '26']}; {'id': '25', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '26', 'type': 'subscript', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '28', 'type': 'integer', 'children': [], 'value': '0'}; {'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': 'self'}; {'id': '33', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '34', 'type': 'call', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'min'}; {'id': '36', 'type': 'argument_list', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'maxrow'}; {'id': '38', 'type': 'subscript', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '40', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '46']}; {'id': '43', 'type': 'subscript', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '45', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '46', 'type': 'call', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '48', 'type': 'argument_list', 'children': ['49', '50']}; {'id': '49', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '50', 'type': 'subscript', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '52', 'type': 'integer', 'children': [], 'value': '2'}; {'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': 'self'}; {'id': '57', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '58', 'type': 'call', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'min'}; {'id': '60', 'type': 'argument_list', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'maxcol'}; {'id': '62', 'type': 'subscript', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '64', 'type': 'integer', 'children': [], 'value': '3'}
|
Crop the slice to the SheetCoordinateSystem's bounds.
|
def removeIndividual(self, individual):
q = models.Individual.delete().where(
models.Individual.id == individual.getId())
q.execute()
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'removeIndividual'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'individual'}; {'id': '6', 'type': 'block', 'children': ['7', '32']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'q'}; {'id': '10', 'type': 'call', 'children': ['11', '20']}; {'id': '11', 'type': 'attribute', 'children': ['12', '19']}; {'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': 'models'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'Individual'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'delete'}; {'id': '18', 'type': 'argument_list', 'children': []}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'where'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}; {'id': '21', 'type': 'comparison_operator', 'children': ['22', '27'], 'value': '=='}; {'id': '22', 'type': 'attribute', 'children': ['23', '26']}; {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'models'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'Individual'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'individual'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'getId'}; {'id': '31', 'type': 'argument_list', 'children': []}; {'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': 'q'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'execute'}; {'id': '37', 'type': 'argument_list', 'children': []}
|
Removes the specified individual from this repository.
|
def update_insert_values(bel_resource: Mapping, mapping: Mapping[str, Tuple[str, str]], values: Dict[str, str]) -> None:
for database_column, (section, key) in mapping.items():
if section in bel_resource and key in bel_resource[section]:
values[database_column] = bel_resource[section][key]
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '34', '36']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'update_insert_values'}; {'id': '3', 'type': 'parameters', 'children': ['4', '8', '24']}; {'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'bel_resource'}; {'id': '6', 'type': 'type', 'children': ['7']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'Mapping'}; {'id': '8', 'type': 'typed_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'mapping'}; {'id': '10', 'type': 'type', 'children': ['11']}; {'id': '11', 'type': 'generic_type', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'Mapping'}; {'id': '13', 'type': 'type_parameter', 'children': ['14', '16']}; {'id': '14', 'type': 'type', 'children': ['15']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '16', 'type': 'type', 'children': ['17']}; {'id': '17', 'type': 'generic_type', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'Tuple'}; {'id': '19', 'type': 'type_parameter', 'children': ['20', '22']}; {'id': '20', 'type': 'type', 'children': ['21']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '22', 'type': 'type', 'children': ['23']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '24', 'type': 'typed_parameter', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '26', 'type': 'type', 'children': ['27']}; {'id': '27', 'type': 'generic_type', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'Dict'}; {'id': '29', 'type': 'type_parameter', 'children': ['30', '32']}; {'id': '30', 'type': 'type', 'children': ['31']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '32', 'type': 'type', 'children': ['33']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '34', 'type': 'type', 'children': ['35']}; {'id': '35', 'type': 'None', 'children': []}; {'id': '36', 'type': 'block', 'children': ['37']}; {'id': '37', 'type': 'for_statement', 'children': ['38', '43', '48']}; {'id': '38', 'type': 'pattern_list', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'database_column'}; {'id': '40', 'type': 'tuple_pattern', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'section'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '43', 'type': 'call', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'mapping'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '47', 'type': 'argument_list', 'children': []}; {'id': '48', 'type': 'block', 'children': ['49']}; {'id': '49', 'type': 'if_statement', 'children': ['50', '59']}; {'id': '50', 'type': 'boolean_operator', 'children': ['51', '54'], 'value': 'and'}; {'id': '51', 'type': 'comparison_operator', 'children': ['52', '53'], 'value': 'in'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'section'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'bel_resource'}; {'id': '54', 'type': 'comparison_operator', 'children': ['55', '56'], 'value': 'in'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '56', 'type': 'subscript', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'bel_resource'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'section'}; {'id': '59', 'type': 'block', 'children': ['60']}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}; {'id': '61', 'type': 'assignment', 'children': ['62', '65']}; {'id': '62', 'type': 'subscript', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'database_column'}; {'id': '65', 'type': 'subscript', 'children': ['66', '69']}; {'id': '66', 'type': 'subscript', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'bel_resource'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'section'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'key'}
|
Update the value dictionary with a BEL resource dictionary.
|
def allow_user(user):
def processor(action, argument):
db.session.add(
ActionUsers.allow(action, argument=argument, user_id=user.id)
)
return processor
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'allow_user'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'user'}; {'id': '5', 'type': 'block', 'children': ['6', '34']}; {'id': '6', 'type': 'function_definition', 'children': ['7', '8', '11']}; {'id': '7', 'type': 'function_name', 'children': [], 'value': 'processor'}; {'id': '8', 'type': 'parameters', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'argument'}; {'id': '11', 'type': 'block', 'children': ['12']}; {'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': 'db'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'session'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'call', 'children': ['21', '24']}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'ActionUsers'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'allow'}; {'id': '24', 'type': 'argument_list', 'children': ['25', '26', '29']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '26', 'type': 'keyword_argument', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'argument'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'argument'}; {'id': '29', 'type': 'keyword_argument', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'user_id'}; {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'user'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '34', 'type': 'return_statement', 'children': ['35']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'processor'}
|
Allow a user identified by an email address.
|
def output_vlan(gandi, vlan, datacenters, output_keys, justify=10):
output_generic(gandi, vlan, output_keys, justify)
if 'dc' in output_keys:
for dc in datacenters:
if dc['id'] == vlan.get('datacenter_id',
vlan.get('datacenter', {}).get('id')):
dc_name = dc.get('dc_code', dc.get('iso', ''))
break
output_line(gandi, 'datacenter', dc_name, justify)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'output_vlan'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'gandi'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'vlan'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'datacenters'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'output_keys'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'justify'}; {'id': '10', 'type': 'integer', 'children': [], 'value': '10'}; {'id': '11', 'type': 'block', 'children': ['12', '20']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}; {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'output_generic'}; {'id': '15', 'type': 'argument_list', 'children': ['16', '17', '18', '19']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'gandi'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'vlan'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'output_keys'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'justify'}; {'id': '20', 'type': 'if_statement', 'children': ['21', '24']}; {'id': '21', 'type': 'comparison_operator', 'children': ['22', '23'], 'value': 'in'}; {'id': '22', 'type': 'string', 'children': [], 'value': "'dc'"}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'output_keys'}; {'id': '24', 'type': 'block', 'children': ['25', '70']}; {'id': '25', 'type': 'for_statement', 'children': ['26', '27', '28']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'dc'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'datacenters'}; {'id': '28', 'type': 'block', 'children': ['29']}; {'id': '29', 'type': 'if_statement', 'children': ['30', '52']}; {'id': '30', 'type': 'comparison_operator', 'children': ['31', '34'], 'value': '=='}; {'id': '31', 'type': 'subscript', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'dc'}; {'id': '33', 'type': 'string', 'children': [], 'value': "'id'"}; {'id': '34', 'type': 'call', 'children': ['35', '38']}; {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'vlan'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '38', 'type': 'argument_list', 'children': ['39', '40']}; {'id': '39', 'type': 'string', 'children': [], 'value': "'datacenter_id'"}; {'id': '40', 'type': 'call', 'children': ['41', '50']}; {'id': '41', 'type': 'attribute', 'children': ['42', '49']}; {'id': '42', 'type': 'call', 'children': ['43', '46']}; {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'vlan'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '46', 'type': 'argument_list', 'children': ['47', '48']}; {'id': '47', 'type': 'string', 'children': [], 'value': "'datacenter'"}; {'id': '48', 'type': 'dictionary', 'children': []}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}; {'id': '51', 'type': 'string', 'children': [], 'value': "'id'"}; {'id': '52', 'type': 'block', 'children': ['53', '69']}; {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'dc_name'}; {'id': '56', 'type': 'call', 'children': ['57', '60']}; {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'dc'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '60', 'type': 'argument_list', 'children': ['61', '62']}; {'id': '61', 'type': 'string', 'children': [], 'value': "'dc_code'"}; {'id': '62', 'type': 'call', 'children': ['63', '66']}; {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'dc'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '66', 'type': 'argument_list', 'children': ['67', '68']}; {'id': '67', 'type': 'string', 'children': [], 'value': "'iso'"}; {'id': '68', 'type': 'string', 'children': [], 'value': "''"}; {'id': '69', 'type': 'break_statement', 'children': []}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}; {'id': '71', 'type': 'call', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'output_line'}; {'id': '73', 'type': 'argument_list', 'children': ['74', '75', '76', '77']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'gandi'}; {'id': '75', 'type': 'string', 'children': [], 'value': "'datacenter'"}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'dc_name'}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'justify'}
|
Helper to output a vlan information.
|
def submit_url(self, url, params={}, _extra_params={}):
self._check_user_parameters(params)
params = copy.copy(params)
params['url'] = url
return self._submit(params, _extra_params=_extra_params)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'submit_url'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '8', 'type': 'dictionary', 'children': []}; {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': '_extra_params'}; {'id': '11', 'type': 'dictionary', 'children': []}; {'id': '12', 'type': 'block', 'children': ['13', '20', '29', '35']}; {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'call', 'children': ['15', '18']}; {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': '_check_user_parameters'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}; {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '23', 'type': 'call', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'params'}; {'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': 'params'}; {'id': '33', 'type': 'string', 'children': [], 'value': "'url'"}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '35', 'type': 'return_statement', 'children': ['36']}; {'id': '36', 'type': 'call', 'children': ['37', '40']}; {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': '_submit'}; {'id': '40', 'type': 'argument_list', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '42', 'type': 'keyword_argument', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': '_extra_params'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': '_extra_params'}
|
Submit a website for analysis.
|
def data_context(fn, mode="r"):
with open(data_context_name(fn), mode) as f:
return f.read()
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'data_context'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'fn'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '7', 'type': 'string', 'children': [], 'value': '"r"'}; {'id': '8', 'type': 'block', 'children': ['9']}; {'id': '9', 'type': 'with_statement', 'children': ['10', '23']}; {'id': '10', 'type': 'with_clause', 'children': ['11']}; {'id': '11', 'type': 'with_item', 'children': ['12']}; {'id': '12', 'type': 'as_pattern', 'children': ['13', '21']}; {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '15', 'type': 'argument_list', 'children': ['16', '20']}; {'id': '16', 'type': 'call', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'data_context_name'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'fn'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '21', 'type': 'as_pattern_target', 'children': ['22']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '23', 'type': 'block', 'children': ['24']}; {'id': '24', 'type': 'return_statement', 'children': ['25']}; {'id': '25', 'type': 'call', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'read'}; {'id': '29', 'type': 'argument_list', 'children': []}
|
Return content fo the `fn` from the `template_data` directory.
|
def customer(self):
url = self._get_link('customer')
if url:
resp = self.client.customers.perform_api_call(self.client.customers.REST_READ, url)
return Customer(resp)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'customer'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '15']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'url'}; {'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': '_get_link'}; {'id': '13', 'type': 'argument_list', 'children': ['14']}; {'id': '14', 'type': 'string', 'children': [], 'value': "'customer'"}; {'id': '15', 'type': 'if_statement', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '17', 'type': 'block', 'children': ['18', '38']}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}; {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'resp'}; {'id': '21', 'type': 'call', 'children': ['22', '29']}; {'id': '22', 'type': 'attribute', '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': 'client'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'customers'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'perform_api_call'}; {'id': '29', 'type': 'argument_list', 'children': ['30', '37']}; {'id': '30', 'type': 'attribute', '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': 'client'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'customers'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'REST_READ'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '38', 'type': 'return_statement', 'children': ['39']}; {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'Customer'}; {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'resp'}
|
Return the customer for this subscription.
|
def gather_metrics(self, runs):
for run_dirs in runs.values():
with open(JSON_METRICS_FILE, 'w') as ostr:
ostr.write('[\n')
for i in range(len(run_dirs)):
with open(osp.join(run_dirs[i], YAML_REPORT_FILE)) as istr:
data = yaml.safe_load(istr)
data.pop('category', None)
data.pop('command', None)
data['id'] = run_dirs[i]
json.dump(data, ostr, indent=2)
if i != len(run_dirs) - 1:
ostr.write(',')
ostr.write('\n')
ostr.write(']\n')
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'gather_metrics'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'runs'}; {'id': '6', 'type': 'block', 'children': ['7']}; {'id': '7', 'type': 'for_statement', 'children': ['8', '9', '14']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'run_dirs'}; {'id': '9', 'type': 'call', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'runs'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '13', 'type': 'argument_list', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15']}; {'id': '15', 'type': 'with_statement', 'children': ['16', '26']}; {'id': '16', 'type': 'with_clause', 'children': ['17']}; {'id': '17', 'type': 'with_item', 'children': ['18']}; {'id': '18', 'type': 'as_pattern', 'children': ['19', '24']}; {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '21', 'type': 'argument_list', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'JSON_METRICS_FILE'}; {'id': '23', 'type': 'string', 'children': [], 'value': "'w'"}; {'id': '24', 'type': 'as_pattern_target', 'children': ['25']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'ostr'}; {'id': '26', 'type': 'block', 'children': ['27', '34', '131']}; {'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': 'ostr'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}; {'id': '33', 'type': 'string', 'children': [], 'value': "'[\\n'"}; {'id': '34', 'type': 'for_statement', 'children': ['35', '36', '43']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '36', 'type': 'call', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}; {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'run_dirs'}; {'id': '43', 'type': 'block', 'children': ['44', '107', '124']}; {'id': '44', 'type': 'with_statement', 'children': ['45', '62']}; {'id': '45', 'type': 'with_clause', 'children': ['46']}; {'id': '46', 'type': 'with_item', 'children': ['47']}; {'id': '47', 'type': 'as_pattern', 'children': ['48', '60']}; {'id': '48', 'type': 'call', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'open'}; {'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': 'osp'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '55', 'type': 'argument_list', 'children': ['56', '59']}; {'id': '56', 'type': 'subscript', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'run_dirs'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'YAML_REPORT_FILE'}; {'id': '60', 'type': 'as_pattern_target', 'children': ['61']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'istr'}; {'id': '62', 'type': 'block', 'children': ['63', '72', '80', '88', '96']}; {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '66', 'type': 'call', 'children': ['67', '70']}; {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'yaml'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'safe_load'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'istr'}; {'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': 'data'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '77', 'type': 'argument_list', 'children': ['78', '79']}; {'id': '78', 'type': 'string', 'children': [], 'value': "'category'"}; {'id': '79', 'type': 'None', 'children': []}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}; {'id': '81', 'type': 'call', 'children': ['82', '85']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '85', 'type': 'argument_list', 'children': ['86', '87']}; {'id': '86', 'type': 'string', 'children': [], 'value': "'command'"}; {'id': '87', 'type': 'None', 'children': []}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}; {'id': '89', 'type': 'assignment', 'children': ['90', '93']}; {'id': '90', 'type': 'subscript', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '92', 'type': 'string', 'children': [], 'value': "'id'"}; {'id': '93', 'type': 'subscript', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'run_dirs'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'i'}; {'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': 'json'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'dump'}; {'id': '101', 'type': 'argument_list', 'children': ['102', '103', '104']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'ostr'}; {'id': '104', 'type': 'keyword_argument', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'indent'}; {'id': '106', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '107', 'type': 'if_statement', 'children': ['108', '116']}; {'id': '108', 'type': 'comparison_operator', 'children': ['109', '110'], 'value': '!='}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '110', 'type': 'binary_operator', 'children': ['111', '115'], 'value': '-'}; {'id': '111', 'type': 'call', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '113', 'type': 'argument_list', 'children': ['114']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'run_dirs'}; {'id': '115', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '116', 'type': 'block', 'children': ['117']}; {'id': '117', 'type': 'expression_statement', 'children': ['118']}; {'id': '118', 'type': 'call', 'children': ['119', '122']}; {'id': '119', 'type': 'attribute', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'ostr'}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '122', 'type': 'argument_list', 'children': ['123']}; {'id': '123', 'type': 'string', 'children': [], 'value': "','"}; {'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': 'ostr'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '129', 'type': 'argument_list', 'children': ['130']}; {'id': '130', 'type': 'string', 'children': [], 'value': "'\\n'"}; {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'call', 'children': ['133', '136']}; {'id': '133', 'type': 'attribute', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'ostr'}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '136', 'type': 'argument_list', 'children': ['137']}; {'id': '137', 'type': 'string', 'children': [], 'value': "']\\n'"}
|
Write a JSON file with the result of every runs
|
async def handle_agent_job_started(self, agent_addr, message: AgentJobStarted):
self._logger.debug("Job %s %s started on agent %s", message.job_id[0], message.job_id[1], agent_addr)
await ZMQUtils.send_with_addr(self._client_socket, message.job_id[0], BackendJobStarted(message.job_id[1]))
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'handle_agent_job_started'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'agent_addr'}; {'id': '6', 'type': 'typed_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '8', 'type': 'type', 'children': ['9']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'AgentJobStarted'}; {'id': '10', 'type': 'block', 'children': ['11', '31']}; {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'call', 'children': ['13', '18']}; {'id': '13', 'type': 'attribute', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': '_logger'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '18', 'type': 'argument_list', 'children': ['19', '20', '25', '30']}; {'id': '19', 'type': 'string', 'children': [], 'value': '"Job %s %s started on agent %s"'}; {'id': '20', 'type': 'subscript', 'children': ['21', '24']}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'job_id'}; {'id': '24', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '25', 'type': 'subscript', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'job_id'}; {'id': '29', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'agent_addr'}; {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'await', 'children': ['33']}; {'id': '33', 'type': 'call', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'ZMQUtils'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'send_with_addr'}; {'id': '37', 'type': 'argument_list', 'children': ['38', '41', '46']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': '_client_socket'}; {'id': '41', 'type': 'subscript', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'job_id'}; {'id': '45', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '46', 'type': 'call', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'BackendJobStarted'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}; {'id': '49', 'type': 'subscript', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'job_id'}; {'id': '53', 'type': 'integer', 'children': [], 'value': '1'}
|
Handle an AgentJobStarted message. Send the data back to the client
|
def meth_acl(args):
r = fapi.get_repository_method_acl(args.namespace, args.method,
args.snapshot_id)
fapi._check_response_code(r, 200)
acls = sorted(r.json(), key=lambda k: k['user'])
return map(lambda acl: '{0}\t{1}'.format(acl['user'], acl['role']), acls)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'meth_acl'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '5', 'type': 'block', 'children': ['6', '23', '31', '50']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '9', 'type': 'call', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'fapi'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'get_repository_method_acl'}; {'id': '13', 'type': 'argument_list', 'children': ['14', '17', '20']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'namespace'}; {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'snapshot_id'}; {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'call', 'children': ['25', '28']}; {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'fapi'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': '_check_response_code'}; {'id': '28', 'type': 'argument_list', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '30', 'type': 'integer', 'children': [], 'value': '200'}; {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'acls'}; {'id': '34', 'type': 'call', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '36', 'type': 'argument_list', 'children': ['37', '42']}; {'id': '37', 'type': 'call', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '41', 'type': 'argument_list', 'children': []}; {'id': '42', 'type': 'keyword_argument', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '44', 'type': 'lambda', 'children': ['45', '47']}; {'id': '45', 'type': 'lambda_parameters', 'children': ['46']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '47', 'type': 'subscript', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '49', 'type': 'string', 'children': [], 'value': "'user'"}; {'id': '50', 'type': 'return_statement', 'children': ['51']}; {'id': '51', 'type': 'call', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'map'}; {'id': '53', 'type': 'argument_list', 'children': ['54', '68']}; {'id': '54', 'type': 'lambda', 'children': ['55', '57']}; {'id': '55', 'type': 'lambda_parameters', 'children': ['56']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'acl'}; {'id': '57', 'type': 'call', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}; {'id': '59', 'type': 'string', 'children': [], 'value': "'{0}\\t{1}'"}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '61', 'type': 'argument_list', 'children': ['62', '65']}; {'id': '62', 'type': 'subscript', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'acl'}; {'id': '64', 'type': 'string', 'children': [], 'value': "'user'"}; {'id': '65', 'type': 'subscript', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'acl'}; {'id': '67', 'type': 'string', 'children': [], 'value': "'role'"}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'acls'}
|
Retrieve access control list for given version of a repository method
|
def _compute_fval(X, A, R, P, Z, lmbdaA, lmbdaR, lmbdaZ, normX):
f = lmbdaA * norm(A) ** 2
for i in range(len(X)):
ARAt = dot(A, dot(R[i], A.T))
f += (norm(X[i] - ARAt) ** 2) / normX[i] + lmbdaR * norm(R[i]) ** 2
return f
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_compute_fval'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '10', '11', '12']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'A'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'R'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'P'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'Z'}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'lmbdaA'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'lmbdaR'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'lmbdaZ'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'normX'}; {'id': '13', 'type': 'block', 'children': ['14', '25', '80']}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}; {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '17', 'type': 'binary_operator', 'children': ['18', '19'], 'value': '*'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'lmbdaA'}; {'id': '19', 'type': 'binary_operator', 'children': ['20', '24'], 'value': '**'}; {'id': '20', 'type': 'call', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'norm'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'A'}; {'id': '24', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '25', 'type': 'for_statement', 'children': ['26', '27', '34']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'call', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '34', 'type': 'block', 'children': ['35', '51']}; {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'ARAt'}; {'id': '38', 'type': 'call', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'dot'}; {'id': '40', 'type': 'argument_list', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'A'}; {'id': '42', 'type': 'call', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'dot'}; {'id': '44', 'type': 'argument_list', 'children': ['45', '48']}; {'id': '45', 'type': 'subscript', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'R'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'A'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'T'}; {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'augmented_assignment', 'children': ['53', '54'], 'value': '+='}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '54', 'type': 'binary_operator', 'children': ['55', '70'], 'value': '+'}; {'id': '55', 'type': 'binary_operator', 'children': ['56', '67'], 'value': '/'}; {'id': '56', 'type': '()', 'children': ['57']}; {'id': '57', 'type': 'binary_operator', 'children': ['58', '66'], 'value': '**'}; {'id': '58', 'type': 'call', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'norm'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}; {'id': '61', 'type': 'binary_operator', 'children': ['62', '65'], 'value': '-'}; {'id': '62', 'type': 'subscript', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'ARAt'}; {'id': '66', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '67', 'type': 'subscript', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'normX'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '70', 'type': 'binary_operator', 'children': ['71', '72'], 'value': '*'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'lmbdaR'}; {'id': '72', 'type': 'binary_operator', 'children': ['73', '79'], 'value': '**'}; {'id': '73', 'type': 'call', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'norm'}; {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'subscript', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'R'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '79', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '80', 'type': 'return_statement', 'children': ['81']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'f'}
|
Compute fit for full slices
|
def browse_outdir(self):
self.dirsel.popup(
'Select directory', self.w.outdir.set_text, initialdir=self.outdir)
self.set_outdir()
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'browse_outdir'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '27']}; {'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': 'dirsel'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'popup'}; {'id': '13', 'type': 'argument_list', 'children': ['14', '15', '22']}; {'id': '14', 'type': 'string', 'children': [], 'value': "'Select directory'"}; {'id': '15', 'type': 'attribute', 'children': ['16', '21']}; {'id': '16', 'type': 'attribute', 'children': ['17', '20']}; {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'w'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'outdir'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'set_text'}; {'id': '22', 'type': 'keyword_argument', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'initialdir'}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'outdir'}; {'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': 'set_outdir'}; {'id': '32', 'type': 'argument_list', 'children': []}
|
Browse for output directory.
|
def to_datetime(t):
if t is None:
return None
year, mon, day, h, m, s = t
try:
return datetime(year, mon, day, h, m, s)
except ValueError:
pass
mday = (0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
if mon < 1:
mon = 1
if mon > 12:
mon = 12
if day < 1:
day = 1
if day > mday[mon]:
day = mday[mon]
if h > 23:
h = 23
if m > 59:
m = 59
if s > 59:
s = 59
if mon == 2 and day == 29:
try:
return datetime(year, mon, day, h, m, s)
except ValueError:
day = 28
return datetime(year, mon, day, h, m, s)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'to_datetime'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '5', 'type': 'block', 'children': ['6', '13', '23', '39', '56', '65', '74', '83', '96', '105', '114', '123', '151']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '10']}; {'id': '7', 'type': 'comparison_operator', 'children': ['8', '9'], 'value': 'is'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '9', 'type': 'None', 'children': []}; {'id': '10', 'type': 'block', 'children': ['11']}; {'id': '11', 'type': 'return_statement', 'children': ['12']}; {'id': '12', 'type': 'None', 'children': []}; {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '22']}; {'id': '15', 'type': 'pattern_list', 'children': ['16', '17', '18', '19', '20', '21']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'year'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'mon'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'day'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'h'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '23', 'type': 'try_statement', 'children': ['24', '35']}; {'id': '24', 'type': 'block', 'children': ['25']}; {'id': '25', 'type': 'return_statement', 'children': ['26']}; {'id': '26', 'type': 'call', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '28', 'type': 'argument_list', 'children': ['29', '30', '31', '32', '33', '34']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'year'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'mon'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'day'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'h'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '35', 'type': 'except_clause', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '37', 'type': 'block', 'children': ['38']}; {'id': '38', 'type': 'pass_statement', 'children': []}; {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'mday'}; {'id': '42', 'type': 'tuple', 'children': ['43', '44', '45', '46', '47', '48', '49', '50', '51', '52', '53', '54', '55']}; {'id': '43', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '44', 'type': 'integer', 'children': [], 'value': '31'}; {'id': '45', 'type': 'integer', 'children': [], 'value': '29'}; {'id': '46', 'type': 'integer', 'children': [], 'value': '31'}; {'id': '47', 'type': 'integer', 'children': [], 'value': '30'}; {'id': '48', 'type': 'integer', 'children': [], 'value': '31'}; {'id': '49', 'type': 'integer', 'children': [], 'value': '30'}; {'id': '50', 'type': 'integer', 'children': [], 'value': '31'}; {'id': '51', 'type': 'integer', 'children': [], 'value': '31'}; {'id': '52', 'type': 'integer', 'children': [], 'value': '30'}; {'id': '53', 'type': 'integer', 'children': [], 'value': '31'}; {'id': '54', 'type': 'integer', 'children': [], 'value': '30'}; {'id': '55', 'type': 'integer', 'children': [], 'value': '31'}; {'id': '56', 'type': 'if_statement', 'children': ['57', '60']}; {'id': '57', 'type': 'comparison_operator', 'children': ['58', '59'], 'value': '<'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'mon'}; {'id': '59', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '60', 'type': 'block', 'children': ['61']}; {'id': '61', 'type': 'expression_statement', 'children': ['62']}; {'id': '62', 'type': 'assignment', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'mon'}; {'id': '64', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '65', 'type': 'if_statement', 'children': ['66', '69']}; {'id': '66', 'type': 'comparison_operator', 'children': ['67', '68'], 'value': '>'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'mon'}; {'id': '68', 'type': 'integer', 'children': [], 'value': '12'}; {'id': '69', 'type': 'block', 'children': ['70']}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}; {'id': '71', 'type': 'assignment', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'mon'}; {'id': '73', 'type': 'integer', 'children': [], 'value': '12'}; {'id': '74', 'type': 'if_statement', 'children': ['75', '78']}; {'id': '75', 'type': 'comparison_operator', 'children': ['76', '77'], 'value': '<'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'day'}; {'id': '77', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '78', 'type': 'block', 'children': ['79']}; {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'day'}; {'id': '82', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '83', 'type': 'if_statement', 'children': ['84', '89']}; {'id': '84', 'type': 'comparison_operator', 'children': ['85', '86'], 'value': '>'}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'day'}; {'id': '86', 'type': 'subscript', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'mday'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'mon'}; {'id': '89', 'type': 'block', 'children': ['90']}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}; {'id': '91', 'type': 'assignment', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'day'}; {'id': '93', 'type': 'subscript', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'mday'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'mon'}; {'id': '96', 'type': 'if_statement', 'children': ['97', '100']}; {'id': '97', 'type': 'comparison_operator', 'children': ['98', '99'], 'value': '>'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'h'}; {'id': '99', 'type': 'integer', 'children': [], 'value': '23'}; {'id': '100', 'type': 'block', 'children': ['101']}; {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'assignment', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'h'}; {'id': '104', 'type': 'integer', 'children': [], 'value': '23'}; {'id': '105', 'type': 'if_statement', 'children': ['106', '109']}; {'id': '106', 'type': 'comparison_operator', 'children': ['107', '108'], 'value': '>'}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '108', 'type': 'integer', 'children': [], 'value': '59'}; {'id': '109', 'type': 'block', 'children': ['110']}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}; {'id': '111', 'type': 'assignment', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '113', 'type': 'integer', 'children': [], 'value': '59'}; {'id': '114', 'type': 'if_statement', 'children': ['115', '118']}; {'id': '115', 'type': 'comparison_operator', 'children': ['116', '117'], 'value': '>'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '117', 'type': 'integer', 'children': [], 'value': '59'}; {'id': '118', 'type': 'block', 'children': ['119']}; {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'assignment', 'children': ['121', '122']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '122', 'type': 'integer', 'children': [], 'value': '59'}; {'id': '123', 'type': 'if_statement', 'children': ['124', '131']}; {'id': '124', 'type': 'boolean_operator', 'children': ['125', '128'], 'value': 'and'}; {'id': '125', 'type': 'comparison_operator', 'children': ['126', '127'], 'value': '=='}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'mon'}; {'id': '127', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '128', 'type': 'comparison_operator', 'children': ['129', '130'], 'value': '=='}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'day'}; {'id': '130', 'type': 'integer', 'children': [], 'value': '29'}; {'id': '131', 'type': 'block', 'children': ['132']}; {'id': '132', 'type': 'try_statement', 'children': ['133', '144']}; {'id': '133', 'type': 'block', 'children': ['134']}; {'id': '134', 'type': 'return_statement', 'children': ['135']}; {'id': '135', 'type': 'call', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '137', 'type': 'argument_list', 'children': ['138', '139', '140', '141', '142', '143']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'year'}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'mon'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'day'}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'h'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '144', 'type': 'except_clause', 'children': ['145', '146']}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '146', 'type': 'block', 'children': ['147']}; {'id': '147', 'type': 'expression_statement', 'children': ['148']}; {'id': '148', 'type': 'assignment', 'children': ['149', '150']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'day'}; {'id': '150', 'type': 'integer', 'children': [], 'value': '28'}; {'id': '151', 'type': 'return_statement', 'children': ['152']}; {'id': '152', 'type': 'call', 'children': ['153', '154']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '154', 'type': 'argument_list', 'children': ['155', '156', '157', '158', '159', '160']}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'year'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'mon'}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'day'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'h'}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 's'}
|
Convert 6-part time tuple into datetime object.
|
def total(self):
total = 0
for item in self.items.all():
total += item.total
return total
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'total'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '10', '26']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'total'}; {'id': '9', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '10', 'type': 'for_statement', 'children': ['11', '12', '19']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'item'}; {'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': 'self'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'all'}; {'id': '18', 'type': 'argument_list', 'children': []}; {'id': '19', 'type': 'block', 'children': ['20']}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}; {'id': '21', 'type': 'augmented_assignment', 'children': ['22', '23'], 'value': '+='}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'total'}; {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'total'}; {'id': '26', 'type': 'return_statement', 'children': ['27']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'total'}
|
Total cost of the order
|
def from_kwargs(cls, **kwargs):
config = cls()
for slot in cls.__slots__:
if slot.startswith('_'):
slot = slot[1:]
setattr(config, slot, kwargs.pop(slot, cls.get_default(slot)))
if kwargs:
raise ValueError("Unrecognized option(s): {}".format(kwargs.keys()))
return config
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'from_kwargs'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '5', 'type': 'dictionary_splat_pattern', 'children': ['6']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '7', 'type': 'block', 'children': ['8', '14', '54', '71']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '11', 'type': 'call', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '13', 'type': 'argument_list', 'children': []}; {'id': '14', 'type': 'for_statement', 'children': ['15', '16', '19']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'slot'}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': '__slots__'}; {'id': '19', 'type': 'block', 'children': ['20', '36']}; {'id': '20', 'type': 'if_statement', 'children': ['21', '27']}; {'id': '21', 'type': 'call', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'slot'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'startswith'}; {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'string', 'children': [], 'value': "'_'"}; {'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': 'slot'}; {'id': '31', 'type': 'subscript', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'slot'}; {'id': '33', 'type': 'slice', 'children': ['34', '35']}; {'id': '34', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '35', 'type': 'colon', 'children': []}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}; {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'setattr'}; {'id': '39', 'type': 'argument_list', 'children': ['40', '41', '42']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'slot'}; {'id': '42', 'type': 'call', 'children': ['43', '46']}; {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '46', 'type': 'argument_list', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'slot'}; {'id': '48', 'type': 'call', 'children': ['49', '52']}; {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'get_default'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'slot'}; {'id': '54', 'type': 'if_statement', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '56', 'type': 'block', 'children': ['57']}; {'id': '57', 'type': 'raise_statement', 'children': ['58']}; {'id': '58', 'type': 'call', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}; {'id': '61', 'type': 'call', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}; {'id': '63', 'type': 'string', 'children': [], 'value': '"Unrecognized option(s): {}"'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'call', 'children': ['67', '70']}; {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '70', 'type': 'argument_list', 'children': []}; {'id': '71', 'type': 'return_statement', 'children': ['72']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'config'}
|
Initialise configuration from kwargs.
|
def delete(self):
res = self.session.delete(self.href)
self.emit('deleted', self)
return res
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'delete'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '19', '27']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'res'}; {'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': 'session'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'delete'}; {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'href'}; {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'call', 'children': ['21', '24']}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'emit'}; {'id': '24', 'type': 'argument_list', 'children': ['25', '26']}; {'id': '25', 'type': 'string', 'children': [], 'value': "'deleted'"}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '27', 'type': 'return_statement', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'res'}
|
Delete resource from the API server
|
def super_mro(self):
if not isinstance(self.mro_pointer, scoped_nodes.ClassDef):
raise exceptions.SuperError(
"The first argument to super must be a subtype of "
"type, not {mro_pointer}.",
super_=self,
)
if isinstance(self.type, scoped_nodes.ClassDef):
self._class_based = True
mro_type = self.type
else:
mro_type = getattr(self.type, "_proxied", None)
if not isinstance(mro_type, (bases.Instance, scoped_nodes.ClassDef)):
raise exceptions.SuperError(
"The second argument to super must be an "
"instance or subtype of type, not {type}.",
super_=self,
)
if not mro_type.newstyle:
raise exceptions.SuperError(
"Unable to call super on old-style classes.", super_=self
)
mro = mro_type.mro()
if self.mro_pointer not in mro:
raise exceptions.SuperError(
"The second argument to super must be an "
"instance or subtype of type, not {type}.",
super_=self,
)
index = mro.index(self.mro_pointer)
return mro[index + 1 :]
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'super_mro'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '30', '92', '108', '116', '135', '146']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '17']}; {'id': '7', 'type': 'not_operator', 'children': ['8']}; {'id': '8', 'type': 'call', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '10', 'type': 'argument_list', 'children': ['11', '14']}; {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'mro_pointer'}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'scoped_nodes'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'ClassDef'}; {'id': '17', 'type': 'block', 'children': ['18']}; {'id': '18', 'type': 'raise_statement', 'children': ['19']}; {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'exceptions'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'SuperError'}; {'id': '23', 'type': 'argument_list', 'children': ['24', '27']}; {'id': '24', 'type': 'concatenated_string', 'children': ['25', '26']}; {'id': '25', 'type': 'string', 'children': [], 'value': '"The first argument to super must be a subtype of "'}; {'id': '26', 'type': 'string', 'children': [], 'value': '"type, not {mro_pointer}."'}; {'id': '27', 'type': 'keyword_argument', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'super_'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '30', 'type': 'if_statement', 'children': ['31', '40', '53']}; {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '33', 'type': 'argument_list', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'scoped_nodes'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'ClassDef'}; {'id': '40', 'type': 'block', 'children': ['41', '47']}; {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '46']}; {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': '_class_based'}; {'id': '46', 'type': 'True', 'children': []}; {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'assignment', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'mro_type'}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '53', 'type': 'else_clause', 'children': ['54']}; {'id': '54', 'type': 'block', 'children': ['55', '66']}; {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'mro_type'}; {'id': '58', 'type': 'call', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '60', 'type': 'argument_list', 'children': ['61', '64', '65']}; {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '64', 'type': 'string', 'children': [], 'value': '"_proxied"'}; {'id': '65', 'type': 'None', 'children': []}; {'id': '66', 'type': 'if_statement', 'children': ['67', '79']}; {'id': '67', 'type': 'not_operator', 'children': ['68']}; {'id': '68', 'type': 'call', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '70', 'type': 'argument_list', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'mro_type'}; {'id': '72', 'type': 'tuple', 'children': ['73', '76']}; {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'bases'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'Instance'}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'scoped_nodes'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'ClassDef'}; {'id': '79', 'type': 'block', 'children': ['80']}; {'id': '80', 'type': 'raise_statement', 'children': ['81']}; {'id': '81', 'type': 'call', 'children': ['82', '85']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'exceptions'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'SuperError'}; {'id': '85', 'type': 'argument_list', 'children': ['86', '89']}; {'id': '86', 'type': 'concatenated_string', 'children': ['87', '88']}; {'id': '87', 'type': 'string', 'children': [], 'value': '"The second argument to super must be an "'}; {'id': '88', 'type': 'string', 'children': [], 'value': '"instance or subtype of type, not {type}."'}; {'id': '89', 'type': 'keyword_argument', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'super_'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '92', 'type': 'if_statement', 'children': ['93', '97']}; {'id': '93', 'type': 'not_operator', 'children': ['94']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'mro_type'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'newstyle'}; {'id': '97', 'type': 'block', 'children': ['98']}; {'id': '98', 'type': 'raise_statement', 'children': ['99']}; {'id': '99', 'type': 'call', 'children': ['100', '103']}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'exceptions'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'SuperError'}; {'id': '103', 'type': 'argument_list', 'children': ['104', '105']}; {'id': '104', 'type': 'string', 'children': [], 'value': '"Unable to call super on old-style classes."'}; {'id': '105', 'type': 'keyword_argument', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'super_'}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}; {'id': '109', 'type': 'assignment', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'mro'}; {'id': '111', 'type': 'call', 'children': ['112', '115']}; {'id': '112', 'type': 'attribute', 'children': ['113', '114']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'mro_type'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'mro'}; {'id': '115', 'type': 'argument_list', 'children': []}; {'id': '116', 'type': 'if_statement', 'children': ['117', '122']}; {'id': '117', 'type': 'comparison_operator', 'children': ['118', '121'], 'value': 'not in'}; {'id': '118', 'type': 'attribute', 'children': ['119', '120']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'mro_pointer'}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'mro'}; {'id': '122', 'type': 'block', 'children': ['123']}; {'id': '123', 'type': 'raise_statement', 'children': ['124']}; {'id': '124', 'type': 'call', 'children': ['125', '128']}; {'id': '125', 'type': 'attribute', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'exceptions'}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'SuperError'}; {'id': '128', 'type': 'argument_list', 'children': ['129', '132']}; {'id': '129', 'type': 'concatenated_string', 'children': ['130', '131']}; {'id': '130', 'type': 'string', 'children': [], 'value': '"The second argument to super must be an "'}; {'id': '131', 'type': 'string', 'children': [], 'value': '"instance or subtype of type, not {type}."'}; {'id': '132', 'type': 'keyword_argument', 'children': ['133', '134']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'super_'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '135', 'type': 'expression_statement', 'children': ['136']}; {'id': '136', 'type': 'assignment', 'children': ['137', '138']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '138', 'type': 'call', 'children': ['139', '142']}; {'id': '139', 'type': 'attribute', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'mro'}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '142', 'type': 'argument_list', 'children': ['143']}; {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'mro_pointer'}; {'id': '146', 'type': 'return_statement', 'children': ['147']}; {'id': '147', 'type': 'subscript', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'mro'}; {'id': '149', 'type': 'slice', 'children': ['150', '153']}; {'id': '150', 'type': 'binary_operator', 'children': ['151', '152'], 'value': '+'}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '152', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '153', 'type': 'colon', 'children': []}
|
Get the MRO which will be used to lookup attributes in this super.
|
def insert(self, space_no, *args):
d = self.replyQueue.get()
packet = RequestInsert(self.charset, self.errors, d._ipro_request_id, space_no, Request.TNT_FLAG_ADD, *args)
self.transport.write(bytes(packet))
return d.addCallback(self.handle_reply, self.charset, self.errors, None)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'insert'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'space_no'}; {'id': '6', 'type': 'list_splat_pattern', 'children': ['7']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '8', 'type': 'block', 'children': ['9', '19', '40', '52']}; {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'd'}; {'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': 'self'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'replyQueue'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'get'}; {'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': 'packet'}; {'id': '22', 'type': 'call', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'RequestInsert'}; {'id': '24', 'type': 'argument_list', 'children': ['25', '28', '31', '34', '35', '38']}; {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'charset'}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': '_ipro_request_id'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'space_no'}; {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'Request'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'TNT_FLAG_ADD'}; {'id': '38', 'type': 'list_splat', 'children': ['39']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}; {'id': '41', 'type': 'call', 'children': ['42', '47']}; {'id': '42', 'type': 'attribute', 'children': ['43', '46']}; {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'transport'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'call', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'bytes'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'packet'}; {'id': '52', 'type': 'return_statement', 'children': ['53']}; {'id': '53', 'type': 'call', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'addCallback'}; {'id': '57', 'type': 'argument_list', 'children': ['58', '61', '64', '67']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'handle_reply'}; {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'charset'}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '67', 'type': 'None', 'children': []}
|
insert tuple, if primary key exists server will return error
|
def server_link(rel, server_id=None, self_rel=False):
servers_href = '/v1/servers'
link = _SERVER_LINKS[rel].copy()
link['href'] = link['href'].format(**locals())
link['rel'] = 'self' if self_rel else rel
return link
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'server_link'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'rel'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'server_id'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'self_rel'}; {'id': '10', 'type': 'False', 'children': []}; {'id': '11', 'type': 'block', 'children': ['12', '16', '26', '42', '51']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}; {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'servers_href'}; {'id': '15', 'type': 'string', 'children': [], 'value': "'/v1/servers'"}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}; {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'link'}; {'id': '19', 'type': 'call', 'children': ['20', '25']}; {'id': '20', 'type': 'attribute', 'children': ['21', '24']}; {'id': '21', 'type': 'subscript', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': '_SERVER_LINKS'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'rel'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '25', 'type': 'argument_list', 'children': []}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}; {'id': '27', 'type': 'assignment', 'children': ['28', '31']}; {'id': '28', 'type': 'subscript', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'link'}; {'id': '30', 'type': 'string', 'children': [], 'value': "'href'"}; {'id': '31', 'type': 'call', 'children': ['32', '37']}; {'id': '32', 'type': 'attribute', 'children': ['33', '36']}; {'id': '33', 'type': 'subscript', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'link'}; {'id': '35', 'type': 'string', 'children': [], 'value': "'href'"}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'dictionary_splat', 'children': ['39']}; {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'locals'}; {'id': '41', 'type': 'argument_list', 'children': []}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}; {'id': '43', 'type': 'assignment', 'children': ['44', '47']}; {'id': '44', 'type': 'subscript', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'link'}; {'id': '46', 'type': 'string', 'children': [], 'value': "'rel'"}; {'id': '47', 'type': 'conditional_expression', 'children': ['48', '49', '50'], 'value': 'if'}; {'id': '48', 'type': 'string', 'children': [], 'value': "'self'"}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'self_rel'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'rel'}; {'id': '51', 'type': 'return_statement', 'children': ['52']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'link'}
|
Helper for getting a Server link document, given a rel.
|
def connect_to_cloud_cdn(region=None):
global default_region
if region in ['DFW', 'IAD', 'ORD', 'SYD', 'HKG']:
return _create_client(ep_name="cdn", region="DFW")
elif region in ['LON']:
return _create_client(ep_name="cdn", region="LON")
else:
if default_region in ['DFW', 'IAD', 'ORD', 'SYD', 'HKG']:
return _create_client(ep_name="cdn", region="DFW")
elif default_region in ['LON']:
return _create_client(ep_name="cdn", region="LON")
else:
return _create_client(ep_name="cdn", region=region)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'connect_to_cloud_cdn'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'default_parameter', 'children': ['5', '6']}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'region'}; {'id': '6', 'type': 'None', 'children': []}; {'id': '7', 'type': 'block', 'children': ['8', '10']}; {'id': '8', 'type': 'global_statement', 'children': ['9']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'default_region'}; {'id': '10', 'type': 'if_statement', 'children': ['11', '19', '30', '46']}; {'id': '11', 'type': 'comparison_operator', 'children': ['12', '13'], 'value': 'in'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'region'}; {'id': '13', 'type': 'list', 'children': ['14', '15', '16', '17', '18'], 'value': "['DFW', 'IAD', 'ORD', 'SYD', 'HKG']"}; {'id': '14', 'type': 'string', 'children': [], 'value': "'DFW'"}; {'id': '15', 'type': 'string', 'children': [], 'value': "'IAD'"}; {'id': '16', 'type': 'string', 'children': [], 'value': "'ORD'"}; {'id': '17', 'type': 'string', 'children': [], 'value': "'SYD'"}; {'id': '18', 'type': 'string', 'children': [], 'value': "'HKG'"}; {'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': '_create_client'}; {'id': '23', 'type': 'argument_list', 'children': ['24', '27']}; {'id': '24', 'type': 'keyword_argument', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'ep_name'}; {'id': '26', 'type': 'string', 'children': [], 'value': '"cdn"'}; {'id': '27', 'type': 'keyword_argument', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'region'}; {'id': '29', 'type': 'string', 'children': [], 'value': '"DFW"'}; {'id': '30', 'type': 'elif_clause', 'children': ['31', '35']}; {'id': '31', 'type': 'comparison_operator', 'children': ['32', '33'], 'value': 'in'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'region'}; {'id': '33', 'type': 'list', 'children': ['34'], 'value': "['LON']"}; {'id': '34', 'type': 'string', 'children': [], 'value': "'LON'"}; {'id': '35', 'type': 'block', 'children': ['36']}; {'id': '36', 'type': 'return_statement', 'children': ['37']}; {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': '_create_client'}; {'id': '39', 'type': 'argument_list', 'children': ['40', '43']}; {'id': '40', 'type': 'keyword_argument', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'ep_name'}; {'id': '42', 'type': 'string', 'children': [], 'value': '"cdn"'}; {'id': '43', 'type': 'keyword_argument', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'region'}; {'id': '45', 'type': 'string', 'children': [], 'value': '"LON"'}; {'id': '46', 'type': 'else_clause', 'children': ['47']}; {'id': '47', 'type': 'block', 'children': ['48']}; {'id': '48', 'type': 'if_statement', 'children': ['49', '57', '68', '84']}; {'id': '49', 'type': 'comparison_operator', 'children': ['50', '51'], 'value': 'in'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'default_region'}; {'id': '51', 'type': 'list', 'children': ['52', '53', '54', '55', '56'], 'value': "['DFW', 'IAD', 'ORD', 'SYD', 'HKG']"}; {'id': '52', 'type': 'string', 'children': [], 'value': "'DFW'"}; {'id': '53', 'type': 'string', 'children': [], 'value': "'IAD'"}; {'id': '54', 'type': 'string', 'children': [], 'value': "'ORD'"}; {'id': '55', 'type': 'string', 'children': [], 'value': "'SYD'"}; {'id': '56', 'type': 'string', 'children': [], 'value': "'HKG'"}; {'id': '57', 'type': 'block', 'children': ['58']}; {'id': '58', 'type': 'return_statement', 'children': ['59']}; {'id': '59', 'type': 'call', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': '_create_client'}; {'id': '61', 'type': 'argument_list', 'children': ['62', '65']}; {'id': '62', 'type': 'keyword_argument', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'ep_name'}; {'id': '64', 'type': 'string', 'children': [], 'value': '"cdn"'}; {'id': '65', 'type': 'keyword_argument', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'region'}; {'id': '67', 'type': 'string', 'children': [], 'value': '"DFW"'}; {'id': '68', 'type': 'elif_clause', 'children': ['69', '73']}; {'id': '69', 'type': 'comparison_operator', 'children': ['70', '71'], 'value': 'in'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'default_region'}; {'id': '71', 'type': 'list', 'children': ['72'], 'value': "['LON']"}; {'id': '72', 'type': 'string', 'children': [], 'value': "'LON'"}; {'id': '73', 'type': 'block', 'children': ['74']}; {'id': '74', 'type': 'return_statement', 'children': ['75']}; {'id': '75', 'type': 'call', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': '_create_client'}; {'id': '77', 'type': 'argument_list', 'children': ['78', '81']}; {'id': '78', 'type': 'keyword_argument', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'ep_name'}; {'id': '80', 'type': 'string', 'children': [], 'value': '"cdn"'}; {'id': '81', 'type': 'keyword_argument', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'region'}; {'id': '83', 'type': 'string', 'children': [], 'value': '"LON"'}; {'id': '84', 'type': 'else_clause', 'children': ['85']}; {'id': '85', 'type': 'block', 'children': ['86']}; {'id': '86', 'type': 'return_statement', 'children': ['87']}; {'id': '87', 'type': 'call', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': '_create_client'}; {'id': '89', 'type': 'argument_list', 'children': ['90', '93']}; {'id': '90', 'type': 'keyword_argument', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'ep_name'}; {'id': '92', 'type': 'string', 'children': [], 'value': '"cdn"'}; {'id': '93', 'type': 'keyword_argument', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'region'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'region'}
|
Creates a client for working with cloud loadbalancers.
|
def GetClosestPoint(x, a, b):
assert(x.IsUnitLength())
assert(a.IsUnitLength())
assert(b.IsUnitLength())
a_cross_b = a.RobustCrossProd(b)
p = x.Minus(
a_cross_b.Times(
x.DotProd(a_cross_b) / a_cross_b.Norm2()))
if SimpleCCW(a_cross_b, a, p) and SimpleCCW(p, b, a_cross_b):
return p.Normalize()
if x.Minus(a).Norm2() <= x.Minus(b).Norm2():
return a
else:
return b
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'GetClosestPoint'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '7', 'type': 'block', 'children': ['8', '15', '22', '29', '38', '63', '84']}; {'id': '8', 'type': 'assert_statement', 'children': ['9']}; {'id': '9', 'type': '()', 'children': ['10']}; {'id': '10', 'type': 'call', 'children': ['11', '14']}; {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'IsUnitLength'}; {'id': '14', 'type': 'argument_list', 'children': []}; {'id': '15', 'type': 'assert_statement', 'children': ['16']}; {'id': '16', 'type': '()', 'children': ['17']}; {'id': '17', 'type': 'call', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'IsUnitLength'}; {'id': '21', 'type': 'argument_list', 'children': []}; {'id': '22', 'type': 'assert_statement', 'children': ['23']}; {'id': '23', 'type': '()', 'children': ['24']}; {'id': '24', 'type': 'call', 'children': ['25', '28']}; {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'IsUnitLength'}; {'id': '28', 'type': 'argument_list', 'children': []}; {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'a_cross_b'}; {'id': '32', 'type': 'call', 'children': ['33', '36']}; {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'RobustCrossProd'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}; {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '41', 'type': 'call', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'Minus'}; {'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': 'a_cross_b'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'Times'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}; {'id': '51', 'type': 'binary_operator', 'children': ['52', '58'], 'value': '/'}; {'id': '52', 'type': 'call', 'children': ['53', '56']}; {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'DotProd'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'a_cross_b'}; {'id': '58', 'type': 'call', 'children': ['59', '62']}; {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'a_cross_b'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'Norm2'}; {'id': '62', 'type': 'argument_list', 'children': []}; {'id': '63', 'type': 'if_statement', 'children': ['64', '77']}; {'id': '64', 'type': 'boolean_operator', 'children': ['65', '71'], 'value': 'and'}; {'id': '65', 'type': 'call', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'SimpleCCW'}; {'id': '67', 'type': 'argument_list', 'children': ['68', '69', '70']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'a_cross_b'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '71', 'type': 'call', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'SimpleCCW'}; {'id': '73', 'type': 'argument_list', 'children': ['74', '75', '76']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'a_cross_b'}; {'id': '77', 'type': 'block', 'children': ['78']}; {'id': '78', 'type': 'return_statement', 'children': ['79']}; {'id': '79', 'type': 'call', 'children': ['80', '83']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'Normalize'}; {'id': '83', 'type': 'argument_list', 'children': []}; {'id': '84', 'type': 'if_statement', 'children': ['85', '106', '109']}; {'id': '85', 'type': 'comparison_operator', 'children': ['86', '96'], 'value': '<='}; {'id': '86', 'type': 'call', 'children': ['87', '95']}; {'id': '87', 'type': 'attribute', 'children': ['88', '94']}; {'id': '88', 'type': 'call', 'children': ['89', '92']}; {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'Minus'}; {'id': '92', 'type': 'argument_list', 'children': ['93']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'Norm2'}; {'id': '95', 'type': 'argument_list', 'children': []}; {'id': '96', 'type': 'call', 'children': ['97', '105']}; {'id': '97', 'type': 'attribute', 'children': ['98', '104']}; {'id': '98', 'type': 'call', 'children': ['99', '102']}; {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'Minus'}; {'id': '102', 'type': 'argument_list', 'children': ['103']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'Norm2'}; {'id': '105', 'type': 'argument_list', 'children': []}; {'id': '106', 'type': 'block', 'children': ['107']}; {'id': '107', 'type': 'return_statement', 'children': ['108']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '109', 'type': 'else_clause', 'children': ['110']}; {'id': '110', 'type': 'block', 'children': ['111']}; {'id': '111', 'type': 'return_statement', 'children': ['112']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'b'}
|
Returns the point on the great circle segment ab closest to x.
|
def layer_tagger_mapping(self):
return {
PARAGRAPHS: self.tokenize_paragraphs,
SENTENCES: self.tokenize_sentences,
WORDS: self.tokenize_words,
ANALYSIS: self.tag_analysis,
TIMEXES: self.tag_timexes,
NAMED_ENTITIES: self.tag_named_entities,
CLAUSE_ANNOTATION: self.tag_clause_annotations,
CLAUSES: self.tag_clauses,
LAYER_CONLL: self.tag_syntax_vislcg3,
LAYER_VISLCG3: self.tag_syntax_maltparser,
WORDNET: self.tag_wordnet
}
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'layer_tagger_mapping'}; {'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', '13', '18', '23', '28', '33', '38', '43', '48', '53', '58']}; {'id': '8', 'type': 'pair', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'PARAGRAPHS'}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'tokenize_paragraphs'}; {'id': '13', 'type': 'pair', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'SENTENCES'}; {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'tokenize_sentences'}; {'id': '18', 'type': 'pair', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'WORDS'}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'tokenize_words'}; {'id': '23', 'type': 'pair', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'ANALYSIS'}; {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'tag_analysis'}; {'id': '28', 'type': 'pair', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'TIMEXES'}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'tag_timexes'}; {'id': '33', 'type': 'pair', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'NAMED_ENTITIES'}; {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'tag_named_entities'}; {'id': '38', 'type': 'pair', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'CLAUSE_ANNOTATION'}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'tag_clause_annotations'}; {'id': '43', 'type': 'pair', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'CLAUSES'}; {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'tag_clauses'}; {'id': '48', 'type': 'pair', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'LAYER_CONLL'}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'tag_syntax_vislcg3'}; {'id': '53', 'type': 'pair', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'LAYER_VISLCG3'}; {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'tag_syntax_maltparser'}; {'id': '58', 'type': 'pair', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'WORDNET'}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'tag_wordnet'}
|
Dictionary that maps layer names to taggers that can create that layer.
|
def btc_is_p2wpkh_address( address ):
wver, whash = segwit_addr_decode(address)
if whash is None:
return False
if len(whash) != 20:
return False
return True
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'btc_is_p2wpkh_address'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'address'}; {'id': '5', 'type': 'block', 'children': ['6', '15', '22', '32']}; {'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': 'wver'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'whash'}; {'id': '11', 'type': 'call', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'segwit_addr_decode'}; {'id': '13', 'type': 'argument_list', 'children': ['14']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'address'}; {'id': '15', 'type': 'if_statement', 'children': ['16', '19']}; {'id': '16', 'type': 'comparison_operator', 'children': ['17', '18'], 'value': 'is'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'whash'}; {'id': '18', 'type': 'None', 'children': []}; {'id': '19', 'type': 'block', 'children': ['20']}; {'id': '20', 'type': 'return_statement', 'children': ['21']}; {'id': '21', 'type': 'False', 'children': []}; {'id': '22', 'type': 'if_statement', 'children': ['23', '29']}; {'id': '23', 'type': 'comparison_operator', 'children': ['24', '28'], 'value': '!='}; {'id': '24', 'type': 'call', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'whash'}; {'id': '28', 'type': 'integer', 'children': [], 'value': '20'}; {'id': '29', 'type': 'block', 'children': ['30']}; {'id': '30', 'type': 'return_statement', 'children': ['31']}; {'id': '31', 'type': 'False', 'children': []}; {'id': '32', 'type': 'return_statement', 'children': ['33']}; {'id': '33', 'type': 'True', 'children': []}
|
Is the given address a p2wpkh address?
|
def tag(self, tagname, message=None, force=True):
return git_tag(self.repo_dir, tagname, message=message, force=force)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'tag'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'tagname'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '8', 'type': 'None', 'children': []}; {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'force'}; {'id': '11', 'type': 'True', 'children': []}; {'id': '12', 'type': 'block', 'children': ['13']}; {'id': '13', 'type': 'return_statement', 'children': ['14']}; {'id': '14', 'type': 'call', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'git_tag'}; {'id': '16', 'type': 'argument_list', 'children': ['17', '20', '21', '24']}; {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'repo_dir'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'tagname'}; {'id': '21', 'type': 'keyword_argument', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '24', 'type': 'keyword_argument', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'force'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'force'}
|
Create an annotated tag.
|
def convert_output_to_v4(self, controller_input):
player_input = SimpleControllerState()
player_input.throttle = controller_input[0]
player_input.steer = controller_input[1]
player_input.pitch = controller_input[2]
player_input.yaw = controller_input[3]
player_input.roll = controller_input[4]
player_input.jump = controller_input[5]
player_input.boost = controller_input[6]
player_input.handbrake = controller_input[7]
return player_input
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'convert_output_to_v4'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'controller_input'}; {'id': '6', 'type': 'block', 'children': ['7', '13', '21', '29', '37', '45', '53', '61', '69', '77']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'player_input'}; {'id': '10', 'type': 'call', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'SimpleControllerState'}; {'id': '12', 'type': 'argument_list', 'children': []}; {'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': 'player_input'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'throttle'}; {'id': '18', 'type': 'subscript', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'controller_input'}; {'id': '20', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '26']}; {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'player_input'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'steer'}; {'id': '26', 'type': 'subscript', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'controller_input'}; {'id': '28', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '34']}; {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'player_input'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'pitch'}; {'id': '34', 'type': 'subscript', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'controller_input'}; {'id': '36', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '42']}; {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'player_input'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'yaw'}; {'id': '42', 'type': 'subscript', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'controller_input'}; {'id': '44', 'type': 'integer', 'children': [], 'value': '3'}; {'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': 'player_input'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'roll'}; {'id': '50', 'type': 'subscript', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'controller_input'}; {'id': '52', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '58']}; {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'player_input'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'jump'}; {'id': '58', 'type': 'subscript', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'controller_input'}; {'id': '60', 'type': 'integer', 'children': [], 'value': '5'}; {'id': '61', 'type': 'expression_statement', 'children': ['62']}; {'id': '62', 'type': 'assignment', 'children': ['63', '66']}; {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'player_input'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'boost'}; {'id': '66', 'type': 'subscript', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'controller_input'}; {'id': '68', 'type': 'integer', 'children': [], 'value': '6'}; {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '74']}; {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'player_input'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'handbrake'}; {'id': '74', 'type': 'subscript', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'controller_input'}; {'id': '76', 'type': 'integer', 'children': [], 'value': '7'}; {'id': '77', 'type': 'return_statement', 'children': ['78']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'player_input'}
|
Converts a v3 output to a v4 controller state
|
def send(self, message):
log.debug("sending '{0}' message".format(message.type))
send_miu = self.socket.getsockopt(nfc.llcp.SO_SNDMIU)
try:
data = str(message)
except nfc.llcp.EncodeError as e:
log.error("message encoding failed: {0}".format(e))
else:
return self._send(data, send_miu)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'send'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '6', 'type': 'block', 'children': ['7', '21', '36']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'call', 'children': ['9', '12']}; {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'log'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '12', 'type': 'argument_list', 'children': ['13']}; {'id': '13', 'type': 'call', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}; {'id': '15', 'type': 'string', 'children': [], 'value': '"sending \'{0}\' message"'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '17', 'type': 'argument_list', 'children': ['18']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'send_miu'}; {'id': '24', 'type': 'call', 'children': ['25', '30']}; {'id': '25', 'type': 'attribute', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'socket'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'getsockopt'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}; {'id': '31', 'type': 'attribute', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'nfc'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'llcp'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'SO_SNDMIU'}; {'id': '36', 'type': 'try_statement', 'children': ['37', '45', '67']}; {'id': '37', 'type': 'block', 'children': ['38']}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}; {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '41', 'type': 'call', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '45', 'type': 'except_clause', 'children': ['46', '54']}; {'id': '46', 'type': 'as_pattern', 'children': ['47', '52']}; {'id': '47', 'type': 'attribute', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'nfc'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'llcp'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'EncodeError'}; {'id': '52', 'type': 'as_pattern_target', 'children': ['53']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '54', 'type': 'block', 'children': ['55']}; {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'call', 'children': ['57', '60']}; {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'log'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}; {'id': '61', 'type': 'call', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}; {'id': '63', 'type': 'string', 'children': [], 'value': '"message encoding failed: {0}"'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '67', 'type': 'else_clause', 'children': ['68']}; {'id': '68', 'type': 'block', 'children': ['69']}; {'id': '69', 'type': 'return_statement', 'children': ['70']}; {'id': '70', 'type': 'call', 'children': ['71', '74']}; {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': '_send'}; {'id': '74', 'type': 'argument_list', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'send_miu'}
|
Send a handover request message to the remote server.
|
def _match_minimum_date_time(self, match_key, date_time_value, match=True):
if match:
gtelt = '$gte'
else:
gtelt = '$lt'
if match_key in self._query_terms:
self._query_terms[match_key][gtelt] = date_time_value
else:
self._query_terms[match_key] = {gtelt: date_time_value}
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_match_minimum_date_time'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'match_key'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'date_time_value'}; {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '9', 'type': 'True', 'children': []}; {'id': '10', 'type': 'block', 'children': ['11', '24']}; {'id': '11', 'type': 'if_statement', 'children': ['12', '13', '18']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '13', 'type': 'block', 'children': ['14']}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}; {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'gtelt'}; {'id': '17', 'type': 'string', 'children': [], 'value': "'$gte'"}; {'id': '18', 'type': 'else_clause', 'children': ['19']}; {'id': '19', 'type': 'block', 'children': ['20']}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}; {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'gtelt'}; {'id': '23', 'type': 'string', 'children': [], 'value': "'$lt'"}; {'id': '24', 'type': 'if_statement', 'children': ['25', '30', '41']}; {'id': '25', 'type': 'comparison_operator', 'children': ['26', '27'], 'value': 'in'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'match_key'}; {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': '_query_terms'}; {'id': '30', 'type': 'block', 'children': ['31']}; {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '40']}; {'id': '33', 'type': 'subscript', 'children': ['34', '39']}; {'id': '34', 'type': 'subscript', 'children': ['35', '38']}; {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': '_query_terms'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'match_key'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'gtelt'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'date_time_value'}; {'id': '41', 'type': 'else_clause', 'children': ['42']}; {'id': '42', 'type': 'block', 'children': ['43']}; {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '50']}; {'id': '45', 'type': 'subscript', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': '_query_terms'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'match_key'}; {'id': '50', 'type': 'dictionary', 'children': ['51']}; {'id': '51', 'type': 'pair', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'gtelt'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'date_time_value'}
|
Matches a minimum date time value
|
def simhash(self, content):
if content is None:
self.hash = -1
return
if isinstance(content, str):
features = self.tokenizer_func(content, self.keyword_weight_pari)
self.hash = self.build_from_features(features)
elif isinstance(content, collections.Iterable):
self.hash = self.build_from_features(content)
elif isinstance(content, int):
self.hash = content
else:
raise Exception("Unsupported parameter type %s" % type(content))
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'simhash'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'content'}; {'id': '6', 'type': 'block', 'children': ['7', '20']}; {'id': '7', 'type': 'if_statement', 'children': ['8', '11']}; {'id': '8', 'type': 'comparison_operator', 'children': ['9', '10'], 'value': 'is'}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'content'}; {'id': '10', 'type': 'None', 'children': []}; {'id': '11', 'type': 'block', 'children': ['12', '19']}; {'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': 'hash'}; {'id': '17', 'type': 'unary_operator', 'children': ['18'], 'value': '-'}; {'id': '18', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '19', 'type': 'return_statement', 'children': []}; {'id': '20', 'type': 'if_statement', 'children': ['21', '26', '50', '70', '83']}; {'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': 'content'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '26', 'type': 'block', 'children': ['27', '39']}; {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'features'}; {'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': 'tokenizer_func'}; {'id': '34', 'type': 'argument_list', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'content'}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'keyword_weight_pari'}; {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '44']}; {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'hash'}; {'id': '44', 'type': 'call', 'children': ['45', '48']}; {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'build_from_features'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'features'}; {'id': '50', 'type': 'elif_clause', 'children': ['51', '58']}; {'id': '51', 'type': 'call', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '53', 'type': 'argument_list', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'content'}; {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'collections'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'Iterable'}; {'id': '58', 'type': 'block', 'children': ['59']}; {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'assignment', 'children': ['61', '64']}; {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'hash'}; {'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': 'build_from_features'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'content'}; {'id': '70', 'type': 'elif_clause', 'children': ['71', '76']}; {'id': '71', 'type': 'call', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '73', 'type': 'argument_list', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'content'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '76', 'type': 'block', 'children': ['77']}; {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '82']}; {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'hash'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'content'}; {'id': '83', 'type': 'else_clause', 'children': ['84']}; {'id': '84', 'type': 'block', 'children': ['85']}; {'id': '85', 'type': 'raise_statement', 'children': ['86']}; {'id': '86', 'type': 'call', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '88', 'type': 'argument_list', 'children': ['89']}; {'id': '89', 'type': 'binary_operator', 'children': ['90', '91'], 'value': '%'}; {'id': '90', 'type': 'string', 'children': [], 'value': '"Unsupported parameter type %s"'}; {'id': '91', 'type': 'call', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '93', 'type': 'argument_list', 'children': ['94']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'content'}
|
Select policies for simhash on the different types of content.
|
def _common_prefix(names):
if not names:
return ''
prefix = names[0]
for name in names:
i = 0
while i < len(prefix) and i < len(name) and prefix[i] == name[i]:
i += 1
prefix = prefix[:i]
return prefix
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_common_prefix'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '5', 'type': 'block', 'children': ['6', '12', '18', '61']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '9']}; {'id': '7', 'type': 'not_operator', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '9', 'type': 'block', 'children': ['10']}; {'id': '10', 'type': 'return_statement', 'children': ['11']}; {'id': '11', 'type': 'string', 'children': [], 'value': "''"}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}; {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '15', 'type': 'subscript', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '17', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '18', 'type': 'for_statement', 'children': ['19', '20', '21']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '21', 'type': 'block', 'children': ['22', '26', '53']}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}; {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '25', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '26', 'type': 'while_statement', 'children': ['27', '48']}; {'id': '27', 'type': 'boolean_operator', 'children': ['28', '41'], 'value': 'and'}; {'id': '28', 'type': 'boolean_operator', 'children': ['29', '35'], 'value': 'and'}; {'id': '29', 'type': 'comparison_operator', 'children': ['30', '31'], 'value': '<'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '35', 'type': 'comparison_operator', 'children': ['36', '37'], 'value': '<'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '41', 'type': 'comparison_operator', 'children': ['42', '45'], 'value': '=='}; {'id': '42', 'type': 'subscript', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '45', 'type': 'subscript', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '48', 'type': 'block', 'children': ['49']}; {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'augmented_assignment', 'children': ['51', '52'], 'value': '+='}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '52', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '56', 'type': 'subscript', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '58', 'type': 'slice', 'children': ['59', '60']}; {'id': '59', 'type': 'colon', 'children': []}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '61', 'type': 'return_statement', 'children': ['62']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'prefix'}
|
Get the common prefix for all names
|
def elements(self):
offset = self.EXTRA_DIGITS
if offset:
return (self._id[:offset], self.company_prefix, self._reference,
self.check_digit)
else:
return (self.company_prefix, self._reference, self.check_digit)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'elements'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '12']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'EXTRA_DIGITS'}; {'id': '12', 'type': 'if_statement', 'children': ['13', '14', '33']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '14', 'type': 'block', 'children': ['15']}; {'id': '15', 'type': 'return_statement', 'children': ['16']}; {'id': '16', 'type': 'tuple', 'children': ['17', '24', '27', '30']}; {'id': '17', 'type': 'subscript', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': '_id'}; {'id': '21', 'type': 'slice', 'children': ['22', '23']}; {'id': '22', 'type': 'colon', 'children': []}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'company_prefix'}; {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': '_reference'}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'check_digit'}; {'id': '33', 'type': 'else_clause', 'children': ['34']}; {'id': '34', 'type': 'block', 'children': ['35']}; {'id': '35', 'type': 'return_statement', 'children': ['36']}; {'id': '36', 'type': 'tuple', 'children': ['37', '40', '43']}; {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'company_prefix'}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': '_reference'}; {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'check_digit'}
|
Return the identifier's elements as tuple.
|
def add_contact(self):
self.api.lists.addcontact(
contact=self.cleaned_data['email'], id=self.list_id, method='POST')
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'add_contact'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'call', 'children': ['8', '15']}; {'id': '8', 'type': 'attribute', 'children': ['9', '14']}; {'id': '9', 'type': 'attribute', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'api'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'lists'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'addcontact'}; {'id': '15', 'type': 'argument_list', 'children': ['16', '23', '28']}; {'id': '16', 'type': 'keyword_argument', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'contact'}; {'id': '18', 'type': 'subscript', 'children': ['19', '22']}; {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'cleaned_data'}; {'id': '22', 'type': 'string', 'children': [], 'value': "'email'"}; {'id': '23', 'type': 'keyword_argument', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'list_id'}; {'id': '28', 'type': 'keyword_argument', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '30', 'type': 'string', 'children': [], 'value': "'POST'"}
|
Create a contact with using the email on the list.
|
async def _wrap_ws(self, handler, *args, **kwargs):
try:
method = self.request_method()
data = await handler(self, *args, **kwargs)
status = self.responses.get(method, OK)
response = {
'type': 'response',
'key': getattr(self.request, 'key', None),
'status': status,
'payload': data
}
except Exception as ex:
response = {
'type': 'response',
'key': getattr(self.request, 'key', None),
'status': getattr(ex, 'status', 500),
'payload': getattr(ex, 'msg', 'general error')
}
return self.format(method, response)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_wrap_ws'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'handler'}; {'id': '6', 'type': 'list_splat_pattern', 'children': ['7']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '8', 'type': 'dictionary_splat_pattern', 'children': ['9']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '10', 'type': 'block', 'children': ['11', '107']}; {'id': '11', 'type': 'try_statement', 'children': ['12', '68']}; {'id': '12', 'type': 'block', 'children': ['13', '21', '33', '45']}; {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'method'}; {'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': 'request_method'}; {'id': '20', 'type': 'argument_list', 'children': []}; {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '24', 'type': 'await', 'children': ['25']}; {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'handler'}; {'id': '27', 'type': 'argument_list', 'children': ['28', '29', '31']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '29', 'type': 'list_splat', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '31', 'type': 'dictionary_splat', 'children': ['32']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'status'}; {'id': '36', 'type': 'call', 'children': ['37', '42']}; {'id': '37', 'type': 'attribute', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'responses'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '42', 'type': 'argument_list', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'OK'}; {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '48', 'type': 'dictionary', 'children': ['49', '52', '62', '65']}; {'id': '49', 'type': 'pair', 'children': ['50', '51']}; {'id': '50', 'type': 'string', 'children': [], 'value': "'type'"}; {'id': '51', 'type': 'string', 'children': [], 'value': "'response'"}; {'id': '52', 'type': 'pair', 'children': ['53', '54']}; {'id': '53', 'type': 'string', 'children': [], 'value': "'key'"}; {'id': '54', 'type': 'call', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '56', 'type': 'argument_list', 'children': ['57', '60', '61']}; {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '60', 'type': 'string', 'children': [], 'value': "'key'"}; {'id': '61', 'type': 'None', 'children': []}; {'id': '62', 'type': 'pair', 'children': ['63', '64']}; {'id': '63', 'type': 'string', 'children': [], 'value': "'status'"}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'status'}; {'id': '65', 'type': 'pair', 'children': ['66', '67']}; {'id': '66', 'type': 'string', 'children': [], 'value': "'payload'"}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '68', 'type': 'except_clause', 'children': ['69', '73']}; {'id': '69', 'type': 'as_pattern', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '71', 'type': 'as_pattern_target', 'children': ['72']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'ex'}; {'id': '73', 'type': 'block', 'children': ['74']}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}; {'id': '75', 'type': 'assignment', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '77', 'type': 'dictionary', 'children': ['78', '81', '91', '99']}; {'id': '78', 'type': 'pair', 'children': ['79', '80']}; {'id': '79', 'type': 'string', 'children': [], 'value': "'type'"}; {'id': '80', 'type': 'string', 'children': [], 'value': "'response'"}; {'id': '81', 'type': 'pair', 'children': ['82', '83']}; {'id': '82', 'type': 'string', 'children': [], 'value': "'key'"}; {'id': '83', 'type': 'call', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '85', 'type': 'argument_list', 'children': ['86', '89', '90']}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '89', 'type': 'string', 'children': [], 'value': "'key'"}; {'id': '90', 'type': 'None', 'children': []}; {'id': '91', 'type': 'pair', 'children': ['92', '93']}; {'id': '92', 'type': 'string', 'children': [], 'value': "'status'"}; {'id': '93', 'type': 'call', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '95', 'type': 'argument_list', 'children': ['96', '97', '98']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'ex'}; {'id': '97', 'type': 'string', 'children': [], 'value': "'status'"}; {'id': '98', 'type': 'integer', 'children': [], 'value': '500'}; {'id': '99', 'type': 'pair', 'children': ['100', '101']}; {'id': '100', 'type': 'string', 'children': [], 'value': "'payload'"}; {'id': '101', 'type': 'call', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '103', 'type': 'argument_list', 'children': ['104', '105', '106']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'ex'}; {'id': '105', 'type': 'string', 'children': [], 'value': "'msg'"}; {'id': '106', 'type': 'string', 'children': [], 'value': "'general error'"}; {'id': '107', 'type': 'return_statement', 'children': ['108']}; {'id': '108', 'type': 'call', 'children': ['109', '112']}; {'id': '109', 'type': 'attribute', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '112', 'type': 'argument_list', 'children': ['113', '114']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'response'}
|
wraps a handler by receiving a websocket request and returning a websocket response
|
def api_send_mail(request, key=None, hproPk=None):
if not check_api_key(request, key, hproPk):
return HttpResponseForbidden
sender = request.POST.get('sender', settings.MAIL_SENDER)
dests = request.POST.getlist('dests')
subject = request.POST['subject']
message = request.POST['message']
html_message = request.POST.get('html_message')
if html_message and html_message.lower() == 'false':
html_message = False
if 'response_id' in request.POST:
key = hproPk + ':' + request.POST['response_id']
else:
key = None
generic_send_mail(sender, dests, subject, message, key, 'PlugIt API (%s)' % (hproPk or 'StandAlone',), html_message)
return HttpResponse(json.dumps({}), content_type="application/json")
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'api_send_mail'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'hproPk'}; {'id': '10', 'type': 'None', 'children': []}; {'id': '11', 'type': 'block', 'children': ['12', '23', '37', '48', '56', '64', '75', '90', '115', '131']}; {'id': '12', 'type': 'if_statement', 'children': ['13', '20']}; {'id': '13', 'type': 'not_operator', 'children': ['14']}; {'id': '14', 'type': 'call', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'check_api_key'}; {'id': '16', 'type': 'argument_list', 'children': ['17', '18', '19']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'hproPk'}; {'id': '20', 'type': 'block', 'children': ['21']}; {'id': '21', 'type': 'return_statement', 'children': ['22']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'HttpResponseForbidden'}; {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'sender'}; {'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': 'request'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'POST'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '32', 'type': 'argument_list', 'children': ['33', '34']}; {'id': '33', 'type': 'string', 'children': [], 'value': "'sender'"}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'settings'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'MAIL_SENDER'}; {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'dests'}; {'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': 'request'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'POST'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'getlist'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}; {'id': '47', 'type': 'string', 'children': [], 'value': "'dests'"}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}; {'id': '49', 'type': 'assignment', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'subject'}; {'id': '51', 'type': 'subscript', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'POST'}; {'id': '55', 'type': 'string', 'children': [], 'value': "'subject'"}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}; {'id': '57', 'type': 'assignment', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '59', 'type': 'subscript', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'POST'}; {'id': '63', 'type': 'string', 'children': [], 'value': "'message'"}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}; {'id': '65', 'type': 'assignment', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'html_message'}; {'id': '67', 'type': 'call', 'children': ['68', '73']}; {'id': '68', 'type': 'attribute', 'children': ['69', '72']}; {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'POST'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'string', 'children': [], 'value': "'html_message'"}; {'id': '75', 'type': 'if_statement', 'children': ['76', '85']}; {'id': '76', 'type': 'boolean_operator', 'children': ['77', '78'], 'value': 'and'}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'html_message'}; {'id': '78', 'type': 'comparison_operator', 'children': ['79', '84'], 'value': '=='}; {'id': '79', 'type': 'call', 'children': ['80', '83']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'html_message'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'lower'}; {'id': '83', 'type': 'argument_list', 'children': []}; {'id': '84', 'type': 'string', 'children': [], 'value': "'false'"}; {'id': '85', 'type': 'block', 'children': ['86']}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}; {'id': '87', 'type': 'assignment', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'html_message'}; {'id': '89', 'type': 'False', 'children': []}; {'id': '90', 'type': 'if_statement', 'children': ['91', '96', '109']}; {'id': '91', 'type': 'comparison_operator', 'children': ['92', '93'], 'value': 'in'}; {'id': '92', 'type': 'string', 'children': [], 'value': "'response_id'"}; {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'POST'}; {'id': '96', 'type': 'block', 'children': ['97']}; {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'assignment', 'children': ['99', '100']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '100', 'type': 'binary_operator', 'children': ['101', '104'], 'value': '+'}; {'id': '101', 'type': 'binary_operator', 'children': ['102', '103'], 'value': '+'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'hproPk'}; {'id': '103', 'type': 'string', 'children': [], 'value': "':'"}; {'id': '104', 'type': 'subscript', 'children': ['105', '108']}; {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'POST'}; {'id': '108', 'type': 'string', 'children': [], 'value': "'response_id'"}; {'id': '109', 'type': 'else_clause', 'children': ['110']}; {'id': '110', 'type': 'block', 'children': ['111']}; {'id': '111', 'type': 'expression_statement', 'children': ['112']}; {'id': '112', 'type': 'assignment', 'children': ['113', '114']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '114', 'type': 'None', 'children': []}; {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'call', 'children': ['117', '118']}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'generic_send_mail'}; {'id': '118', 'type': 'argument_list', 'children': ['119', '120', '121', '122', '123', '124', '130']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'sender'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'dests'}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'subject'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '124', 'type': 'binary_operator', 'children': ['125', '126'], 'value': '%'}; {'id': '125', 'type': 'string', 'children': [], 'value': "'PlugIt API (%s)'"}; {'id': '126', 'type': 'tuple', 'children': ['127']}; {'id': '127', 'type': 'boolean_operator', 'children': ['128', '129'], 'value': 'or'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'hproPk'}; {'id': '129', 'type': 'string', 'children': [], 'value': "'StandAlone'"}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'html_message'}; {'id': '131', 'type': 'return_statement', 'children': ['132']}; {'id': '132', 'type': 'call', 'children': ['133', '134']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'HttpResponse'}; {'id': '134', 'type': 'argument_list', 'children': ['135', '141']}; {'id': '135', 'type': 'call', 'children': ['136', '139']}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'dumps'}; {'id': '139', 'type': 'argument_list', 'children': ['140']}; {'id': '140', 'type': 'dictionary', 'children': []}; {'id': '141', 'type': 'keyword_argument', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'content_type'}; {'id': '143', 'type': 'string', 'children': [], 'value': '"application/json"'}
|
Send a email. Posts parameters are used
|
def explain_weights_sklearn(estimator, vec=None, top=_TOP,
target_names=None,
targets=None,
feature_names=None, coef_scale=None,
feature_re=None, feature_filter=None):
return explain_weights_sklearn_not_supported(estimator)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '29']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'explain_weights_sklearn'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'estimator'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'vec'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'top'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': '_TOP'}; {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'target_names'}; {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'targets'}; {'id': '16', 'type': 'None', 'children': []}; {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'feature_names'}; {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'coef_scale'}; {'id': '22', 'type': 'None', 'children': []}; {'id': '23', 'type': 'default_parameter', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'feature_re'}; {'id': '25', 'type': 'None', 'children': []}; {'id': '26', 'type': 'default_parameter', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'feature_filter'}; {'id': '28', 'type': 'None', 'children': []}; {'id': '29', 'type': 'block', 'children': ['30']}; {'id': '30', 'type': 'return_statement', 'children': ['31']}; {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'explain_weights_sklearn_not_supported'}; {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'estimator'}
|
Return an explanation of an estimator
|
def _init_server_authentication(self, ssl_verify: OpenSslVerifyEnum, ssl_verify_locations: Optional[str]) -> None:
self._ssl_ctx.set_verify(ssl_verify.value)
if ssl_verify_locations:
with open(ssl_verify_locations):
pass
self._ssl_ctx.load_verify_locations(ssl_verify_locations)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17', '19']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_init_server_authentication'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'typed_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'ssl_verify'}; {'id': '7', 'type': 'type', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'OpenSslVerifyEnum'}; {'id': '9', 'type': 'typed_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'ssl_verify_locations'}; {'id': '11', 'type': 'type', 'children': ['12']}; {'id': '12', 'type': 'generic_type', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'Optional'}; {'id': '14', 'type': 'type_parameter', 'children': ['15']}; {'id': '15', 'type': 'type', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '17', 'type': 'type', 'children': ['18']}; {'id': '18', 'type': 'None', 'children': []}; {'id': '19', 'type': 'block', 'children': ['20', '31']}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}; {'id': '21', 'type': 'call', 'children': ['22', '27']}; {'id': '22', 'type': 'attribute', 'children': ['23', '26']}; {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': '_ssl_ctx'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'set_verify'}; {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'ssl_verify'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '31', 'type': 'if_statement', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'ssl_verify_locations'}; {'id': '33', 'type': 'block', 'children': ['34', '43']}; {'id': '34', 'type': 'with_statement', 'children': ['35', '41']}; {'id': '35', 'type': 'with_clause', 'children': ['36']}; {'id': '36', 'type': 'with_item', 'children': ['37']}; {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'ssl_verify_locations'}; {'id': '41', 'type': 'block', 'children': ['42']}; {'id': '42', 'type': 'pass_statement', 'children': []}; {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'call', 'children': ['45', '50']}; {'id': '45', 'type': 'attribute', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': '_ssl_ctx'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'load_verify_locations'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'ssl_verify_locations'}
|
Setup the certificate validation logic for authenticating the server.
|
def match_to_dict(self, match, gids):
values = {}
for gid in gids:
try:
values[gid] = self.map_value(match.group(gid), gid)
except IndexError:
pass
return values
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'match_to_dict'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'gids'}; {'id': '7', 'type': 'block', 'children': ['8', '12', '39']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '11', 'type': 'dictionary', 'children': []}; {'id': '12', 'type': 'for_statement', 'children': ['13', '14', '15']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'gid'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'gids'}; {'id': '15', 'type': 'block', 'children': ['16']}; {'id': '16', 'type': 'try_statement', 'children': ['17', '35']}; {'id': '17', 'type': 'block', 'children': ['18']}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}; {'id': '19', 'type': 'assignment', 'children': ['20', '23']}; {'id': '20', 'type': 'subscript', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'gid'}; {'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': 'map_value'}; {'id': '27', 'type': 'argument_list', 'children': ['28', '34']}; {'id': '28', 'type': 'call', 'children': ['29', '32']}; {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'gid'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'gid'}; {'id': '35', 'type': 'except_clause', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'IndexError'}; {'id': '37', 'type': 'block', 'children': ['38']}; {'id': '38', 'type': 'pass_statement', 'children': []}; {'id': '39', 'type': 'return_statement', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'values'}
|
Map values from match into a dictionary.
|
def handle_modifier_down(self, modifier):
_logger.debug("%s pressed", modifier)
if modifier in (Key.CAPSLOCK, Key.NUMLOCK):
if self.modifiers[modifier]:
self.modifiers[modifier] = False
else:
self.modifiers[modifier] = True
else:
self.modifiers[modifier] = True
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'handle_modifier_down'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'modifier'}; {'id': '6', 'type': 'block', 'children': ['7', '15']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'call', 'children': ['9', '12']}; {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': '_logger'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '12', 'type': 'argument_list', 'children': ['13', '14']}; {'id': '13', 'type': 'string', 'children': [], 'value': '"%s pressed"'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'modifier'}; {'id': '15', 'type': 'if_statement', 'children': ['16', '25', '51']}; {'id': '16', 'type': 'comparison_operator', 'children': ['17', '18'], 'value': 'in'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'modifier'}; {'id': '18', 'type': 'tuple', 'children': ['19', '22']}; {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'Key'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'CAPSLOCK'}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'Key'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'NUMLOCK'}; {'id': '25', 'type': 'block', 'children': ['26']}; {'id': '26', 'type': 'if_statement', 'children': ['27', '32', '41']}; {'id': '27', 'type': 'subscript', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'modifiers'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'modifier'}; {'id': '32', 'type': 'block', 'children': ['33']}; {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '40']}; {'id': '35', 'type': 'subscript', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'modifiers'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'modifier'}; {'id': '40', 'type': 'False', 'children': []}; {'id': '41', 'type': 'else_clause', 'children': ['42']}; {'id': '42', 'type': 'block', 'children': ['43']}; {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '50']}; {'id': '45', 'type': 'subscript', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'modifiers'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'modifier'}; {'id': '50', 'type': 'True', 'children': []}; {'id': '51', 'type': 'else_clause', 'children': ['52']}; {'id': '52', 'type': 'block', 'children': ['53']}; {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '60']}; {'id': '55', 'type': 'subscript', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'modifiers'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'modifier'}; {'id': '60', 'type': 'True', 'children': []}
|
Updates the state of the given modifier key to 'pressed'
|
def update(self, other):
Cluster.update(self, other)
self.rules.extend(other.rules)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'update'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'other'}; {'id': '6', 'type': 'block', 'children': ['7', '15']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'call', 'children': ['9', '12']}; {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'Cluster'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '12', 'type': 'argument_list', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'other'}; {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'call', 'children': ['17', '22']}; {'id': '17', 'type': 'attribute', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'rules'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'extend'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}; {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'other'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'rules'}
|
Extend the current cluster with data from another cluster
|
def text_extract(path, password=None):
pdf = Info(path, password).pdf
return [pdf.getPage(i).extractText() for i in range(pdf.getNumPages())]
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'text_extract'}; {'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': 'password'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '19']}; {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'pdf'}; {'id': '12', 'type': 'attribute', 'children': ['13', '18']}; {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'Info'}; {'id': '15', 'type': 'argument_list', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'password'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'pdf'}; {'id': '19', 'type': 'return_statement', 'children': ['20']}; {'id': '20', 'type': 'list_comprehension', 'children': ['21', '31']}; {'id': '21', 'type': 'call', 'children': ['22', '30']}; {'id': '22', 'type': 'attribute', 'children': ['23', '29']}; {'id': '23', 'type': 'call', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'pdf'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'getPage'}; {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'extractText'}; {'id': '30', 'type': 'argument_list', 'children': []}; {'id': '31', 'type': 'for_in_clause', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '33', 'type': 'call', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'call', 'children': ['37', '40']}; {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'pdf'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'getNumPages'}; {'id': '40', 'type': 'argument_list', 'children': []}
|
Extract text from a PDF file
|
def paintEvent(self, event):
if self.isVisible() and self.position != self.Position.FLOATING:
self._background_brush = QBrush(QColor(
self.editor.sideareas_color))
self._foreground_pen = QPen(QColor(
self.palette().windowText().color()))
painter = QPainter(self)
painter.fillRect(event.rect(), self._background_brush)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'paintEvent'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '6', 'type': 'block', 'children': ['7']}; {'id': '7', 'type': 'if_statement', 'children': ['8', '23']}; {'id': '8', 'type': 'boolean_operator', 'children': ['9', '14'], 'value': 'and'}; {'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': 'isVisible'}; {'id': '13', 'type': 'argument_list', 'children': []}; {'id': '14', 'type': 'comparison_operator', 'children': ['15', '18'], 'value': '!='}; {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'position'}; {'id': '18', 'type': 'attribute', 'children': ['19', '22']}; {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'Position'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'FLOATING'}; {'id': '23', 'type': 'block', 'children': ['24', '40', '64', '71']}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}; {'id': '25', 'type': 'assignment', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': '_background_brush'}; {'id': '29', 'type': 'call', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'QBrush'}; {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'call', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'QColor'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}; {'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': 'editor'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'sideareas_color'}; {'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': '_foreground_pen'}; {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'QPen'}; {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'call', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'QColor'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}; {'id': '51', 'type': 'call', 'children': ['52', '63']}; {'id': '52', 'type': 'attribute', 'children': ['53', '62']}; {'id': '53', 'type': 'call', 'children': ['54', '61']}; {'id': '54', 'type': 'attribute', 'children': ['55', '60']}; {'id': '55', 'type': 'call', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'palette'}; {'id': '59', 'type': 'argument_list', 'children': []}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'windowText'}; {'id': '61', 'type': 'argument_list', 'children': []}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'color'}; {'id': '63', 'type': 'argument_list', 'children': []}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}; {'id': '65', 'type': 'assignment', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'painter'}; {'id': '67', 'type': 'call', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'QPainter'}; {'id': '69', 'type': 'argument_list', 'children': ['70']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'call', 'children': ['73', '76']}; {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'painter'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'fillRect'}; {'id': '76', 'type': 'argument_list', 'children': ['77', '82']}; {'id': '77', 'type': 'call', 'children': ['78', '81']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'rect'}; {'id': '81', 'type': 'argument_list', 'children': []}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': '_background_brush'}
|
Fills the panel background using QPalette.
|
def _twig_to_uniqueid(bundle, twig, **kwargs):
res = bundle.filter(twig=twig, force_ps=True, check_visible=False, check_default=False, **kwargs)
if len(res) == 1:
return res.to_list()[0].uniqueid
else:
raise ValueError("did not return a single unique match to a parameter for '{}'".format(twig))
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_twig_to_uniqueid'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'bundle'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'twig'}; {'id': '6', 'type': 'dictionary_splat_pattern', 'children': ['7']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '8', 'type': 'block', 'children': ['9', '31']}; {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '12', 'type': 'call', 'children': ['13', '16']}; {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'bundle'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'filter'}; {'id': '16', 'type': 'argument_list', 'children': ['17', '20', '23', '26', '29']}; {'id': '17', 'type': 'keyword_argument', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'twig'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'twig'}; {'id': '20', 'type': 'keyword_argument', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'force_ps'}; {'id': '22', 'type': 'True', 'children': []}; {'id': '23', 'type': 'keyword_argument', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'check_visible'}; {'id': '25', 'type': 'False', 'children': []}; {'id': '26', 'type': 'keyword_argument', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'check_default'}; {'id': '28', 'type': 'False', 'children': []}; {'id': '29', 'type': 'dictionary_splat', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '31', 'type': 'if_statement', 'children': ['32', '38', '49']}; {'id': '32', 'type': 'comparison_operator', 'children': ['33', '37'], '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': 'identifier', 'children': [], 'value': 'res'}; {'id': '37', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '38', 'type': 'block', 'children': ['39']}; {'id': '39', 'type': 'return_statement', 'children': ['40']}; {'id': '40', 'type': 'attribute', 'children': ['41', '48']}; {'id': '41', 'type': 'subscript', 'children': ['42', '47']}; {'id': '42', 'type': 'call', 'children': ['43', '46']}; {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'to_list'}; {'id': '46', 'type': 'argument_list', 'children': []}; {'id': '47', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'uniqueid'}; {'id': '49', 'type': 'else_clause', 'children': ['50']}; {'id': '50', 'type': 'block', 'children': ['51']}; {'id': '51', 'type': 'raise_statement', 'children': ['52']}; {'id': '52', 'type': 'call', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'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': '"did not return a single unique match to a parameter for \'{}\'"'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '59', 'type': 'argument_list', 'children': ['60']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'twig'}
|
kwargs are passed on to filter
|
def run(url, cmd, log_path, log_level, log_session, force_discovery, print_info):
log_level = log_levels[log_level]
conn = condoor.Connection("host", list(url), log_session=log_session, log_level=log_level, log_dir=log_path)
try:
conn.connect(force_discovery=force_discovery)
if print_info:
echo_info(conn)
for command in cmd:
result = conn.send(command)
print("\nCommand: {}".format(command))
print("Result: \n{}".format(result))
except (condoor.ConnectionError, condoor.ConnectionAuthenticationError, condoor.ConnectionTimeoutError,
condoor.InvalidHopInfoError, condoor.CommandSyntaxError, condoor.CommandTimeoutError,
condoor.CommandError, condoor.ConnectionError) as excpt:
click.echo(excpt)
finally:
conn.disconnect()
return
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'run'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '10']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'log_path'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'log_level'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'log_session'}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'force_discovery'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'print_info'}; {'id': '11', 'type': 'block', 'children': ['12', '18', '40', '137']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}; {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'log_level'}; {'id': '15', 'type': 'subscript', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'log_levels'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'log_level'}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}; {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'conn'}; {'id': '21', 'type': 'call', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'condoor'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'Connection'}; {'id': '25', 'type': 'argument_list', 'children': ['26', '27', '31', '34', '37']}; {'id': '26', 'type': 'string', 'children': [], 'value': '"host"'}; {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '31', 'type': 'keyword_argument', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'log_session'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'log_session'}; {'id': '34', 'type': 'keyword_argument', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'log_level'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'log_level'}; {'id': '37', 'type': 'keyword_argument', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'log_dir'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'log_path'}; {'id': '40', 'type': 'try_statement', 'children': ['41', '92', '129']}; {'id': '41', 'type': 'block', 'children': ['42', '51', '59']}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}; {'id': '43', 'type': 'call', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'conn'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'connect'}; {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'keyword_argument', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'force_discovery'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'force_discovery'}; {'id': '51', 'type': 'if_statement', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'print_info'}; {'id': '53', 'type': 'block', 'children': ['54']}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}; {'id': '55', 'type': 'call', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'echo_info'}; {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'conn'}; {'id': '59', 'type': 'for_statement', 'children': ['60', '61', '62']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'command'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '62', 'type': 'block', 'children': ['63', '72', '82']}; {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '66', 'type': 'call', 'children': ['67', '70']}; {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'conn'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'send'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'command'}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}; {'id': '73', 'type': 'call', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'call', 'children': ['77', '80']}; {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'string', 'children': [], 'value': '"\\nCommand: {}"'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'command'}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}; {'id': '83', 'type': 'call', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '85', 'type': 'argument_list', 'children': ['86']}; {'id': '86', 'type': 'call', 'children': ['87', '90']}; {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'string', 'children': [], 'value': '"Result: \\n{}"'}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '90', 'type': 'argument_list', 'children': ['91']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '92', 'type': 'except_clause', 'children': ['93', '121']}; {'id': '93', 'type': 'as_pattern', 'children': ['94', '119']}; {'id': '94', 'type': 'tuple', 'children': ['95', '98', '101', '104', '107', '110', '113', '116']}; {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'condoor'}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'ConnectionError'}; {'id': '98', 'type': 'attribute', 'children': ['99', '100']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'condoor'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'ConnectionAuthenticationError'}; {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'condoor'}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'ConnectionTimeoutError'}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'condoor'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'InvalidHopInfoError'}; {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'condoor'}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'CommandSyntaxError'}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'condoor'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'CommandTimeoutError'}; {'id': '113', 'type': 'attribute', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'condoor'}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'CommandError'}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'condoor'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'ConnectionError'}; {'id': '119', 'type': 'as_pattern_target', 'children': ['120']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'excpt'}; {'id': '121', 'type': 'block', 'children': ['122']}; {'id': '122', 'type': 'expression_statement', 'children': ['123']}; {'id': '123', 'type': 'call', 'children': ['124', '127']}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'click'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'echo'}; {'id': '127', 'type': 'argument_list', 'children': ['128']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'excpt'}; {'id': '129', 'type': 'finally_clause', 'children': ['130']}; {'id': '130', 'type': 'block', 'children': ['131']}; {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'call', 'children': ['133', '136']}; {'id': '133', 'type': 'attribute', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'conn'}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'disconnect'}; {'id': '136', 'type': 'argument_list', 'children': []}; {'id': '137', 'type': 'return_statement', 'children': []}
|
Run the main function.
|
def run_friedman_smooth(x, y, span):
N = len(x)
weight = numpy.ones(N)
results = numpy.zeros(N)
residuals = numpy.zeros(N)
mace.smooth(x, y, weight, span, 1, 1e-7, results, residuals)
return results, residuals
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'run_friedman_smooth'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'span'}; {'id': '7', 'type': 'block', 'children': ['8', '15', '24', '33', '42', '56']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'N'}; {'id': '11', 'type': 'call', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'len'}; {'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': 'weight'}; {'id': '18', 'type': 'call', 'children': ['19', '22']}; {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'numpy'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'ones'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'N'}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}; {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'numpy'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'zeros'}; {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'N'}; {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'residuals'}; {'id': '36', 'type': 'call', 'children': ['37', '40']}; {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'numpy'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'zeros'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'N'}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}; {'id': '43', 'type': 'call', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'mace'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'smooth'}; {'id': '47', 'type': 'argument_list', 'children': ['48', '49', '50', '51', '52', '53', '54', '55']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'weight'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'span'}; {'id': '52', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '53', 'type': 'float', 'children': [], 'value': '1e-7'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'residuals'}; {'id': '56', 'type': 'return_statement', 'children': ['57']}; {'id': '57', 'type': 'expression_list', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'residuals'}
|
Run the FORTRAN smoother.
|
def job_exists(self, prov):
with self.lock:
self.cur.execute('select * from "jobs" where "prov" = ?;', (prov,))
rec = self.cur.fetchone()
return rec is not None
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'job_exists'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'prov'}; {'id': '6', 'type': 'block', 'children': ['7']}; {'id': '7', 'type': 'with_statement', 'children': ['8', '13']}; {'id': '8', 'type': 'with_clause', 'children': ['9']}; {'id': '9', 'type': 'with_item', 'children': ['10']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'lock'}; {'id': '13', 'type': 'block', 'children': ['14', '25', '35']}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}; {'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': 'self'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'cur'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'execute'}; {'id': '21', 'type': 'argument_list', 'children': ['22', '23']}; {'id': '22', 'type': 'string', 'children': [], 'value': '\'select * from "jobs" where "prov" = ?;\''}; {'id': '23', 'type': 'tuple', 'children': ['24']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'prov'}; {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'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': 'cur'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'fetchone'}; {'id': '34', 'type': 'argument_list', 'children': []}; {'id': '35', 'type': 'return_statement', 'children': ['36']}; {'id': '36', 'type': 'comparison_operator', 'children': ['37', '38'], 'value': 'is not'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '38', 'type': 'None', 'children': []}
|
Check if a job exists in the database.
|
def _resizeCurrentColumnToContents(self, new_index, old_index):
if new_index.column() not in self._autosized_cols:
self._resizeVisibleColumnsToContents()
self.dataTable.scrollTo(new_index)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_resizeCurrentColumnToContents'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'new_index'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'old_index'}; {'id': '7', 'type': 'block', 'children': ['8']}; {'id': '8', 'type': 'if_statement', 'children': ['9', '18']}; {'id': '9', 'type': 'comparison_operator', 'children': ['10', '15'], 'value': 'not in'}; {'id': '10', 'type': 'call', 'children': ['11', '14']}; {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'new_index'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'column'}; {'id': '14', 'type': 'argument_list', 'children': []}; {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': '_autosized_cols'}; {'id': '18', 'type': 'block', 'children': ['19', '25']}; {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'call', 'children': ['21', '24']}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': '_resizeVisibleColumnsToContents'}; {'id': '24', 'type': 'argument_list', 'children': []}; {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'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': 'self'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'dataTable'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'scrollTo'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'new_index'}
|
Resize the current column to its contents.
|
def reopen(args):
if not args.isadmin:
return "Nope, not gonna do it."
msg = args.msg.split()
if not msg:
return "Syntax: !poll reopen <pollnum>"
if not msg[0].isdigit():
return "Not a valid positve integer."
pid = int(msg[0])
poll = get_open_poll(args.session, pid)
if poll is None:
return "That poll doesn't exist or has been deleted!"
poll.active = 1
return "Poll %d reopened!" % pid
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'reopen'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '5', 'type': 'block', 'children': ['6', '14', '24', '30', '42', '51', '61', '68', '74']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '11']}; {'id': '7', 'type': 'not_operator', 'children': ['8']}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'isadmin'}; {'id': '11', 'type': 'block', 'children': ['12']}; {'id': '12', 'type': 'return_statement', 'children': ['13']}; {'id': '13', 'type': 'string', 'children': [], 'value': '"Nope, not gonna do it."'}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}; {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'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': 'args'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '23', 'type': 'argument_list', 'children': []}; {'id': '24', 'type': 'if_statement', 'children': ['25', '27']}; {'id': '25', 'type': 'not_operator', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '27', 'type': 'block', 'children': ['28']}; {'id': '28', 'type': 'return_statement', 'children': ['29']}; {'id': '29', 'type': 'string', 'children': [], 'value': '"Syntax: !poll reopen <pollnum>"'}; {'id': '30', 'type': 'if_statement', 'children': ['31', '39']}; {'id': '31', 'type': 'not_operator', 'children': ['32']}; {'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': 'msg'}; {'id': '36', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'isdigit'}; {'id': '38', 'type': 'argument_list', 'children': []}; {'id': '39', 'type': 'block', 'children': ['40']}; {'id': '40', 'type': 'return_statement', 'children': ['41']}; {'id': '41', 'type': 'string', 'children': [], 'value': '"Not a valid positve integer."'}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}; {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'pid'}; {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'subscript', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '50', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'poll'}; {'id': '54', 'type': 'call', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'get_open_poll'}; {'id': '56', 'type': 'argument_list', 'children': ['57', '60']}; {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'session'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'pid'}; {'id': '61', 'type': 'if_statement', 'children': ['62', '65']}; {'id': '62', 'type': 'comparison_operator', 'children': ['63', '64'], 'value': 'is'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'poll'}; {'id': '64', 'type': 'None', 'children': []}; {'id': '65', 'type': 'block', 'children': ['66']}; {'id': '66', 'type': 'return_statement', 'children': ['67']}; {'id': '67', 'type': 'string', 'children': [], 'value': '"That poll doesn\'t exist or has been deleted!"'}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}; {'id': '69', 'type': 'assignment', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'poll'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'active'}; {'id': '73', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '74', 'type': 'return_statement', 'children': ['75']}; {'id': '75', 'type': 'binary_operator', 'children': ['76', '77'], 'value': '%'}; {'id': '76', 'type': 'string', 'children': [], 'value': '"Poll %d reopened!"'}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'pid'}
|
reopens a closed poll.
|
def _file_path(self, src_path, dest, regex):
m = re.search(regex, src_path)
if dest.endswith('/') or dest == '':
dest += '{filename}'
names = m.groupdict()
if not names and m.groups():
names = {'filename': m.groups()[-1]}
for name, value in names.items():
dest = dest.replace('{%s}' % name, value)
dest = dest.strip(' /')
if not dest:
progress_logger.error('destination path must not resolve to be null')
raise GrablibError('bad path')
new_path = self.download_root.joinpath(dest)
new_path.relative_to(self.download_root)
return new_path
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_file_path'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'src_path'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'dest'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'regex'}; {'id': '8', 'type': 'block', 'children': ['9', '19', '35', '43', '67', '89', '98', '114', '125', '134']}; {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '12', 'type': 'call', 'children': ['13', '16']}; {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'search'}; {'id': '16', 'type': 'argument_list', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'regex'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'src_path'}; {'id': '19', 'type': 'if_statement', 'children': ['20', '30']}; {'id': '20', 'type': 'boolean_operator', 'children': ['21', '27'], 'value': 'or'}; {'id': '21', 'type': 'call', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'dest'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'endswith'}; {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'string', 'children': [], 'value': "'/'"}; {'id': '27', 'type': 'comparison_operator', 'children': ['28', '29'], 'value': '=='}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'dest'}; {'id': '29', 'type': 'string', 'children': [], 'value': "''"}; {'id': '30', 'type': 'block', 'children': ['31']}; {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'augmented_assignment', 'children': ['33', '34'], 'value': '+='}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'dest'}; {'id': '34', 'type': 'string', 'children': [], 'value': "'{filename}'"}; {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '38', 'type': 'call', 'children': ['39', '42']}; {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'groupdict'}; {'id': '42', 'type': 'argument_list', 'children': []}; {'id': '43', 'type': 'if_statement', 'children': ['44', '52']}; {'id': '44', 'type': 'boolean_operator', 'children': ['45', '47'], 'value': 'and'}; {'id': '45', 'type': 'not_operator', 'children': ['46']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '47', 'type': 'call', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'groups'}; {'id': '51', 'type': 'argument_list', 'children': []}; {'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': 'names'}; {'id': '56', 'type': 'dictionary', 'children': ['57']}; {'id': '57', 'type': 'pair', 'children': ['58', '59']}; {'id': '58', 'type': 'string', 'children': [], 'value': "'filename'"}; {'id': '59', 'type': 'subscript', 'children': ['60', '65']}; {'id': '60', 'type': 'call', 'children': ['61', '64']}; {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'groups'}; {'id': '64', 'type': 'argument_list', 'children': []}; {'id': '65', 'type': 'unary_operator', 'children': ['66'], 'value': '-'}; {'id': '66', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '67', 'type': 'for_statement', 'children': ['68', '71', '76']}; {'id': '68', 'type': 'pattern_list', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '71', 'type': 'call', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '75', 'type': 'argument_list', 'children': []}; {'id': '76', 'type': 'block', 'children': ['77']}; {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'dest'}; {'id': '80', 'type': 'call', 'children': ['81', '84']}; {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'dest'}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '84', 'type': 'argument_list', 'children': ['85', '88']}; {'id': '85', 'type': 'binary_operator', 'children': ['86', '87'], 'value': '%'}; {'id': '86', 'type': 'string', 'children': [], 'value': "'{%s}'"}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '89', 'type': 'expression_statement', 'children': ['90']}; {'id': '90', 'type': 'assignment', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'dest'}; {'id': '92', 'type': 'call', 'children': ['93', '96']}; {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'dest'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '96', 'type': 'argument_list', 'children': ['97']}; {'id': '97', 'type': 'string', 'children': [], 'value': "' /'"}; {'id': '98', 'type': 'if_statement', 'children': ['99', '101']}; {'id': '99', 'type': 'not_operator', 'children': ['100']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'dest'}; {'id': '101', 'type': 'block', 'children': ['102', '109']}; {'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': 'progress_logger'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '107', 'type': 'argument_list', 'children': ['108']}; {'id': '108', 'type': 'string', 'children': [], 'value': "'destination path must not resolve to be null'"}; {'id': '109', 'type': 'raise_statement', 'children': ['110']}; {'id': '110', 'type': 'call', 'children': ['111', '112']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'GrablibError'}; {'id': '112', 'type': 'argument_list', 'children': ['113']}; {'id': '113', 'type': 'string', 'children': [], 'value': "'bad path'"}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}; {'id': '115', 'type': 'assignment', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'new_path'}; {'id': '117', 'type': 'call', 'children': ['118', '123']}; {'id': '118', 'type': 'attribute', 'children': ['119', '122']}; {'id': '119', 'type': 'attribute', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'download_root'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'joinpath'}; {'id': '123', 'type': 'argument_list', 'children': ['124']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'dest'}; {'id': '125', 'type': 'expression_statement', 'children': ['126']}; {'id': '126', 'type': 'call', 'children': ['127', '130']}; {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'new_path'}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'relative_to'}; {'id': '130', 'type': 'argument_list', 'children': ['131']}; {'id': '131', 'type': 'attribute', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'download_root'}; {'id': '134', 'type': 'return_statement', 'children': ['135']}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'new_path'}
|
check src_path complies with regex and generate new filename
|
def encode(data, mime_type='', charset='utf-8', base64=True):
if isinstance(data, six.text_type):
data = data.encode(charset)
else:
charset = None
if base64:
data = utils.text(b64encode(data))
else:
data = utils.text(quote(data))
result = ['data:', ]
if mime_type:
result.append(mime_type)
if charset:
result.append(';charset=')
result.append(charset)
if base64:
result.append(';base64')
result.append(',')
result.append(data)
return ''.join(result)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'encode'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'mime_type'}; {'id': '7', 'type': 'string', 'children': [], 'value': "''"}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'charset'}; {'id': '10', 'type': 'string', 'children': [], 'value': "'utf-8'"}; {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'base64'}; {'id': '13', 'type': 'True', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15', '39', '68', '73', '83', '100', '110', '117', '124']}; {'id': '15', 'type': 'if_statement', 'children': ['16', '23', '33']}; {'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': 'data'}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'text_type'}; {'id': '23', 'type': 'block', 'children': ['24']}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}; {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'encode'}; {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'charset'}; {'id': '33', 'type': 'else_clause', 'children': ['34']}; {'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': 'charset'}; {'id': '38', 'type': 'None', 'children': []}; {'id': '39', 'type': 'if_statement', 'children': ['40', '41', '54']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'base64'}; {'id': '41', 'type': 'block', 'children': ['42']}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}; {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'call', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'b64encode'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '54', 'type': 'else_clause', 'children': ['55']}; {'id': '55', 'type': 'block', 'children': ['56']}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}; {'id': '57', 'type': 'assignment', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '59', 'type': 'call', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'call', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'quote'}; {'id': '66', 'type': 'argument_list', 'children': ['67']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}; {'id': '69', 'type': 'assignment', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '71', 'type': 'list', 'children': ['72'], 'value': "['data:', ]"}; {'id': '72', 'type': 'string', 'children': [], 'value': "'data:'"}; {'id': '73', 'type': 'if_statement', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'mime_type'}; {'id': '75', 'type': 'block', 'children': ['76']}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}; {'id': '77', 'type': 'call', 'children': ['78', '81']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'mime_type'}; {'id': '83', 'type': 'if_statement', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'charset'}; {'id': '85', 'type': 'block', 'children': ['86', '93']}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}; {'id': '87', 'type': 'call', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'string', 'children': [], 'value': "';charset='"}; {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'call', 'children': ['95', '98']}; {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '98', 'type': 'argument_list', 'children': ['99']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'charset'}; {'id': '100', 'type': 'if_statement', 'children': ['101', '102']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'base64'}; {'id': '102', 'type': 'block', 'children': ['103']}; {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'call', 'children': ['105', '108']}; {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '108', 'type': 'argument_list', 'children': ['109']}; {'id': '109', 'type': 'string', 'children': [], 'value': "';base64'"}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}; {'id': '111', 'type': 'call', 'children': ['112', '115']}; {'id': '112', 'type': 'attribute', 'children': ['113', '114']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '115', 'type': 'argument_list', 'children': ['116']}; {'id': '116', 'type': 'string', 'children': [], 'value': "','"}; {'id': '117', 'type': 'expression_statement', 'children': ['118']}; {'id': '118', 'type': 'call', 'children': ['119', '122']}; {'id': '119', 'type': 'attribute', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '122', 'type': 'argument_list', 'children': ['123']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '124', 'type': 'return_statement', 'children': ['125']}; {'id': '125', 'type': 'call', 'children': ['126', '129']}; {'id': '126', 'type': 'attribute', 'children': ['127', '128']}; {'id': '127', 'type': 'string', 'children': [], 'value': "''"}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '129', 'type': 'argument_list', 'children': ['130']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'result'}
|
Encode data to DataURL
|
def unknown_command(self, args):
mode_mapping = self.master.mode_mapping()
mode = args[0].upper()
if mode in mode_mapping:
self.master.set_mode(mode_mapping[mode])
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': 'unknown_command'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '6', 'type': 'block', 'children': ['7', '17', '27', '45']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'mode_mapping'}; {'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': 'self'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'master'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'mode_mapping'}; {'id': '16', 'type': 'argument_list', 'children': []}; {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '20', 'type': 'call', 'children': ['21', '26']}; {'id': '21', 'type': 'attribute', 'children': ['22', '25']}; {'id': '22', 'type': 'subscript', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '24', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'upper'}; {'id': '26', 'type': 'argument_list', 'children': []}; {'id': '27', 'type': 'if_statement', 'children': ['28', '31']}; {'id': '28', 'type': 'comparison_operator', 'children': ['29', '30'], 'value': 'in'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'mode_mapping'}; {'id': '31', 'type': 'block', 'children': ['32', '43']}; {'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': 'master'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'set_mode'}; {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'subscript', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'mode_mapping'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '43', 'type': 'return_statement', 'children': ['44']}; {'id': '44', 'type': 'True', 'children': []}; {'id': '45', 'type': 'return_statement', 'children': ['46']}; {'id': '46', 'type': 'False', 'children': []}
|
handle mode switch by mode name as command
|
def apseudo(Ss, ipar, sigma):
Is = random.randint(0, len(Ss) - 1, size=len(Ss))
if not ipar:
BSs = Ss[Is]
else:
A, B = design(6)
K, BSs = [], []
for k in range(len(Ss)):
K.append(np.dot(A, Ss[k][0:6]))
Pars = np.random.normal(K, sigma)
for k in range(len(Ss)):
BSs.append(np.dot(B, Pars[k]))
return np.array(BSs)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'apseudo'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'Ss'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'ipar'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'sigma'}; {'id': '7', 'type': 'block', 'children': ['8', '29', '125']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'Is'}; {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'random'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'randint'}; {'id': '15', 'type': 'argument_list', 'children': ['16', '17', '23']}; {'id': '16', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '17', 'type': 'binary_operator', 'children': ['18', '22'], 'value': '-'}; {'id': '18', 'type': 'call', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'Ss'}; {'id': '22', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '23', 'type': 'keyword_argument', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'size'}; {'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': 'Ss'}; {'id': '29', 'type': 'if_statement', 'children': ['30', '32', '39']}; {'id': '30', 'type': 'not_operator', 'children': ['31']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'ipar'}; {'id': '32', 'type': 'block', 'children': ['33']}; {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'BSs'}; {'id': '36', 'type': 'subscript', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'Ss'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'Is'}; {'id': '39', 'type': 'else_clause', 'children': ['40']}; {'id': '40', 'type': 'block', 'children': ['41', '50', '58', '88', '100']}; {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '46']}; {'id': '43', 'type': 'pattern_list', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'A'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'B'}; {'id': '46', 'type': 'call', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'design'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}; {'id': '49', 'type': 'integer', 'children': [], 'value': '6'}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}; {'id': '51', 'type': 'assignment', 'children': ['52', '55']}; {'id': '52', 'type': 'pattern_list', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'K'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'BSs'}; {'id': '55', 'type': 'expression_list', 'children': ['56', '57']}; {'id': '56', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '57', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '58', 'type': 'for_statement', 'children': ['59', '60', '67']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '60', 'type': 'call', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}; {'id': '63', 'type': 'call', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'Ss'}; {'id': '67', 'type': 'block', 'children': ['68']}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}; {'id': '69', 'type': 'call', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'K'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'call', 'children': ['75', '78']}; {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'dot'}; {'id': '78', 'type': 'argument_list', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'A'}; {'id': '80', 'type': 'subscript', 'children': ['81', '84']}; {'id': '81', 'type': 'subscript', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'Ss'}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '84', 'type': 'slice', 'children': ['85', '86', '87']}; {'id': '85', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '86', 'type': 'colon', 'children': []}; {'id': '87', 'type': 'integer', 'children': [], 'value': '6'}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}; {'id': '89', 'type': 'assignment', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'Pars'}; {'id': '91', 'type': 'call', 'children': ['92', '97']}; {'id': '92', 'type': 'attribute', 'children': ['93', '96']}; {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'random'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'normal'}; {'id': '97', 'type': 'argument_list', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'K'}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'sigma'}; {'id': '100', 'type': 'for_statement', 'children': ['101', '102', '109']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '102', 'type': 'call', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '104', 'type': 'argument_list', 'children': ['105']}; {'id': '105', 'type': 'call', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '107', 'type': 'argument_list', 'children': ['108']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'Ss'}; {'id': '109', 'type': 'block', 'children': ['110']}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}; {'id': '111', 'type': 'call', 'children': ['112', '115']}; {'id': '112', 'type': 'attribute', 'children': ['113', '114']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'BSs'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '115', 'type': 'argument_list', 'children': ['116']}; {'id': '116', 'type': 'call', 'children': ['117', '120']}; {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'dot'}; {'id': '120', 'type': 'argument_list', 'children': ['121', '122']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'B'}; {'id': '122', 'type': 'subscript', 'children': ['123', '124']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'Pars'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '125', 'type': 'return_statement', 'children': ['126']}; {'id': '126', 'type': 'call', 'children': ['127', '130']}; {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '130', 'type': 'argument_list', 'children': ['131']}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'BSs'}
|
draw a bootstrap sample of Ss
|
def calculate_metrics(self, model, train_loader, valid_loader, metrics_dict):
self.log_count += 1
log_valid = (
valid_loader is not None
and self.valid_every_X
and not (self.log_count % self.valid_every_X)
)
metrics_dict = {}
if self.config["log_train_metrics_func"] is not None:
func = self.config["log_train_metrics_func"]
func_list = func if isinstance(func, list) else [func]
for func in func_list:
metrics_dict = self._calculate_custom_metrics(
model, train_loader, func, metrics_dict, split="train"
)
if self.config["log_valid_metrics_func"] is not None and log_valid:
func = self.config["log_valid_metrics_func"]
func_list = func if isinstance(func, list) else [func]
for func in func_list:
metrics_dict = self._calculate_custom_metrics(
model, valid_loader, func, metrics_dict, split="valid"
)
metrics_dict = self._calculate_standard_metrics(
model, train_loader, self.log_train_metrics, metrics_dict, "train"
)
if log_valid:
metrics_dict = self._calculate_standard_metrics(
model, valid_loader, self.log_valid_metrics, metrics_dict, "valid"
)
return metrics_dict
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'calculate_metrics'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'train_loader'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'valid_loader'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'metrics_dict'}; {'id': '9', 'type': 'block', 'children': ['10', '16', '37', '41', '89', '139', '154', '172']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}; {'id': '11', 'type': 'augmented_assignment', 'children': ['12', '15'], 'value': '+='}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'log_count'}; {'id': '15', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}; {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'log_valid'}; {'id': '19', 'type': '()', 'children': ['20']}; {'id': '20', 'type': 'boolean_operator', 'children': ['21', '28'], 'value': 'and'}; {'id': '21', 'type': 'boolean_operator', 'children': ['22', '25'], 'value': 'and'}; {'id': '22', 'type': 'comparison_operator', 'children': ['23', '24'], 'value': 'is not'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'valid_loader'}; {'id': '24', 'type': 'None', 'children': []}; {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'valid_every_X'}; {'id': '28', 'type': 'not_operator', 'children': ['29']}; {'id': '29', 'type': '()', 'children': ['30']}; {'id': '30', 'type': 'binary_operator', 'children': ['31', '34'], 'value': '%'}; {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'log_count'}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'valid_every_X'}; {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'metrics_dict'}; {'id': '40', 'type': 'dictionary', 'children': []}; {'id': '41', 'type': 'if_statement', 'children': ['42', '49']}; {'id': '42', 'type': 'comparison_operator', 'children': ['43', '48'], 'value': 'is not'}; {'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': 'config'}; {'id': '47', 'type': 'string', 'children': [], 'value': '"log_train_metrics_func"'}; {'id': '48', 'type': 'None', 'children': []}; {'id': '49', 'type': 'block', 'children': ['50', '58', '70']}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}; {'id': '51', 'type': 'assignment', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'func'}; {'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': 'config'}; {'id': '57', 'type': 'string', 'children': [], 'value': '"log_train_metrics_func"'}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}; {'id': '59', 'type': 'assignment', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'func_list'}; {'id': '61', 'type': 'conditional_expression', 'children': ['62', '63', '68'], 'value': 'if'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '63', 'type': 'call', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '65', 'type': 'argument_list', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '68', 'type': 'list', 'children': ['69'], 'value': '[func]'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '70', 'type': 'for_statement', 'children': ['71', '72', '73']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'func_list'}; {'id': '73', 'type': 'block', 'children': ['74']}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}; {'id': '75', 'type': 'assignment', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'metrics_dict'}; {'id': '77', 'type': 'call', 'children': ['78', '81']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': '_calculate_custom_metrics'}; {'id': '81', 'type': 'argument_list', 'children': ['82', '83', '84', '85', '86']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'train_loader'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'metrics_dict'}; {'id': '86', 'type': 'keyword_argument', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '88', 'type': 'string', 'children': [], 'value': '"train"'}; {'id': '89', 'type': 'if_statement', 'children': ['90', '99']}; {'id': '90', 'type': 'boolean_operator', 'children': ['91', '98'], 'value': 'and'}; {'id': '91', 'type': 'comparison_operator', 'children': ['92', '97'], 'value': 'is not'}; {'id': '92', 'type': 'subscript', 'children': ['93', '96']}; {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '96', 'type': 'string', 'children': [], 'value': '"log_valid_metrics_func"'}; {'id': '97', 'type': 'None', 'children': []}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'log_valid'}; {'id': '99', 'type': 'block', 'children': ['100', '108', '120']}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}; {'id': '101', 'type': 'assignment', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '103', 'type': 'subscript', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '107', 'type': 'string', 'children': [], 'value': '"log_valid_metrics_func"'}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}; {'id': '109', 'type': 'assignment', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'func_list'}; {'id': '111', 'type': 'conditional_expression', 'children': ['112', '113', '118'], 'value': 'if'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '113', 'type': 'call', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '115', 'type': 'argument_list', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '118', 'type': 'list', 'children': ['119'], 'value': '[func]'}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '120', 'type': 'for_statement', 'children': ['121', '122', '123']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'func_list'}; {'id': '123', 'type': 'block', 'children': ['124']}; {'id': '124', 'type': 'expression_statement', 'children': ['125']}; {'id': '125', 'type': 'assignment', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'metrics_dict'}; {'id': '127', 'type': 'call', 'children': ['128', '131']}; {'id': '128', 'type': 'attribute', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': '_calculate_custom_metrics'}; {'id': '131', 'type': 'argument_list', 'children': ['132', '133', '134', '135', '136']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'valid_loader'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'metrics_dict'}; {'id': '136', 'type': 'keyword_argument', 'children': ['137', '138']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '138', 'type': 'string', 'children': [], 'value': '"valid"'}; {'id': '139', 'type': 'expression_statement', 'children': ['140']}; {'id': '140', 'type': 'assignment', 'children': ['141', '142']}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'metrics_dict'}; {'id': '142', 'type': 'call', 'children': ['143', '146']}; {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '145', 'type': 'identifier', 'children': [], 'value': '_calculate_standard_metrics'}; {'id': '146', 'type': 'argument_list', 'children': ['147', '148', '149', '152', '153']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'train_loader'}; {'id': '149', 'type': 'attribute', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'log_train_metrics'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'metrics_dict'}; {'id': '153', 'type': 'string', 'children': [], 'value': '"train"'}; {'id': '154', 'type': 'if_statement', 'children': ['155', '156']}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'log_valid'}; {'id': '156', 'type': 'block', 'children': ['157']}; {'id': '157', 'type': 'expression_statement', 'children': ['158']}; {'id': '158', 'type': 'assignment', 'children': ['159', '160']}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'metrics_dict'}; {'id': '160', 'type': 'call', 'children': ['161', '164']}; {'id': '161', 'type': 'attribute', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '163', 'type': 'identifier', 'children': [], 'value': '_calculate_standard_metrics'}; {'id': '164', 'type': 'argument_list', 'children': ['165', '166', '167', '170', '171']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'valid_loader'}; {'id': '167', 'type': 'attribute', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'log_valid_metrics'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'metrics_dict'}; {'id': '171', 'type': 'string', 'children': [], 'value': '"valid"'}; {'id': '172', 'type': 'return_statement', 'children': ['173']}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'metrics_dict'}
|
Add standard and custom metrics to metrics_dict
|
def create_command(self, name, operation, **kwargs):
if not isinstance(operation, six.string_types):
raise ValueError("Operation must be a string. Got '{}'".format(operation))
name = ' '.join(name.split())
client_factory = kwargs.get('client_factory', None)
def _command_handler(command_args):
op = CLICommandsLoader._get_op_handler(operation)
client = client_factory(command_args) if client_factory else None
result = op(client, **command_args) if client else op(**command_args)
return result
def arguments_loader():
return list(extract_args_from_signature(CLICommandsLoader._get_op_handler(operation),
excluded_params=self.excluded_command_handler_args))
def description_loader():
return extract_full_summary_from_signature(CLICommandsLoader._get_op_handler(operation))
kwargs['arguments_loader'] = arguments_loader
kwargs['description_loader'] = description_loader
cmd = self.command_cls(self.cli_ctx, name, _command_handler, **kwargs)
return cmd
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'create_command'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'operation'}; {'id': '7', 'type': 'dictionary_splat_pattern', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '9', 'type': 'block', 'children': ['10', '30', '43', '53', '95', '117', '131', '137', '143', '158']}; {'id': '10', 'type': 'if_statement', 'children': ['11', '19']}; {'id': '11', 'type': 'not_operator', 'children': ['12']}; {'id': '12', 'type': 'call', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '14', 'type': 'argument_list', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'operation'}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'string_types'}; {'id': '19', 'type': 'block', 'children': ['20']}; {'id': '20', 'type': 'raise_statement', 'children': ['21']}; {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'call', 'children': ['25', '28']}; {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'string', 'children': [], 'value': '"Operation must be a string. Got \'{}\'"'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'operation'}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}; {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '33', 'type': 'call', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}; {'id': '35', 'type': 'string', 'children': [], 'value': "' '"}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'join'}; {'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': 'name'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '42', 'type': 'argument_list', 'children': []}; {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'client_factory'}; {'id': '46', 'type': 'call', 'children': ['47', '50']}; {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '50', 'type': 'argument_list', 'children': ['51', '52']}; {'id': '51', 'type': 'string', 'children': [], 'value': "'client_factory'"}; {'id': '52', 'type': 'None', 'children': []}; {'id': '53', 'type': 'function_definition', 'children': ['54', '55', '57']}; {'id': '54', 'type': 'function_name', 'children': [], 'value': '_command_handler'}; {'id': '55', 'type': 'parameters', 'children': ['56']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'command_args'}; {'id': '57', 'type': 'block', 'children': ['58', '67', '77', '93']}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}; {'id': '59', 'type': 'assignment', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'op'}; {'id': '61', 'type': 'call', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'CLICommandsLoader'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': '_get_op_handler'}; {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'operation'}; {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'assignment', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'client'}; {'id': '70', 'type': 'conditional_expression', 'children': ['71', '75', '76'], 'value': 'if'}; {'id': '71', 'type': 'call', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'client_factory'}; {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'command_args'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'client_factory'}; {'id': '76', 'type': 'None', 'children': []}; {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '80', 'type': 'conditional_expression', 'children': ['81', '87', '88'], 'value': 'if'}; {'id': '81', 'type': 'call', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'op'}; {'id': '83', 'type': 'argument_list', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'client'}; {'id': '85', 'type': 'dictionary_splat', 'children': ['86']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'command_args'}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'client'}; {'id': '88', 'type': 'call', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'op'}; {'id': '90', 'type': 'argument_list', 'children': ['91']}; {'id': '91', 'type': 'dictionary_splat', 'children': ['92']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'command_args'}; {'id': '93', 'type': 'return_statement', 'children': ['94']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '95', 'type': 'function_definition', 'children': ['96', '97', '98']}; {'id': '96', 'type': 'function_name', 'children': [], 'value': 'arguments_loader'}; {'id': '97', 'type': 'parameters', 'children': []}; {'id': '98', 'type': 'block', 'children': ['99']}; {'id': '99', 'type': 'return_statement', 'children': ['100']}; {'id': '100', 'type': 'call', 'children': ['101', '102']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '102', 'type': 'argument_list', 'children': ['103']}; {'id': '103', 'type': 'call', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'extract_args_from_signature'}; {'id': '105', 'type': 'argument_list', 'children': ['106', '112']}; {'id': '106', 'type': 'call', 'children': ['107', '110']}; {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'CLICommandsLoader'}; {'id': '109', 'type': 'identifier', 'children': [], 'value': '_get_op_handler'}; {'id': '110', 'type': 'argument_list', 'children': ['111']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'operation'}; {'id': '112', 'type': 'keyword_argument', 'children': ['113', '114']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'excluded_params'}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'excluded_command_handler_args'}; {'id': '117', 'type': 'function_definition', 'children': ['118', '119', '120']}; {'id': '118', 'type': 'function_name', 'children': [], 'value': 'description_loader'}; {'id': '119', 'type': 'parameters', 'children': []}; {'id': '120', 'type': 'block', 'children': ['121']}; {'id': '121', 'type': 'return_statement', 'children': ['122']}; {'id': '122', 'type': 'call', 'children': ['123', '124']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'extract_full_summary_from_signature'}; {'id': '124', 'type': 'argument_list', 'children': ['125']}; {'id': '125', 'type': 'call', 'children': ['126', '129']}; {'id': '126', 'type': 'attribute', 'children': ['127', '128']}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'CLICommandsLoader'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': '_get_op_handler'}; {'id': '129', 'type': 'argument_list', 'children': ['130']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'operation'}; {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'assignment', 'children': ['133', '136']}; {'id': '133', 'type': 'subscript', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '135', 'type': 'string', 'children': [], 'value': "'arguments_loader'"}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'arguments_loader'}; {'id': '137', 'type': 'expression_statement', 'children': ['138']}; {'id': '138', 'type': 'assignment', 'children': ['139', '142']}; {'id': '139', 'type': 'subscript', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '141', 'type': 'string', 'children': [], 'value': "'description_loader'"}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'description_loader'}; {'id': '143', 'type': 'expression_statement', 'children': ['144']}; {'id': '144', 'type': 'assignment', 'children': ['145', '146']}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '146', 'type': 'call', 'children': ['147', '150']}; {'id': '147', 'type': 'attribute', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'command_cls'}; {'id': '150', 'type': 'argument_list', 'children': ['151', '154', '155', '156']}; {'id': '151', 'type': 'attribute', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'cli_ctx'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '155', 'type': 'identifier', 'children': [], 'value': '_command_handler'}; {'id': '156', 'type': 'dictionary_splat', 'children': ['157']}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '158', 'type': 'return_statement', 'children': ['159']}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'cmd'}
|
Constructs the command object that can then be added to the command table
|
def service(self, name: str = None):
if self._services_initialized:
from warnings import warn
warn('Services have already been initialized. Please register '
f'{name} sooner.')
return lambda x: x
def wrapper(service):
self.register_service(name, service)
return service
return wrapper
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'service'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'typed_default_parameter', 'children': ['6', '7', '9']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '7', 'type': 'type', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '9', 'type': 'None', 'children': []}; {'id': '10', 'type': 'block', 'children': ['11', '33', '48']}; {'id': '11', 'type': 'if_statement', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': '_services_initialized'}; {'id': '15', 'type': 'block', 'children': ['16', '21', '28']}; {'id': '16', 'type': 'import_from_statement', 'children': ['17', '19']}; {'id': '17', 'type': 'dotted_name', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'warnings'}; {'id': '19', 'type': 'dotted_name', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'warn'}; {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'call', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'warn'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}; {'id': '25', 'type': 'concatenated_string', 'children': ['26', '27']}; {'id': '26', 'type': 'string', 'children': [], 'value': "'Services have already been initialized. Please register '"}; {'id': '27', 'type': 'string', 'children': [], 'value': "f'{name} sooner.'"}; {'id': '28', 'type': 'return_statement', 'children': ['29']}; {'id': '29', 'type': 'lambda', 'children': ['30', '32']}; {'id': '30', 'type': 'lambda_parameters', 'children': ['31']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '33', 'type': 'function_definition', 'children': ['34', '35', '37']}; {'id': '34', 'type': 'function_name', 'children': [], 'value': 'wrapper'}; {'id': '35', 'type': 'parameters', 'children': ['36']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'service'}; {'id': '37', 'type': 'block', 'children': ['38', '46']}; {'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': 'self'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'register_service'}; {'id': '43', 'type': 'argument_list', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'service'}; {'id': '46', 'type': 'return_statement', 'children': ['47']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'service'}; {'id': '48', 'type': 'return_statement', 'children': ['49']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'wrapper'}
|
Decorator to mark something as a service.
|
def new_revision(self, *fields):
if not self._id:
assert g.get('draft'), \
'Only draft documents can be assigned new revisions'
else:
with self.draft_context():
assert self.count(Q._id == self._id) == 1, \
'Only draft documents can be assigned new revisions'
if len(fields) > 0:
fields.append('revision')
self.revision = datetime.now()
self.upsert(*fields)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'new_revision'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'list_splat_pattern', 'children': ['6']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'fields'}; {'id': '7', 'type': 'block', 'children': ['8', '49', '64', '74']}; {'id': '8', 'type': 'if_statement', 'children': ['9', '13', '22']}; {'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': '_id'}; {'id': '13', 'type': 'block', 'children': ['14']}; {'id': '14', 'type': 'assert_statement', 'children': ['15', '21']}; {'id': '15', 'type': 'call', 'children': ['16', '19']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'string', 'children': [], 'value': "'draft'"}; {'id': '21', 'type': 'string', 'children': [], 'value': "'Only draft documents can be assigned new revisions'"}; {'id': '22', 'type': 'else_clause', 'children': ['23']}; {'id': '23', 'type': 'block', 'children': ['24']}; {'id': '24', 'type': 'with_statement', 'children': ['25', '32']}; {'id': '25', 'type': 'with_clause', 'children': ['26']}; {'id': '26', 'type': 'with_item', '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': 'draft_context'}; {'id': '31', 'type': 'argument_list', 'children': []}; {'id': '32', 'type': 'block', 'children': ['33']}; {'id': '33', 'type': 'assert_statement', 'children': ['34', '48']}; {'id': '34', 'type': 'comparison_operator', 'children': ['35', '47'], 'value': '=='}; {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'comparison_operator', 'children': ['41', '44'], 'value': '=='}; {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'Q'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': '_id'}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': '_id'}; {'id': '47', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '48', 'type': 'string', 'children': [], 'value': "'Only draft documents can be assigned new revisions'"}; {'id': '49', 'type': 'if_statement', 'children': ['50', '56']}; {'id': '50', 'type': 'comparison_operator', 'children': ['51', '55'], 'value': '>'}; {'id': '51', 'type': 'call', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'fields'}; {'id': '55', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '56', 'type': 'block', 'children': ['57']}; {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'call', 'children': ['59', '62']}; {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'fields'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}; {'id': '63', 'type': 'string', 'children': [], 'value': "'revision'"}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}; {'id': '65', 'type': 'assignment', 'children': ['66', '69']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'revision'}; {'id': '69', 'type': 'call', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'now'}; {'id': '73', 'type': 'argument_list', 'children': []}; {'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': 'self'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'upsert'}; {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'list_splat', 'children': ['81']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'fields'}
|
Save a new revision of the document
|
def construct(self, uri, *args, **kw):
logger.debug(util.lazy_format("Constructing {0}", uri))
if ('override' not in kw or kw['override'] is False) \
and uri in self.resolved:
logger.debug(util.lazy_format("Using existing {0}", uri))
return self.resolved[uri]
else:
ret = self._construct(uri, *args, **kw)
logger.debug(util.lazy_format("Constructed {0}", ret))
return ret
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'construct'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'uri'}; {'id': '6', 'type': 'list_splat_pattern', 'children': ['7']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '8', 'type': 'dictionary_splat_pattern', 'children': ['9']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'kw'}; {'id': '10', 'type': 'block', 'children': ['11', '24', '77', '90']}; {'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': 'logger'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '16', 'type': 'argument_list', 'children': ['17']}; {'id': '17', 'type': 'call', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'util'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'lazy_format'}; {'id': '21', 'type': 'argument_list', 'children': ['22', '23']}; {'id': '22', 'type': 'string', 'children': [], 'value': '"Constructing {0}"'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'uri'}; {'id': '24', 'type': 'if_statement', 'children': ['25', '42', '62']}; {'id': '25', 'type': 'boolean_operator', 'children': ['26', '36', '37'], 'value': 'and'}; {'id': '26', 'type': '()', 'children': ['27']}; {'id': '27', 'type': 'boolean_operator', 'children': ['28', '31'], 'value': 'or'}; {'id': '28', 'type': 'comparison_operator', 'children': ['29', '30'], 'value': 'not in'}; {'id': '29', 'type': 'string', 'children': [], 'value': "'override'"}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'kw'}; {'id': '31', 'type': 'comparison_operator', 'children': ['32', '35'], 'value': 'is'}; {'id': '32', 'type': 'subscript', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'kw'}; {'id': '34', 'type': 'string', 'children': [], 'value': "'override'"}; {'id': '35', 'type': 'False', 'children': []}; {'id': '36', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '37', 'type': 'comparison_operator', 'children': ['38', '39'], 'value': 'in'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'uri'}; {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'resolved'}; {'id': '42', 'type': 'block', 'children': ['43', '56']}; {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'call', 'children': ['45', '48']}; {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}; {'id': '49', 'type': 'call', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'util'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'lazy_format'}; {'id': '53', 'type': 'argument_list', 'children': ['54', '55']}; {'id': '54', 'type': 'string', 'children': [], 'value': '"Using existing {0}"'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'uri'}; {'id': '56', 'type': 'return_statement', 'children': ['57']}; {'id': '57', 'type': 'subscript', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'resolved'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'uri'}; {'id': '62', 'type': 'else_clause', 'children': ['63']}; {'id': '63', 'type': 'block', 'children': ['64']}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}; {'id': '65', 'type': 'assignment', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '67', 'type': 'call', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': '_construct'}; {'id': '71', 'type': 'argument_list', 'children': ['72', '73', '75']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'uri'}; {'id': '73', 'type': 'list_splat', 'children': ['74']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '75', 'type': 'dictionary_splat', 'children': ['76']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'kw'}; {'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': 'logger'}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}; {'id': '83', 'type': 'call', 'children': ['84', '87']}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'util'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'lazy_format'}; {'id': '87', 'type': 'argument_list', 'children': ['88', '89']}; {'id': '88', 'type': 'string', 'children': [], 'value': '"Constructed {0}"'}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '90', 'type': 'return_statement', 'children': ['91']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'ret'}
|
Wrapper to debug things
|
def files_in_path(path):
aggregated_files = []
for dir_, _, files in os.walk(path):
for file in files:
relative_dir = os.path.relpath(dir_, path)
if ".git" not in relative_dir:
relative_file = os.path.join(relative_dir, file)
aggregated_files.append(relative_file)
return aggregated_files
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'files_in_path'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '5', 'type': 'block', 'children': ['6', '10', '62']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'aggregated_files'}; {'id': '9', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '10', 'type': 'for_statement', 'children': ['11', '15', '21']}; {'id': '11', 'type': 'pattern_list', 'children': ['12', '13', '14']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'dir_'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'files'}; {'id': '15', 'type': 'call', 'children': ['16', '19']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'walk'}; {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '21', 'type': 'block', 'children': ['22']}; {'id': '22', 'type': 'for_statement', 'children': ['23', '24', '25']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'file'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'files'}; {'id': '25', 'type': 'block', 'children': ['26', '38']}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}; {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'relative_dir'}; {'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': 'os'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'relpath'}; {'id': '35', 'type': 'argument_list', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'dir_'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '38', 'type': 'if_statement', 'children': ['39', '42']}; {'id': '39', 'type': 'comparison_operator', 'children': ['40', '41'], 'value': 'not in'}; {'id': '40', 'type': 'string', 'children': [], 'value': '".git"'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'relative_dir'}; {'id': '42', 'type': 'block', 'children': ['43', '55']}; {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'relative_file'}; {'id': '46', 'type': 'call', 'children': ['47', '52']}; {'id': '47', 'type': 'attribute', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '52', 'type': 'argument_list', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'relative_dir'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'file'}; {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'call', 'children': ['57', '60']}; {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'aggregated_files'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'relative_file'}; {'id': '62', 'type': 'return_statement', 'children': ['63']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'aggregated_files'}
|
Return a list of all files in a path but exclude git folders.
|
def get(self, block=True, timeout=None):
value = self._queue.get(block, timeout)
if self._queue.empty():
self.clear()
return value
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'block'}; {'id': '7', 'type': 'True', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'timeout'}; {'id': '10', 'type': 'None', 'children': []}; {'id': '11', 'type': 'block', 'children': ['12', '24', '39']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}; {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'value'}; {'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': 'self'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': '_queue'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '21', 'type': 'argument_list', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'block'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'timeout'}; {'id': '24', 'type': 'if_statement', 'children': ['25', '32']}; {'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': '_queue'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'empty'}; {'id': '31', 'type': 'argument_list', 'children': []}; {'id': '32', 'type': 'block', 'children': ['33']}; {'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': 'self'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'clear'}; {'id': '38', 'type': 'argument_list', 'children': []}; {'id': '39', 'type': 'return_statement', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'value'}
|
Removes and returns an item from the queue.
|
def list_records_for_project(id=None, name=None, page_size=200, page_index=0, sort="", q=""):
data = list_records_for_project_raw(id, name, page_size, page_index, sort, q)
if data:
return utils.format_json_list(data)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '22']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'list_records_for_project'}; {'id': '3', 'type': 'parameters', 'children': ['4', '7', '10', '13', '16', '19']}; {'id': '4', 'type': 'default_parameter', 'children': ['5', '6']}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '6', 'type': 'None', 'children': []}; {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '9', 'type': 'None', 'children': []}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'page_size'}; {'id': '12', 'type': 'integer', 'children': [], 'value': '200'}; {'id': '13', 'type': 'default_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'page_index'}; {'id': '15', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '16', 'type': 'default_parameter', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '18', 'type': 'string', 'children': [], 'value': '""'}; {'id': '19', 'type': 'default_parameter', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'q'}; {'id': '21', 'type': 'string', 'children': [], 'value': '""'}; {'id': '22', 'type': 'block', 'children': ['23', '35']}; {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '26', 'type': 'call', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'list_records_for_project_raw'}; {'id': '28', 'type': 'argument_list', 'children': ['29', '30', '31', '32', '33', '34']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'page_size'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'page_index'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'q'}; {'id': '35', 'type': 'if_statement', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '37', 'type': 'block', 'children': ['38']}; {'id': '38', 'type': 'return_statement', 'children': ['39']}; {'id': '39', 'type': 'call', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'format_json_list'}; {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'data'}
|
List all BuildRecords for a given Project
|
def colorbar(height, length, colormap):
cbar = np.tile(np.arange(length) * 1.0 / (length - 1), (height, 1))
cbar = (cbar * (colormap.values.max() - colormap.values.min())
+ colormap.values.min())
return colormap.colorize(cbar)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'colorbar'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'height'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'length'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'colormap'}; {'id': '7', 'type': 'block', 'children': ['8', '32', '62']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'cbar'}; {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'tile'}; {'id': '15', 'type': 'argument_list', 'children': ['16', '29']}; {'id': '16', 'type': 'binary_operator', 'children': ['17', '25'], 'value': '/'}; {'id': '17', 'type': 'binary_operator', 'children': ['18', '24'], 'value': '*'}; {'id': '18', 'type': 'call', 'children': ['19', '22']}; {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'arange'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'length'}; {'id': '24', 'type': 'float', 'children': [], 'value': '1.0'}; {'id': '25', 'type': '()', 'children': ['26']}; {'id': '26', 'type': 'binary_operator', 'children': ['27', '28'], 'value': '-'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'length'}; {'id': '28', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '29', 'type': 'tuple', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'height'}; {'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': 'cbar'}; {'id': '35', 'type': '()', 'children': ['36']}; {'id': '36', 'type': 'binary_operator', 'children': ['37', '55'], 'value': '+'}; {'id': '37', 'type': 'binary_operator', 'children': ['38', '39'], 'value': '*'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'cbar'}; {'id': '39', 'type': '()', 'children': ['40']}; {'id': '40', 'type': 'binary_operator', 'children': ['41', '48'], 'value': '-'}; {'id': '41', 'type': 'call', 'children': ['42', '47']}; {'id': '42', 'type': 'attribute', 'children': ['43', '46']}; {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'colormap'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '47', 'type': 'argument_list', 'children': []}; {'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': 'colormap'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'min'}; {'id': '54', 'type': 'argument_list', 'children': []}; {'id': '55', 'type': 'call', 'children': ['56', '61']}; {'id': '56', 'type': 'attribute', 'children': ['57', '60']}; {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'colormap'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'min'}; {'id': '61', 'type': 'argument_list', 'children': []}; {'id': '62', 'type': 'return_statement', 'children': ['63']}; {'id': '63', 'type': 'call', 'children': ['64', '67']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'colormap'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'colorize'}; {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'cbar'}
|
Return the channels of a colorbar.
|
def reply_bytes(self, request):
flags = struct.pack("<I", self._flags)
payload_type = struct.pack("<b", 0)
payload_data = bson.BSON.encode(self.doc)
data = b''.join([flags, payload_type, payload_data])
reply_id = random.randint(0, 1000000)
response_to = request.request_id
header = struct.pack(
"<iiii", 16 + len(data), reply_id, response_to, OP_MSG)
return header + data
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'reply_bytes'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '6', 'type': 'block', 'children': ['7', '19', '29', '42', '54', '64', '70', '88']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'flags'}; {'id': '10', 'type': 'call', 'children': ['11', '14']}; {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'struct'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'pack'}; {'id': '14', 'type': 'argument_list', 'children': ['15', '16']}; {'id': '15', 'type': 'string', 'children': [], 'value': '"<I"'}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': '_flags'}; {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'payload_type'}; {'id': '22', 'type': 'call', 'children': ['23', '26']}; {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'struct'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'pack'}; {'id': '26', 'type': 'argument_list', 'children': ['27', '28']}; {'id': '27', 'type': 'string', 'children': [], 'value': '"<b"'}; {'id': '28', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'payload_data'}; {'id': '32', 'type': 'call', 'children': ['33', '38']}; {'id': '33', 'type': 'attribute', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'bson'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'BSON'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'encode'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}; {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'doc'}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}; {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}; {'id': '47', 'type': 'string', 'children': [], 'value': "b''"}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'list', 'children': ['51', '52', '53'], 'value': '[flags, payload_type, payload_data]'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'flags'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'payload_type'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'payload_data'}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}; {'id': '55', 'type': 'assignment', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'reply_id'}; {'id': '57', 'type': 'call', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'random'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'randint'}; {'id': '61', 'type': 'argument_list', 'children': ['62', '63']}; {'id': '62', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '63', 'type': 'integer', 'children': [], 'value': '1000000'}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}; {'id': '65', 'type': 'assignment', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'response_to'}; {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'request_id'}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}; {'id': '71', 'type': 'assignment', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'header'}; {'id': '73', 'type': 'call', 'children': ['74', '77']}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'struct'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'pack'}; {'id': '77', 'type': 'argument_list', 'children': ['78', '79', '85', '86', '87']}; {'id': '78', 'type': 'string', 'children': [], 'value': '"<iiii"'}; {'id': '79', 'type': 'binary_operator', 'children': ['80', '81'], 'value': '+'}; {'id': '80', 'type': 'integer', 'children': [], 'value': '16'}; {'id': '81', 'type': 'call', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '83', 'type': 'argument_list', 'children': ['84']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'reply_id'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'response_to'}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'OP_MSG'}; {'id': '88', 'type': 'return_statement', 'children': ['89']}; {'id': '89', 'type': 'binary_operator', 'children': ['90', '91'], 'value': '+'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'header'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'data'}
|
Take a `Request` and return an OP_MSG message as bytes.
|
def _from_dict(cls, _dict):
args = {}
if 'models' in _dict:
args['models'] = [
SpeechModel._from_dict(x) for x in (_dict.get('models'))
]
else:
raise ValueError(
'Required property \'models\' not present in SpeechModels JSON')
return cls(**args)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_from_dict'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': '_dict'}; {'id': '6', 'type': 'block', 'children': ['7', '11', '44']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '10', 'type': 'dictionary', 'children': []}; {'id': '11', 'type': 'if_statement', 'children': ['12', '15', '37']}; {'id': '12', 'type': 'comparison_operator', 'children': ['13', '14'], 'value': 'in'}; {'id': '13', 'type': 'string', 'children': [], 'value': "'models'"}; {'id': '14', 'type': 'identifier', 'children': [], 'value': '_dict'}; {'id': '15', 'type': 'block', 'children': ['16']}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}; {'id': '17', 'type': 'assignment', 'children': ['18', '21']}; {'id': '18', 'type': 'subscript', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '20', 'type': 'string', 'children': [], 'value': "'models'"}; {'id': '21', 'type': 'list_comprehension', 'children': ['22', '28']}; {'id': '22', 'type': 'call', 'children': ['23', '26']}; {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'SpeechModel'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': '_from_dict'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '28', 'type': 'for_in_clause', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '30', 'type': '()', 'children': ['31']}; {'id': '31', 'type': 'call', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': '_dict'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'string', 'children': [], 'value': "'models'"}; {'id': '37', 'type': 'else_clause', 'children': ['38']}; {'id': '38', 'type': 'block', 'children': ['39']}; {'id': '39', 'type': 'raise_statement', 'children': ['40']}; {'id': '40', 'type': 'call', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}; {'id': '43', 'type': 'string', 'children': [], 'value': "'Required property \\'models\\' not present in SpeechModels JSON'"}; {'id': '44', 'type': 'return_statement', 'children': ['45']}; {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'dictionary_splat', 'children': ['49']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'args'}
|
Initialize a SpeechModels object from a json dictionary.
|
def astype(self, type_name):
if type_name == 'nddata':
return self.as_nddata()
if type_name == 'hdu':
return self.as_hdu()
raise ValueError("Unrecognized conversion type '%s'" % (type_name))
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'astype'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'type_name'}; {'id': '6', 'type': 'block', 'children': ['7', '18', '29']}; {'id': '7', 'type': 'if_statement', 'children': ['8', '11']}; {'id': '8', 'type': 'comparison_operator', 'children': ['9', '10'], 'value': '=='}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'type_name'}; {'id': '10', 'type': 'string', 'children': [], 'value': "'nddata'"}; {'id': '11', 'type': 'block', 'children': ['12']}; {'id': '12', 'type': 'return_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': 'as_nddata'}; {'id': '17', 'type': 'argument_list', 'children': []}; {'id': '18', 'type': 'if_statement', 'children': ['19', '22']}; {'id': '19', 'type': 'comparison_operator', 'children': ['20', '21'], 'value': '=='}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'type_name'}; {'id': '21', 'type': 'string', 'children': [], 'value': "'hdu'"}; {'id': '22', 'type': 'block', 'children': ['23']}; {'id': '23', 'type': 'return_statement', 'children': ['24']}; {'id': '24', 'type': 'call', 'children': ['25', '28']}; {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'as_hdu'}; {'id': '28', 'type': 'argument_list', 'children': []}; {'id': '29', 'type': 'raise_statement', 'children': ['30']}; {'id': '30', 'type': 'call', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}; {'id': '33', 'type': 'binary_operator', 'children': ['34', '35'], 'value': '%'}; {'id': '34', 'type': 'string', 'children': [], 'value': '"Unrecognized conversion type \'%s\'"'}; {'id': '35', 'type': '()', 'children': ['36']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'type_name'}
|
Convert AstroImage object to some other kind of object.
|
def select(self, table, cols, execute=True, select_type='SELECT', return_type=list):
select_type = select_type.upper()
assert select_type in SELECT_QUERY_TYPES
statement = '{0} {1} FROM {2}'.format(select_type, join_cols(cols), wrap(table))
if not execute:
return statement
values = self.fetch(statement)
return self._return_rows(table, cols, values, return_type)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'select'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'table'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'cols'}; {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'execute'}; {'id': '9', 'type': 'True', 'children': []}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'select_type'}; {'id': '12', 'type': 'string', 'children': [], 'value': "'SELECT'"}; {'id': '13', 'type': 'default_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'return_type'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '16', 'type': 'block', 'children': ['17', '25', '29', '46', '52', '61']}; {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'select_type'}; {'id': '20', 'type': 'call', 'children': ['21', '24']}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'select_type'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'upper'}; {'id': '24', 'type': 'argument_list', 'children': []}; {'id': '25', 'type': 'assert_statement', 'children': ['26']}; {'id': '26', 'type': 'comparison_operator', 'children': ['27', '28'], 'value': 'in'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'select_type'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'SELECT_QUERY_TYPES'}; {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'statement'}; {'id': '32', 'type': 'call', 'children': ['33', '36']}; {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'string', 'children': [], 'value': "'{0} {1} FROM {2}'"}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '36', 'type': 'argument_list', 'children': ['37', '38', '42']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'select_type'}; {'id': '38', 'type': 'call', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'join_cols'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'cols'}; {'id': '42', 'type': 'call', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'wrap'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'table'}; {'id': '46', 'type': 'if_statement', 'children': ['47', '49']}; {'id': '47', 'type': 'not_operator', 'children': ['48']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'execute'}; {'id': '49', 'type': 'block', 'children': ['50']}; {'id': '50', 'type': 'return_statement', 'children': ['51']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'statement'}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}; {'id': '53', 'type': 'assignment', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'values'}; {'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': 'fetch'}; {'id': '59', 'type': 'argument_list', 'children': ['60']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'statement'}; {'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': '_return_rows'}; {'id': '66', 'type': 'argument_list', 'children': ['67', '68', '69', '70']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'table'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'cols'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'return_type'}
|
Query every row and only certain columns from a table.
|
def decode(hashcode, delta=False):
lat, lon, lat_length, lon_length = _decode_c2i(hashcode)
if hasattr(float, "fromhex"):
latitude_delta = 90.0/(1 << lat_length)
longitude_delta = 180.0/(1 << lon_length)
latitude = _int_to_float_hex(lat, lat_length) * 90.0 + latitude_delta
longitude = _int_to_float_hex(lon, lon_length) * 180.0 + longitude_delta
if delta:
return latitude, longitude, latitude_delta, longitude_delta
return latitude, longitude
lat = (lat << 1) + 1
lon = (lon << 1) + 1
lat_length += 1
lon_length += 1
latitude = 180.0*(lat-(1 << (lat_length-1)))/(1 << lat_length)
longitude = 360.0*(lon-(1 << (lon_length-1)))/(1 << lon_length)
if delta:
latitude_delta = 180.0/(1 << lat_length)
longitude_delta = 360.0/(1 << lon_length)
return latitude, longitude, latitude_delta, longitude_delta
return latitude, longitude
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'decode'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'hashcode'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'delta'}; {'id': '7', 'type': 'False', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '20', '82', '91', '100', '104', '108', '128', '148', '175']}; {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '16']}; {'id': '11', 'type': 'pattern_list', 'children': ['12', '13', '14', '15']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'lat'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'lon'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'lat_length'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'lon_length'}; {'id': '16', 'type': 'call', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': '_decode_c2i'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'hashcode'}; {'id': '20', 'type': 'if_statement', 'children': ['21', '26']}; {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'hasattr'}; {'id': '23', 'type': 'argument_list', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '25', 'type': 'string', 'children': [], 'value': '"fromhex"'}; {'id': '26', 'type': 'block', 'children': ['27', '36', '45', '57', '69', '78']}; {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'latitude_delta'}; {'id': '30', 'type': 'binary_operator', 'children': ['31', '32'], 'value': '/'}; {'id': '31', 'type': 'float', 'children': [], 'value': '90.0'}; {'id': '32', 'type': '()', 'children': ['33']}; {'id': '33', 'type': 'binary_operator', 'children': ['34', '35'], 'value': '<<'}; {'id': '34', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'lat_length'}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}; {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'longitude_delta'}; {'id': '39', 'type': 'binary_operator', 'children': ['40', '41'], 'value': '/'}; {'id': '40', 'type': 'float', 'children': [], 'value': '180.0'}; {'id': '41', 'type': '()', 'children': ['42']}; {'id': '42', 'type': 'binary_operator', 'children': ['43', '44'], 'value': '<<'}; {'id': '43', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'lon_length'}; {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'latitude'}; {'id': '48', 'type': 'binary_operator', 'children': ['49', '56'], 'value': '+'}; {'id': '49', 'type': 'binary_operator', 'children': ['50', '55'], 'value': '*'}; {'id': '50', 'type': 'call', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': '_int_to_float_hex'}; {'id': '52', 'type': 'argument_list', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'lat'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'lat_length'}; {'id': '55', 'type': 'float', 'children': [], 'value': '90.0'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'latitude_delta'}; {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'longitude'}; {'id': '60', 'type': 'binary_operator', 'children': ['61', '68'], 'value': '+'}; {'id': '61', 'type': 'binary_operator', 'children': ['62', '67'], 'value': '*'}; {'id': '62', 'type': 'call', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': '_int_to_float_hex'}; {'id': '64', 'type': 'argument_list', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'lon'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'lon_length'}; {'id': '67', 'type': 'float', 'children': [], 'value': '180.0'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'longitude_delta'}; {'id': '69', 'type': 'if_statement', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'delta'}; {'id': '71', 'type': 'block', 'children': ['72']}; {'id': '72', 'type': 'return_statement', 'children': ['73']}; {'id': '73', 'type': 'expression_list', 'children': ['74', '75', '76', '77']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'latitude'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'longitude'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'latitude_delta'}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'longitude_delta'}; {'id': '78', 'type': 'return_statement', 'children': ['79']}; {'id': '79', 'type': 'expression_list', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'latitude'}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'longitude'}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}; {'id': '83', 'type': 'assignment', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'lat'}; {'id': '85', 'type': 'binary_operator', 'children': ['86', '90'], 'value': '+'}; {'id': '86', 'type': '()', 'children': ['87']}; {'id': '87', 'type': 'binary_operator', 'children': ['88', '89'], 'value': '<<'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'lat'}; {'id': '89', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '90', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'lon'}; {'id': '94', 'type': 'binary_operator', 'children': ['95', '99'], 'value': '+'}; {'id': '95', 'type': '()', 'children': ['96']}; {'id': '96', 'type': 'binary_operator', 'children': ['97', '98'], 'value': '<<'}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'lon'}; {'id': '98', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '99', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}; {'id': '101', 'type': 'augmented_assignment', 'children': ['102', '103'], 'value': '+='}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'lat_length'}; {'id': '103', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}; {'id': '105', 'type': 'augmented_assignment', 'children': ['106', '107'], 'value': '+='}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'lon_length'}; {'id': '107', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}; {'id': '109', 'type': 'assignment', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'latitude'}; {'id': '111', 'type': 'binary_operator', 'children': ['112', '124'], 'value': '/'}; {'id': '112', 'type': 'binary_operator', 'children': ['113', '114'], 'value': '*'}; {'id': '113', 'type': 'float', 'children': [], 'value': '180.0'}; {'id': '114', 'type': '()', 'children': ['115']}; {'id': '115', 'type': 'binary_operator', 'children': ['116', '117'], 'value': '-'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'lat'}; {'id': '117', 'type': '()', 'children': ['118']}; {'id': '118', 'type': 'binary_operator', 'children': ['119', '120'], 'value': '<<'}; {'id': '119', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '120', 'type': '()', 'children': ['121']}; {'id': '121', 'type': 'binary_operator', 'children': ['122', '123'], 'value': '-'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'lat_length'}; {'id': '123', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '124', 'type': '()', 'children': ['125']}; {'id': '125', 'type': 'binary_operator', 'children': ['126', '127'], 'value': '<<'}; {'id': '126', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'lat_length'}; {'id': '128', 'type': 'expression_statement', 'children': ['129']}; {'id': '129', 'type': 'assignment', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'longitude'}; {'id': '131', 'type': 'binary_operator', 'children': ['132', '144'], 'value': '/'}; {'id': '132', 'type': 'binary_operator', 'children': ['133', '134'], 'value': '*'}; {'id': '133', 'type': 'float', 'children': [], 'value': '360.0'}; {'id': '134', 'type': '()', 'children': ['135']}; {'id': '135', 'type': 'binary_operator', 'children': ['136', '137'], 'value': '-'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'lon'}; {'id': '137', 'type': '()', 'children': ['138']}; {'id': '138', 'type': 'binary_operator', 'children': ['139', '140'], 'value': '<<'}; {'id': '139', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '140', 'type': '()', 'children': ['141']}; {'id': '141', 'type': 'binary_operator', 'children': ['142', '143'], 'value': '-'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'lon_length'}; {'id': '143', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '144', 'type': '()', 'children': ['145']}; {'id': '145', 'type': 'binary_operator', 'children': ['146', '147'], 'value': '<<'}; {'id': '146', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'lon_length'}; {'id': '148', 'type': 'if_statement', 'children': ['149', '150']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'delta'}; {'id': '150', 'type': 'block', 'children': ['151', '160', '169']}; {'id': '151', 'type': 'expression_statement', 'children': ['152']}; {'id': '152', 'type': 'assignment', 'children': ['153', '154']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'latitude_delta'}; {'id': '154', 'type': 'binary_operator', 'children': ['155', '156'], 'value': '/'}; {'id': '155', 'type': 'float', 'children': [], 'value': '180.0'}; {'id': '156', 'type': '()', 'children': ['157']}; {'id': '157', 'type': 'binary_operator', 'children': ['158', '159'], 'value': '<<'}; {'id': '158', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'lat_length'}; {'id': '160', 'type': 'expression_statement', 'children': ['161']}; {'id': '161', 'type': 'assignment', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'longitude_delta'}; {'id': '163', 'type': 'binary_operator', 'children': ['164', '165'], 'value': '/'}; {'id': '164', 'type': 'float', 'children': [], 'value': '360.0'}; {'id': '165', 'type': '()', 'children': ['166']}; {'id': '166', 'type': 'binary_operator', 'children': ['167', '168'], 'value': '<<'}; {'id': '167', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'lon_length'}; {'id': '169', 'type': 'return_statement', 'children': ['170']}; {'id': '170', 'type': 'expression_list', 'children': ['171', '172', '173', '174']}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'latitude'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'longitude'}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'latitude_delta'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'longitude_delta'}; {'id': '175', 'type': 'return_statement', 'children': ['176']}; {'id': '176', 'type': 'expression_list', 'children': ['177', '178']}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'latitude'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'longitude'}
|
decode a hashcode and get center coordinate, and distance between center and outer border
|
def apply_interceptors(work_db, enabled_interceptors):
names = (name for name in interceptor_names() if name in enabled_interceptors)
for name in names:
interceptor = get_interceptor(name)
interceptor(work_db)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'apply_interceptors'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'work_db'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'enabled_interceptors'}; {'id': '6', 'type': 'block', 'children': ['7', '21']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '10', 'type': 'generator_expression', 'children': ['11', '12', '17']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '12', 'type': 'for_in_clause', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '14', 'type': 'call', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'interceptor_names'}; {'id': '16', 'type': 'argument_list', 'children': []}; {'id': '17', 'type': 'if_clause', 'children': ['18']}; {'id': '18', 'type': 'comparison_operator', 'children': ['19', '20'], 'value': 'in'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'enabled_interceptors'}; {'id': '21', 'type': 'for_statement', 'children': ['22', '23', '24']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '24', 'type': 'block', 'children': ['25', '32']}; {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'interceptor'}; {'id': '28', 'type': 'call', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'get_interceptor'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}; {'id': '33', 'type': 'call', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'interceptor'}; {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'work_db'}
|
Apply each registered interceptor to the WorkDB.
|
def send(self, *args):
for frame in args:
self.sock.sendall(self.apply_send_hooks(frame, False).pack())
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'send'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'list_splat_pattern', 'children': ['6']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '7', 'type': 'block', 'children': ['8']}; {'id': '8', 'type': 'for_statement', 'children': ['9', '10', '11']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'frame'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '11', 'type': 'block', 'children': ['12']}; {'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': 'sock'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'sendall'}; {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'call', 'children': ['21', '30']}; {'id': '21', 'type': 'attribute', 'children': ['22', '29']}; {'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': 'apply_send_hooks'}; {'id': '26', 'type': 'argument_list', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'frame'}; {'id': '28', 'type': 'False', 'children': []}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'pack'}; {'id': '30', 'type': 'argument_list', 'children': []}
|
Send a number of frames.
|
def from_etree(
el, node=None, node_cls=None,
tagsub=functools.partial(re.sub, r'\{.+?\}', ''),
Node=Node):
node_cls = node_cls or Node
if node is None:
node = node_cls()
tag = tagsub(el.tag)
attrib = dict((tagsub(k), v) for (k, v) in el.attrib.items())
node.update(attrib, tag=tag)
if el.text:
node['text'] = el.text
for child in el:
child = from_etree(child, node_cls=node_cls)
node.append(child)
if el.tail:
node['tail'] = el.tail
return node
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '26']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'from_etree'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '23']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'el'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'node_cls'}; {'id': '10', 'type': 'None', 'children': []}; {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'tagsub'}; {'id': '13', 'type': 'call', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'functools'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'partial'}; {'id': '17', 'type': 'argument_list', 'children': ['18', '21', '22']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'sub'}; {'id': '21', 'type': 'string', 'children': [], 'value': "r'\\{.+?\\}'"}; {'id': '22', 'type': 'string', 'children': [], 'value': "''"}; {'id': '23', 'type': 'default_parameter', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'Node'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'Node'}; {'id': '26', 'type': 'block', 'children': ['27', '33', '44', '53', '76', '86', '99', '120', '133']}; {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'node_cls'}; {'id': '30', 'type': 'boolean_operator', 'children': ['31', '32'], 'value': 'or'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'node_cls'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'Node'}; {'id': '33', 'type': 'if_statement', 'children': ['34', '37']}; {'id': '34', 'type': 'comparison_operator', 'children': ['35', '36'], 'value': 'is'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '36', 'type': 'None', 'children': []}; {'id': '37', 'type': 'block', 'children': ['38']}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}; {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '41', 'type': 'call', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'node_cls'}; {'id': '43', 'type': 'argument_list', 'children': []}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}; {'id': '45', 'type': 'assignment', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'id': '47', 'type': 'call', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'tagsub'}; {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'el'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'attrib'}; {'id': '56', 'type': 'call', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '58', 'type': 'generator_expression', 'children': ['59', '65']}; {'id': '59', 'type': 'tuple', 'children': ['60', '64']}; {'id': '60', 'type': 'call', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'tagsub'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '65', 'type': 'for_in_clause', 'children': ['66', '69']}; {'id': '66', 'type': 'tuple_pattern', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '69', 'type': 'call', 'children': ['70', '75']}; {'id': '70', 'type': 'attribute', 'children': ['71', '74']}; {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'el'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'attrib'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '75', 'type': 'argument_list', 'children': []}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}; {'id': '77', 'type': 'call', 'children': ['78', '81']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '81', 'type': 'argument_list', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'attrib'}; {'id': '83', 'type': 'keyword_argument', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'id': '86', 'type': 'if_statement', 'children': ['87', '90']}; {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'el'}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '90', 'type': 'block', 'children': ['91']}; {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '96']}; {'id': '93', 'type': 'subscript', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '95', 'type': 'string', 'children': [], 'value': "'text'"}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'el'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '99', 'type': 'for_statement', 'children': ['100', '101', '102']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'el'}; {'id': '102', 'type': 'block', 'children': ['103', '113']}; {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'assignment', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '106', 'type': 'call', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'from_etree'}; {'id': '108', 'type': 'argument_list', 'children': ['109', '110']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '110', 'type': 'keyword_argument', 'children': ['111', '112']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'node_cls'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'node_cls'}; {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'call', 'children': ['115', '118']}; {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '118', 'type': 'argument_list', 'children': ['119']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '120', 'type': 'if_statement', 'children': ['121', '124']}; {'id': '121', 'type': 'attribute', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'el'}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'tail'}; {'id': '124', 'type': 'block', 'children': ['125']}; {'id': '125', 'type': 'expression_statement', 'children': ['126']}; {'id': '126', 'type': 'assignment', 'children': ['127', '130']}; {'id': '127', 'type': 'subscript', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '129', 'type': 'string', 'children': [], 'value': "'tail'"}; {'id': '130', 'type': 'attribute', 'children': ['131', '132']}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'el'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'tail'}; {'id': '133', 'type': 'return_statement', 'children': ['134']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'node'}
|
Convert the element tree to a tater tree.
|
def update(self, **kwargs):
if 'monitor' in kwargs:
value = self._format_monitor_parameter(kwargs['monitor'])
kwargs['monitor'] = value
elif 'monitor' in self.__dict__:
value = self._format_monitor_parameter(self.__dict__['monitor'])
self.__dict__['monitor'] = value
return super(Pool, self)._update(**kwargs)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'update'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'dictionary_splat_pattern', 'children': ['6']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '7', 'type': 'block', 'children': ['8', '58']}; {'id': '8', 'type': 'if_statement', 'children': ['9', '12', '30']}; {'id': '9', 'type': 'comparison_operator', 'children': ['10', '11'], 'value': 'in'}; {'id': '10', 'type': 'string', 'children': [], 'value': "'monitor'"}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '12', 'type': 'block', 'children': ['13', '24']}; {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'value'}; {'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': '_format_monitor_parameter'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}; {'id': '21', 'type': 'subscript', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '23', 'type': 'string', 'children': [], 'value': "'monitor'"}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}; {'id': '25', 'type': 'assignment', 'children': ['26', '29']}; {'id': '26', 'type': 'subscript', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '28', 'type': 'string', 'children': [], 'value': "'monitor'"}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '30', 'type': 'elif_clause', 'children': ['31', '36']}; {'id': '31', 'type': 'comparison_operator', 'children': ['32', '33'], 'value': 'in'}; {'id': '32', 'type': 'string', 'children': [], 'value': "'monitor'"}; {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': '__dict__'}; {'id': '36', 'type': 'block', 'children': ['37', '50']}; {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '40', 'type': 'call', 'children': ['41', '44']}; {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': '_format_monitor_parameter'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}; {'id': '45', 'type': 'subscript', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': '__dict__'}; {'id': '49', 'type': 'string', 'children': [], 'value': "'monitor'"}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}; {'id': '51', 'type': 'assignment', 'children': ['52', '57']}; {'id': '52', 'type': 'subscript', 'children': ['53', '56']}; {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': '__dict__'}; {'id': '56', 'type': 'string', 'children': [], 'value': "'monitor'"}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '58', 'type': 'return_statement', 'children': ['59']}; {'id': '59', 'type': 'call', 'children': ['60', '67']}; {'id': '60', 'type': 'attribute', 'children': ['61', '66']}; {'id': '61', 'type': 'call', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'super'}; {'id': '63', 'type': 'argument_list', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'Pool'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': '_update'}; {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'dictionary_splat', 'children': ['69']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'kwargs'}
|
Custom update method to implement monitor parameter formatting.
|
def secretfile_args(parser):
parser.add_argument('--secrets',
dest='secrets',
help='Path where secrets are stored',
default=os.path.join(os.getcwd(), ".secrets"))
parser.add_argument('--policies',
dest='policies',
help='Path where policies are stored',
default=os.path.join(os.getcwd(), "vault", ""))
parser.add_argument('--secretfile',
dest='secretfile',
help='Secretfile to use',
default=os.path.join(os.getcwd(), "Secretfile"))
parser.add_argument('--tags',
dest='tags',
help='Tags of things to seed',
default=[],
type=str,
action='append')
parser.add_argument('--include',
dest='include',
help='Specify paths to include',
default=[],
type=str,
action='append')
parser.add_argument('--exclude',
dest='exclude',
help='Specify paths to exclude',
default=[],
type=str,
action='append')
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'secretfile_args'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'parser'}; {'id': '5', 'type': 'block', 'children': ['6', '34', '63', '91', '113', '135']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'call', 'children': ['8', '11']}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'parser'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'add_argument'}; {'id': '11', 'type': 'argument_list', 'children': ['12', '13', '16', '19']}; {'id': '12', 'type': 'string', 'children': [], 'value': "'--secrets'"}; {'id': '13', 'type': 'keyword_argument', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'dest'}; {'id': '15', 'type': 'string', 'children': [], 'value': "'secrets'"}; {'id': '16', 'type': 'keyword_argument', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'help'}; {'id': '18', 'type': 'string', 'children': [], 'value': "'Path where secrets are stored'"}; {'id': '19', 'type': 'keyword_argument', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '21', 'type': 'call', 'children': ['22', '27']}; {'id': '22', 'type': 'attribute', 'children': ['23', '26']}; {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '27', 'type': 'argument_list', 'children': ['28', '33']}; {'id': '28', 'type': 'call', 'children': ['29', '32']}; {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'getcwd'}; {'id': '32', 'type': 'argument_list', 'children': []}; {'id': '33', 'type': 'string', 'children': [], 'value': '".secrets"'}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}; {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'parser'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'add_argument'}; {'id': '39', 'type': 'argument_list', 'children': ['40', '41', '44', '47']}; {'id': '40', 'type': 'string', 'children': [], 'value': "'--policies'"}; {'id': '41', 'type': 'keyword_argument', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'dest'}; {'id': '43', 'type': 'string', 'children': [], 'value': "'policies'"}; {'id': '44', 'type': 'keyword_argument', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'help'}; {'id': '46', 'type': 'string', 'children': [], 'value': "'Path where policies are stored'"}; {'id': '47', 'type': 'keyword_argument', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '49', 'type': 'call', 'children': ['50', '55']}; {'id': '50', 'type': 'attribute', 'children': ['51', '54']}; {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '55', 'type': 'argument_list', 'children': ['56', '61', '62']}; {'id': '56', 'type': 'call', 'children': ['57', '60']}; {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'getcwd'}; {'id': '60', 'type': 'argument_list', 'children': []}; {'id': '61', 'type': 'string', 'children': [], 'value': '"vault"'}; {'id': '62', 'type': 'string', 'children': [], 'value': '""'}; {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'call', 'children': ['65', '68']}; {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'parser'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'add_argument'}; {'id': '68', 'type': 'argument_list', 'children': ['69', '70', '73', '76']}; {'id': '69', 'type': 'string', 'children': [], 'value': "'--secretfile'"}; {'id': '70', 'type': 'keyword_argument', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'dest'}; {'id': '72', 'type': 'string', 'children': [], 'value': "'secretfile'"}; {'id': '73', 'type': 'keyword_argument', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'help'}; {'id': '75', 'type': 'string', 'children': [], 'value': "'Secretfile to use'"}; {'id': '76', 'type': 'keyword_argument', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'default'}; {'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': 'os'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '84', 'type': 'argument_list', 'children': ['85', '90']}; {'id': '85', 'type': 'call', 'children': ['86', '89']}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'getcwd'}; {'id': '89', 'type': 'argument_list', 'children': []}; {'id': '90', 'type': 'string', 'children': [], 'value': '"Secretfile"'}; {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'call', 'children': ['93', '96']}; {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'parser'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'add_argument'}; {'id': '96', 'type': 'argument_list', 'children': ['97', '98', '101', '104', '107', '110']}; {'id': '97', 'type': 'string', 'children': [], 'value': "'--tags'"}; {'id': '98', 'type': 'keyword_argument', 'children': ['99', '100']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'dest'}; {'id': '100', 'type': 'string', 'children': [], 'value': "'tags'"}; {'id': '101', 'type': 'keyword_argument', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'help'}; {'id': '103', 'type': 'string', 'children': [], 'value': "'Tags of things to seed'"}; {'id': '104', 'type': 'keyword_argument', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '106', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '107', 'type': 'keyword_argument', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '110', 'type': 'keyword_argument', 'children': ['111', '112']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '112', 'type': 'string', 'children': [], 'value': "'append'"}; {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'call', 'children': ['115', '118']}; {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'parser'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'add_argument'}; {'id': '118', 'type': 'argument_list', 'children': ['119', '120', '123', '126', '129', '132']}; {'id': '119', 'type': 'string', 'children': [], 'value': "'--include'"}; {'id': '120', 'type': 'keyword_argument', 'children': ['121', '122']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'dest'}; {'id': '122', 'type': 'string', 'children': [], 'value': "'include'"}; {'id': '123', 'type': 'keyword_argument', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'help'}; {'id': '125', 'type': 'string', 'children': [], 'value': "'Specify paths to include'"}; {'id': '126', 'type': 'keyword_argument', 'children': ['127', '128']}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '128', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '129', 'type': 'keyword_argument', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '132', 'type': 'keyword_argument', 'children': ['133', '134']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '134', 'type': 'string', 'children': [], 'value': "'append'"}; {'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': 'parser'}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'add_argument'}; {'id': '140', 'type': 'argument_list', 'children': ['141', '142', '145', '148', '151', '154']}; {'id': '141', 'type': 'string', 'children': [], 'value': "'--exclude'"}; {'id': '142', 'type': 'keyword_argument', 'children': ['143', '144']}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'dest'}; {'id': '144', 'type': 'string', 'children': [], 'value': "'exclude'"}; {'id': '145', 'type': 'keyword_argument', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'help'}; {'id': '147', 'type': 'string', 'children': [], 'value': "'Specify paths to exclude'"}; {'id': '148', 'type': 'keyword_argument', 'children': ['149', '150']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '150', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '151', 'type': 'keyword_argument', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '154', 'type': 'keyword_argument', 'children': ['155', '156']}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '156', 'type': 'string', 'children': [], 'value': "'append'"}
|
Add Secretfile management command line arguments to parser
|
def bind(renderer, to):
@wraps(to)
def view(request, **kwargs):
try:
returned = to(request, **kwargs)
except Exception as error:
view_error = getattr(renderer, "view_error", None)
if view_error is None:
raise
return view_error(request, error)
try:
return renderer.render(request, returned)
except Exception as error:
render_error = getattr(renderer, "render_error", None)
if render_error is None:
raise
return render_error(request, returned, error)
return view
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'bind'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'renderer'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'to'}; {'id': '6', 'type': 'block', 'children': ['7', '96']}; {'id': '7', 'type': 'decorated_definition', 'children': ['8', '13']}; {'id': '8', 'type': 'decorator', 'children': ['9']}; {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'wraps'}; {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'to'}; {'id': '13', 'type': 'function_definition', 'children': ['14', '15', '19']}; {'id': '14', 'type': 'function_name', 'children': [], 'value': 'view'}; {'id': '15', 'type': 'parameters', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '17', 'type': 'dictionary_splat_pattern', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '19', 'type': 'block', 'children': ['20', '58']}; {'id': '20', 'type': 'try_statement', 'children': ['21', '31']}; {'id': '21', 'type': 'block', 'children': ['22']}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}; {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'returned'}; {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'to'}; {'id': '27', 'type': 'argument_list', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '29', 'type': 'dictionary_splat', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '31', 'type': 'except_clause', 'children': ['32', '36']}; {'id': '32', 'type': 'as_pattern', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '34', 'type': 'as_pattern_target', 'children': ['35']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '36', 'type': 'block', 'children': ['37', '46', '52']}; {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'view_error'}; {'id': '40', 'type': 'call', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '42', 'type': 'argument_list', 'children': ['43', '44', '45']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'renderer'}; {'id': '44', 'type': 'string', 'children': [], 'value': '"view_error"'}; {'id': '45', 'type': 'None', 'children': []}; {'id': '46', 'type': 'if_statement', 'children': ['47', '50']}; {'id': '47', 'type': 'comparison_operator', 'children': ['48', '49'], 'value': 'is'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'view_error'}; {'id': '49', 'type': 'None', 'children': []}; {'id': '50', 'type': 'block', 'children': ['51']}; {'id': '51', 'type': 'raise_statement', 'children': []}; {'id': '52', 'type': 'return_statement', 'children': ['53']}; {'id': '53', 'type': 'call', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'view_error'}; {'id': '55', 'type': 'argument_list', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '58', 'type': 'try_statement', 'children': ['59', '68']}; {'id': '59', 'type': 'block', 'children': ['60']}; {'id': '60', 'type': 'return_statement', 'children': ['61']}; {'id': '61', 'type': 'call', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'renderer'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'render'}; {'id': '65', 'type': 'argument_list', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'returned'}; {'id': '68', 'type': 'except_clause', 'children': ['69', '73']}; {'id': '69', 'type': 'as_pattern', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '71', 'type': 'as_pattern_target', 'children': ['72']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '73', 'type': 'block', 'children': ['74', '83', '89']}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}; {'id': '75', 'type': 'assignment', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'render_error'}; {'id': '77', 'type': 'call', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '79', 'type': 'argument_list', 'children': ['80', '81', '82']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'renderer'}; {'id': '81', 'type': 'string', 'children': [], 'value': '"render_error"'}; {'id': '82', 'type': 'None', 'children': []}; {'id': '83', 'type': 'if_statement', 'children': ['84', '87']}; {'id': '84', 'type': 'comparison_operator', 'children': ['85', '86'], 'value': 'is'}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'render_error'}; {'id': '86', 'type': 'None', 'children': []}; {'id': '87', 'type': 'block', 'children': ['88']}; {'id': '88', 'type': 'raise_statement', 'children': []}; {'id': '89', 'type': 'return_statement', 'children': ['90']}; {'id': '90', 'type': 'call', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'render_error'}; {'id': '92', 'type': 'argument_list', 'children': ['93', '94', '95']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'returned'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '96', 'type': 'return_statement', 'children': ['97']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'view'}
|
Bind a renderer to the given callable by constructing a new rendering view.
|
def Contradiction(expr1: Expression, expr2: Expression) -> Expression:
expr = Disjunction(Conjunction(expr1, Negation(expr2)),
Conjunction(Negation(expr1), expr2))
return ast.fix_missing_locations(expr)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'Contradiction'}; {'id': '3', 'type': 'parameters', 'children': ['4', '8']}; {'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'expr1'}; {'id': '6', 'type': 'type', 'children': ['7']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'Expression'}; {'id': '8', 'type': 'typed_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'expr2'}; {'id': '10', 'type': 'type', 'children': ['11']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'Expression'}; {'id': '12', 'type': 'type', 'children': ['13']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'Expression'}; {'id': '14', 'type': 'block', 'children': ['15', '37']}; {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'expr'}; {'id': '18', 'type': 'call', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'Disjunction'}; {'id': '20', 'type': 'argument_list', 'children': ['21', '29']}; {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'Conjunction'}; {'id': '23', 'type': 'argument_list', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'expr1'}; {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'Negation'}; {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'expr2'}; {'id': '29', 'type': 'call', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'Conjunction'}; {'id': '31', 'type': 'argument_list', 'children': ['32', '36']}; {'id': '32', 'type': 'call', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'Negation'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'expr1'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'expr2'}; {'id': '37', 'type': 'return_statement', 'children': ['38']}; {'id': '38', 'type': 'call', 'children': ['39', '42']}; {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'ast'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'fix_missing_locations'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'expr'}
|
Return expression which is the contradiction of `expr1` and `expr2`.
|
def to_rdkit_molecule(data):
mol = RWMol()
conf = Conformer()
mapping = {}
is_3d = False
for n, a in data.atoms():
ra = Atom(a.number)
ra.SetAtomMapNum(n)
if a.charge:
ra.SetFormalCharge(a.charge)
if a.isotope != a.common_isotope:
ra.SetIsotope(a.isotope)
if a.radical:
ra.SetNumRadicalElectrons(a.radical)
mapping[n] = m = mol.AddAtom(ra)
conf.SetAtomPosition(m, (a.x, a.y, a.z))
if a.z:
is_3d = True
if not is_3d:
conf.Set3D(False)
for n, m, b in data.bonds():
mol.AddBond(mapping[n], mapping[m], _bond_map[b.order])
mol.AddConformer(conf)
SanitizeMol(mol)
return mol
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'to_rdkit_molecule'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '5', 'type': 'block', 'children': ['6', '12', '18', '22', '26', '137', '148', '176', '183', '188']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'mol'}; {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'RWMol'}; {'id': '11', 'type': 'argument_list', 'children': []}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}; {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'conf'}; {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'Conformer'}; {'id': '17', 'type': 'argument_list', 'children': []}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}; {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'mapping'}; {'id': '21', 'type': 'dictionary', 'children': []}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}; {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'is_3d'}; {'id': '25', 'type': 'False', 'children': []}; {'id': '26', 'type': 'for_statement', 'children': ['27', '30', '35']}; {'id': '27', 'type': 'pattern_list', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'a'}; {'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': 'atoms'}; {'id': '34', 'type': 'argument_list', 'children': []}; {'id': '35', 'type': 'block', 'children': ['36', '45', '52', '66', '84', '98', '111', '128']}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}; {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'ra'}; {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'Atom'}; {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'number'}; {'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': 'ra'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'SetAtomMapNum'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '52', 'type': 'if_statement', 'children': ['53', '56']}; {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'charge'}; {'id': '56', 'type': 'block', 'children': ['57']}; {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'call', 'children': ['59', '62']}; {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'ra'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'SetFormalCharge'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}; {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'charge'}; {'id': '66', 'type': 'if_statement', 'children': ['67', '74']}; {'id': '67', 'type': 'comparison_operator', 'children': ['68', '71'], 'value': '!='}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'isotope'}; {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'common_isotope'}; {'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': 'ra'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'SetIsotope'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}; {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'isotope'}; {'id': '84', 'type': 'if_statement', 'children': ['85', '88']}; {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'radical'}; {'id': '88', 'type': 'block', 'children': ['89']}; {'id': '89', 'type': 'expression_statement', 'children': ['90']}; {'id': '90', 'type': 'call', 'children': ['91', '94']}; {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'ra'}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'SetNumRadicalElectrons'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}; {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'radical'}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}; {'id': '99', 'type': 'assignment', 'children': ['100', '103']}; {'id': '100', 'type': 'subscript', 'children': ['101', '102']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'mapping'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '103', 'type': 'assignment', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '105', 'type': 'call', 'children': ['106', '109']}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'mol'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'AddAtom'}; {'id': '109', 'type': 'argument_list', 'children': ['110']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'ra'}; {'id': '111', 'type': 'expression_statement', 'children': ['112']}; {'id': '112', 'type': 'call', 'children': ['113', '116']}; {'id': '113', 'type': 'attribute', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'conf'}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'SetAtomPosition'}; {'id': '116', 'type': 'argument_list', 'children': ['117', '118']}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '118', 'type': 'tuple', 'children': ['119', '122', '125']}; {'id': '119', 'type': 'attribute', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '122', 'type': 'attribute', 'children': ['123', '124']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '125', 'type': 'attribute', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'z'}; {'id': '128', 'type': 'if_statement', 'children': ['129', '132']}; {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'z'}; {'id': '132', 'type': 'block', 'children': ['133']}; {'id': '133', 'type': 'expression_statement', 'children': ['134']}; {'id': '134', 'type': 'assignment', 'children': ['135', '136']}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'is_3d'}; {'id': '136', 'type': 'True', 'children': []}; {'id': '137', 'type': 'if_statement', 'children': ['138', '140']}; {'id': '138', 'type': 'not_operator', 'children': ['139']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'is_3d'}; {'id': '140', 'type': 'block', 'children': ['141']}; {'id': '141', 'type': 'expression_statement', 'children': ['142']}; {'id': '142', 'type': 'call', 'children': ['143', '146']}; {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'conf'}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'Set3D'}; {'id': '146', 'type': 'argument_list', 'children': ['147']}; {'id': '147', 'type': 'False', 'children': []}; {'id': '148', 'type': 'for_statement', 'children': ['149', '153', '158']}; {'id': '149', 'type': 'pattern_list', 'children': ['150', '151', '152']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '153', 'type': 'call', 'children': ['154', '157']}; {'id': '154', 'type': 'attribute', 'children': ['155', '156']}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'bonds'}; {'id': '157', 'type': 'argument_list', 'children': []}; {'id': '158', 'type': 'block', 'children': ['159']}; {'id': '159', 'type': 'expression_statement', 'children': ['160']}; {'id': '160', 'type': 'call', 'children': ['161', '164']}; {'id': '161', 'type': 'attribute', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'mol'}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'AddBond'}; {'id': '164', 'type': 'argument_list', 'children': ['165', '168', '171']}; {'id': '165', 'type': 'subscript', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'mapping'}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '168', 'type': 'subscript', 'children': ['169', '170']}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'mapping'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '171', 'type': 'subscript', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': '_bond_map'}; {'id': '173', 'type': 'attribute', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '176', 'type': 'expression_statement', 'children': ['177']}; {'id': '177', 'type': 'call', 'children': ['178', '181']}; {'id': '178', 'type': 'attribute', 'children': ['179', '180']}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'mol'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'AddConformer'}; {'id': '181', 'type': 'argument_list', 'children': ['182']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'conf'}; {'id': '183', 'type': 'expression_statement', 'children': ['184']}; {'id': '184', 'type': 'call', 'children': ['185', '186']}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'SanitizeMol'}; {'id': '186', 'type': 'argument_list', 'children': ['187']}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'mol'}; {'id': '188', 'type': 'return_statement', 'children': ['189']}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'mol'}
|
MoleculeContainer to RDKit molecule object converter
|
def deprecate(
message: str, category: Any = DeprecationWarning, stacklevel: int = 0
) -> Callable[[F], F]:
def decorator(func: F) -> F:
if not __debug__:
return func
@functools.wraps(func)
def wrapper(*args, **kargs):
warnings.warn(message, category, stacklevel=stacklevel + 2)
return func(*args, **kargs)
return cast(F, wrapper)
return decorator
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '18', '27']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'deprecate'}; {'id': '3', 'type': 'parameters', 'children': ['4', '8', '13']}; {'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '6', 'type': 'type', 'children': ['7']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '8', 'type': 'typed_default_parameter', 'children': ['9', '10', '12']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'category'}; {'id': '10', 'type': 'type', 'children': ['11']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'Any'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'DeprecationWarning'}; {'id': '13', 'type': 'typed_default_parameter', 'children': ['14', '15', '17']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'stacklevel'}; {'id': '15', 'type': 'type', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '17', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '18', 'type': 'type', 'children': ['19']}; {'id': '19', 'type': 'generic_type', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'Callable'}; {'id': '21', 'type': 'type_parameter', 'children': ['22', '25']}; {'id': '22', 'type': 'type', 'children': ['23']}; {'id': '23', 'type': 'list', 'children': ['24'], 'value': '[F]'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'F'}; {'id': '25', 'type': 'type', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'F'}; {'id': '27', 'type': 'block', 'children': ['28', '87']}; {'id': '28', 'type': 'function_definition', 'children': ['29', '30', '35', '37']}; {'id': '29', 'type': 'function_name', 'children': [], 'value': 'decorator'}; {'id': '30', 'type': 'parameters', 'children': ['31']}; {'id': '31', 'type': 'typed_parameter', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '33', 'type': 'type', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'F'}; {'id': '35', 'type': 'type', 'children': ['36']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'F'}; {'id': '37', 'type': 'block', 'children': ['38', '44', '81']}; {'id': '38', 'type': 'if_statement', 'children': ['39', '41']}; {'id': '39', 'type': 'not_operator', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': '__debug__'}; {'id': '41', 'type': 'block', 'children': ['42']}; {'id': '42', 'type': 'return_statement', 'children': ['43']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '44', 'type': 'decorated_definition', 'children': ['45', '52']}; {'id': '45', 'type': 'decorator', 'children': ['46']}; {'id': '46', 'type': 'call', 'children': ['47', '50']}; {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'functools'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'wraps'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '52', 'type': 'function_definition', 'children': ['53', '54', '59']}; {'id': '53', 'type': 'function_name', 'children': [], 'value': 'wrapper'}; {'id': '54', 'type': 'parameters', 'children': ['55', '57']}; {'id': '55', 'type': 'list_splat_pattern', 'children': ['56']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '57', 'type': 'dictionary_splat_pattern', 'children': ['58']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'kargs'}; {'id': '59', 'type': 'block', 'children': ['60', '73']}; {'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': 'warnings'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'warn'}; {'id': '65', 'type': 'argument_list', 'children': ['66', '67', '68']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'category'}; {'id': '68', 'type': 'keyword_argument', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'stacklevel'}; {'id': '70', 'type': 'binary_operator', 'children': ['71', '72'], 'value': '+'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'stacklevel'}; {'id': '72', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '73', 'type': 'return_statement', 'children': ['74']}; {'id': '74', 'type': 'call', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '76', 'type': 'argument_list', 'children': ['77', '79']}; {'id': '77', 'type': 'list_splat', 'children': ['78']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '79', 'type': 'dictionary_splat', 'children': ['80']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'kargs'}; {'id': '81', 'type': 'return_statement', 'children': ['82']}; {'id': '82', 'type': 'call', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'cast'}; {'id': '84', 'type': 'argument_list', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'F'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'wrapper'}; {'id': '87', 'type': 'return_statement', 'children': ['88']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'decorator'}
|
Return a decorator which adds a warning to functions.
|
def do_api_calls_update_cache(self):
zones = self.parse_env_zones()
data = self.group_instances(zones)
self.cache.write_to_cache(data)
self.inventory = data
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'do_api_calls_update_cache'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '14', '23', '32']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'zones'}; {'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': 'parse_env_zones'}; {'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': 'data'}; {'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': 'group_instances'}; {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'zones'}; {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'call', 'children': ['25', '30']}; {'id': '25', 'type': 'attribute', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'cache'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'write_to_cache'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'data'}; {'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': 'self'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'inventory'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'data'}
|
Do API calls and save data in cache.
|
def _calc_distortion(self):
m = self._X.shape[0]
self.distortion = 1/m * sum(
linalg.norm(self._X[i, :] - self.centroids[self.clusters[i]])**2 for i in range(m)
)
return self.distortion
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_calc_distortion'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '16', '58']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '9', 'type': 'subscript', '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': '_X'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '15', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}; {'id': '17', 'type': 'assignment', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'distortion'}; {'id': '21', 'type': 'binary_operator', 'children': ['22', '25'], 'value': '*'}; {'id': '22', 'type': 'binary_operator', 'children': ['23', '24'], 'value': '/'}; {'id': '23', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'sum'}; {'id': '27', 'type': 'generator_expression', 'children': ['28', '52']}; {'id': '28', 'type': 'binary_operator', 'children': ['29', '51'], 'value': '**'}; {'id': '29', 'type': 'call', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'linalg'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'norm'}; {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'binary_operator', 'children': ['35', '42'], 'value': '-'}; {'id': '35', 'type': 'subscript', 'children': ['36', '39', '40']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': '_X'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '40', 'type': 'slice', 'children': ['41']}; {'id': '41', 'type': 'colon', 'children': []}; {'id': '42', 'type': 'subscript', 'children': ['43', '46']}; {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'centroids'}; {'id': '46', 'type': 'subscript', 'children': ['47', '50']}; {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'clusters'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '51', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '52', 'type': 'for_in_clause', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '54', 'type': 'call', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '58', 'type': 'return_statement', 'children': ['59']}; {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'distortion'}
|
Calculates the distortion value of the current clusters
|
def acquire_node(self, node):
try:
return node.set(self.resource, self.lock_key, nx=True, px=self.ttl)
except (redis.exceptions.ConnectionError, redis.exceptions.TimeoutError):
return False
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'acquire_node'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '6', 'type': 'block', 'children': ['7']}; {'id': '7', 'type': 'try_statement', 'children': ['8', '29']}; {'id': '8', 'type': 'block', 'children': ['9']}; {'id': '9', 'type': 'return_statement', 'children': ['10']}; {'id': '10', 'type': 'call', 'children': ['11', '14']}; {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '14', 'type': 'argument_list', 'children': ['15', '18', '21', '24']}; {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'resource'}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'lock_key'}; {'id': '21', 'type': 'keyword_argument', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'nx'}; {'id': '23', 'type': 'True', 'children': []}; {'id': '24', 'type': 'keyword_argument', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'px'}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'ttl'}; {'id': '29', 'type': 'except_clause', 'children': ['30', '41']}; {'id': '30', 'type': 'tuple', 'children': ['31', '36']}; {'id': '31', 'type': 'attribute', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'redis'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'exceptions'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'ConnectionError'}; {'id': '36', 'type': 'attribute', 'children': ['37', '40']}; {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'redis'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'exceptions'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'TimeoutError'}; {'id': '41', 'type': 'block', 'children': ['42']}; {'id': '42', 'type': 'return_statement', 'children': ['43']}; {'id': '43', 'type': 'False', 'children': []}
|
acquire a single redis node
|
def _cast_number(value):
"Convert numbers as string to an int or float"
m = FLOAT_REGEX.search(value)
if m is not None:
return float(value)
return int(value)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_cast_number'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '5', 'type': 'block', 'children': ['6', '8', '17', '27']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'string', 'children': [], 'value': '"Convert numbers as string to an int or float"'}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'FLOAT_REGEX'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'search'}; {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '17', 'type': 'if_statement', 'children': ['18', '21']}; {'id': '18', 'type': 'comparison_operator', 'children': ['19', '20'], 'value': 'is not'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '20', 'type': 'None', 'children': []}; {'id': '21', 'type': 'block', 'children': ['22']}; {'id': '22', 'type': 'return_statement', 'children': ['23']}; {'id': '23', 'type': 'call', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '27', 'type': 'return_statement', 'children': ['28']}; {'id': '28', 'type': 'call', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'value'}
|
Convert numbers as string to an int or float
|
def stream(self, request, counter=0):
if self._children:
for child in self._children:
if isinstance(child, String):
yield from child.stream(request, counter+1)
else:
yield child
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'stream'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'counter'}; {'id': '8', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '9', 'type': 'block', 'children': ['10']}; {'id': '10', 'type': 'if_statement', 'children': ['11', '14']}; {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': '_children'}; {'id': '14', 'type': 'block', 'children': ['15']}; {'id': '15', 'type': 'for_statement', 'children': ['16', '17', '20']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': '_children'}; {'id': '20', 'type': 'block', 'children': ['21']}; {'id': '21', 'type': 'if_statement', 'children': ['22', '27', '39']}; {'id': '22', 'type': 'call', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '24', 'type': 'argument_list', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'String'}; {'id': '27', 'type': 'block', 'children': ['28']}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}; {'id': '29', 'type': 'yield', 'children': ['30']}; {'id': '30', 'type': 'call', 'children': ['31', '34']}; {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'stream'}; {'id': '34', 'type': 'argument_list', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '36', 'type': 'binary_operator', 'children': ['37', '38'], 'value': '+'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'counter'}; {'id': '38', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '39', 'type': 'else_clause', 'children': ['40']}; {'id': '40', 'type': 'block', 'children': ['41']}; {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'yield', 'children': ['43']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'child'}
|
Returns an iterable over strings.
|
def _build_line(colwidths, colaligns, linefmt):
"Return a string which represents a horizontal line."
if not linefmt:
return None
if hasattr(linefmt, "__call__"):
return linefmt(colwidths, colaligns)
else:
begin, fill, sep, end = linefmt
cells = [fill*w for w in colwidths]
return _build_simple_row(cells, (begin, sep, end))
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_build_line'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'colwidths'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'colaligns'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'linefmt'}; {'id': '7', 'type': 'block', 'children': ['8', '10', '16']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'string', 'children': [], 'value': '"Return a string which represents a horizontal line."'}; {'id': '10', 'type': 'if_statement', 'children': ['11', '13']}; {'id': '11', 'type': 'not_operator', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'linefmt'}; {'id': '13', 'type': 'block', 'children': ['14']}; {'id': '14', 'type': 'return_statement', 'children': ['15']}; {'id': '15', 'type': 'None', 'children': []}; {'id': '16', 'type': 'if_statement', 'children': ['17', '22', '29']}; {'id': '17', 'type': 'call', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'hasattr'}; {'id': '19', 'type': 'argument_list', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'linefmt'}; {'id': '21', 'type': 'string', 'children': [], 'value': '"__call__"'}; {'id': '22', 'type': 'block', 'children': ['23']}; {'id': '23', 'type': 'return_statement', 'children': ['24']}; {'id': '24', 'type': 'call', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'linefmt'}; {'id': '26', 'type': 'argument_list', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'colwidths'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'colaligns'}; {'id': '29', 'type': 'else_clause', 'children': ['30']}; {'id': '30', 'type': 'block', 'children': ['31', '39', '49']}; {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '38']}; {'id': '33', 'type': 'pattern_list', 'children': ['34', '35', '36', '37']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'begin'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'fill'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'sep'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'linefmt'}; {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'cells'}; {'id': '42', 'type': 'list_comprehension', 'children': ['43', '46']}; {'id': '43', 'type': 'binary_operator', 'children': ['44', '45'], 'value': '*'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'fill'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'w'}; {'id': '46', 'type': 'for_in_clause', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'w'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'colwidths'}; {'id': '49', 'type': 'return_statement', 'children': ['50']}; {'id': '50', 'type': 'call', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': '_build_simple_row'}; {'id': '52', 'type': 'argument_list', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'cells'}; {'id': '54', 'type': 'tuple', 'children': ['55', '56', '57']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'begin'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'sep'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'end'}
|
Return a string which represents a horizontal line.
|
def crawler(site, uri=None):
config = load_site_config(site)
model = _get_model('crawl', config, uri)
visited_set, visited_uri_set, consume_set, crawl_set = get_site_sets(
site, config
)
if not visited_set.has(model.hash):
visited_set.add(model.hash)
visited_uri_set.add(model.uri)
if (
model.is_consume_page
and not consume_set.has(model.hash)
):
consume_set.add(model.hash)
consume_q.enqueue(
consumer,
site,
model.uri
)
else:
for crawl_uri in model.uris_to_crawl:
if (
not visited_uri_set.has(crawl_uri)
and not crawl_set.has(crawl_uri)
):
crawl_set.add(crawl_uri)
crawl_q.enqueue(
crawler,
site,
crawl_uri
)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'crawler'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'site'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'uri'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '16', '25', '37']}; {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '12', 'type': 'call', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'load_site_config'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'site'}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}; {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': '_get_model'}; {'id': '21', 'type': 'argument_list', 'children': ['22', '23', '24']}; {'id': '22', 'type': 'string', 'children': [], 'value': "'crawl'"}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'uri'}; {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '32']}; {'id': '27', 'type': 'pattern_list', 'children': ['28', '29', '30', '31']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'visited_set'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'visited_uri_set'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'consume_set'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'crawl_set'}; {'id': '32', 'type': 'call', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'get_site_sets'}; {'id': '34', 'type': 'argument_list', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'site'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '37', 'type': 'if_statement', 'children': ['38', '47']}; {'id': '38', 'type': 'not_operator', 'children': ['39']}; {'id': '39', 'type': 'call', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'visited_set'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'has'}; {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'hash'}; {'id': '47', 'type': 'block', 'children': ['48', '57', '66']}; {'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': 'visited_set'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'hash'}; {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'call', 'children': ['59', '62']}; {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'visited_uri_set'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}; {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'uri'}; {'id': '66', 'type': 'if_statement', 'children': ['67', '81', '102']}; {'id': '67', 'type': '()', 'children': ['68']}; {'id': '68', 'type': 'boolean_operator', 'children': ['69', '72'], 'value': 'and'}; {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'is_consume_page'}; {'id': '72', 'type': 'not_operator', 'children': ['73']}; {'id': '73', 'type': 'call', 'children': ['74', '77']}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'consume_set'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'has'}; {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'hash'}; {'id': '81', 'type': 'block', 'children': ['82', '91']}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}; {'id': '83', 'type': 'call', 'children': ['84', '87']}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'consume_set'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '87', 'type': 'argument_list', 'children': ['88']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'hash'}; {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'call', 'children': ['93', '96']}; {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'consume_q'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'enqueue'}; {'id': '96', 'type': 'argument_list', 'children': ['97', '98', '99']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'consumer'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'site'}; {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'uri'}; {'id': '102', 'type': 'else_clause', 'children': ['103']}; {'id': '103', 'type': 'block', 'children': ['104']}; {'id': '104', 'type': 'for_statement', 'children': ['105', '106', '109']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'crawl_uri'}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'uris_to_crawl'}; {'id': '109', 'type': 'block', 'children': ['110']}; {'id': '110', 'type': 'if_statement', 'children': ['111', '127']}; {'id': '111', 'type': '()', 'children': ['112']}; {'id': '112', 'type': 'boolean_operator', 'children': ['113', '120'], 'value': 'and'}; {'id': '113', 'type': 'not_operator', 'children': ['114']}; {'id': '114', 'type': 'call', 'children': ['115', '118']}; {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'visited_uri_set'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'has'}; {'id': '118', 'type': 'argument_list', 'children': ['119']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'crawl_uri'}; {'id': '120', 'type': 'not_operator', 'children': ['121']}; {'id': '121', 'type': 'call', 'children': ['122', '125']}; {'id': '122', 'type': 'attribute', 'children': ['123', '124']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'crawl_set'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'has'}; {'id': '125', 'type': 'argument_list', 'children': ['126']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'crawl_uri'}; {'id': '127', 'type': 'block', 'children': ['128', '135']}; {'id': '128', 'type': 'expression_statement', 'children': ['129']}; {'id': '129', 'type': 'call', 'children': ['130', '133']}; {'id': '130', 'type': 'attribute', 'children': ['131', '132']}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'crawl_set'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '133', 'type': 'argument_list', 'children': ['134']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'crawl_uri'}; {'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': 'crawl_q'}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'enqueue'}; {'id': '140', 'type': 'argument_list', 'children': ['141', '142', '143']}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'crawler'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'site'}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'crawl_uri'}
|
Crawl URI using site config.
|
def iterations(self, parameter):
return numpy.arange(0, self.last_iteration(parameter), self.thinned_by)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'iterations'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'parameter'}; {'id': '6', 'type': 'block', 'children': ['7']}; {'id': '7', 'type': 'return_statement', 'children': ['8']}; {'id': '8', 'type': 'call', 'children': ['9', '12']}; {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'numpy'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'arange'}; {'id': '12', 'type': 'argument_list', 'children': ['13', '14', '20']}; {'id': '13', 'type': 'integer', 'children': [], 'value': '0'}; {'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': 'last_iteration'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'parameter'}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'thinned_by'}
|
Returns the iteration each sample occurred at.
|
def external_answer(self, *sequences):
if not getattr(self, 'external', False):
return
if hasattr(self, 'test_func') and self.test_func is not self._ident:
return
libs = libraries.get_libs(self.__class__.__name__)
for lib in libs:
if not lib.check_conditions(self, *sequences):
continue
if not lib.get_function():
continue
prepared_sequences = lib.prepare(*sequences)
try:
return lib.func(*prepared_sequences)
except Exception:
pass
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'external_answer'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'list_splat_pattern', 'children': ['6']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'sequences'}; {'id': '7', 'type': 'block', 'children': ['8', '18', '34', '47']}; {'id': '8', 'type': 'if_statement', 'children': ['9', '16']}; {'id': '9', 'type': 'not_operator', 'children': ['10']}; {'id': '10', 'type': 'call', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '12', 'type': 'argument_list', 'children': ['13', '14', '15']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '14', 'type': 'string', 'children': [], 'value': "'external'"}; {'id': '15', 'type': 'False', 'children': []}; {'id': '16', 'type': 'block', 'children': ['17']}; {'id': '17', 'type': 'return_statement', 'children': []}; {'id': '18', 'type': 'if_statement', 'children': ['19', '32']}; {'id': '19', 'type': 'boolean_operator', 'children': ['20', '25'], 'value': 'and'}; {'id': '20', 'type': 'call', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'hasattr'}; {'id': '22', 'type': 'argument_list', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '24', 'type': 'string', 'children': [], 'value': "'test_func'"}; {'id': '25', 'type': 'comparison_operator', 'children': ['26', '29'], 'value': 'is not'}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'test_func'}; {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': '_ident'}; {'id': '32', 'type': 'block', 'children': ['33']}; {'id': '33', 'type': 'return_statement', 'children': []}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}; {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'libs'}; {'id': '37', 'type': 'call', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'libraries'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'get_libs'}; {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'attribute', 'children': ['43', '46']}; {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': '__class__'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': '__name__'}; {'id': '47', 'type': 'for_statement', 'children': ['48', '49', '50']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'lib'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'libs'}; {'id': '50', 'type': 'block', 'children': ['51', '63', '72', '82']}; {'id': '51', 'type': 'if_statement', 'children': ['52', '61']}; {'id': '52', 'type': 'not_operator', 'children': ['53']}; {'id': '53', 'type': 'call', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'lib'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'check_conditions'}; {'id': '57', 'type': 'argument_list', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '59', 'type': 'list_splat', 'children': ['60']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'sequences'}; {'id': '61', 'type': 'block', 'children': ['62']}; {'id': '62', 'type': 'continue_statement', 'children': []}; {'id': '63', 'type': 'if_statement', 'children': ['64', '70']}; {'id': '64', 'type': 'not_operator', 'children': ['65']}; {'id': '65', 'type': 'call', 'children': ['66', '69']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'lib'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'get_function'}; {'id': '69', 'type': 'argument_list', 'children': []}; {'id': '70', 'type': 'block', 'children': ['71']}; {'id': '71', 'type': 'continue_statement', 'children': []}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}; {'id': '73', 'type': 'assignment', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'prepared_sequences'}; {'id': '75', 'type': 'call', 'children': ['76', '79']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'lib'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'prepare'}; {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'list_splat', 'children': ['81']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'sequences'}; {'id': '82', 'type': 'try_statement', 'children': ['83', '92']}; {'id': '83', 'type': 'block', 'children': ['84']}; {'id': '84', 'type': 'return_statement', 'children': ['85']}; {'id': '85', 'type': 'call', 'children': ['86', '89']}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'lib'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'list_splat', 'children': ['91']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'prepared_sequences'}; {'id': '92', 'type': 'except_clause', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '94', 'type': 'block', 'children': ['95']}; {'id': '95', 'type': 'pass_statement', 'children': []}
|
Try to get answer from known external libraries.
|
def scene_command(self, command):
self.logger.info("scene_command: Group %s Command %s", self.group_id, command)
command_url = self.hub.hub_url + '/0?' + command + self.group_id + "=I=0"
return self.hub.post_direct_command(command_url)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'scene_command'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'command'}; {'id': '6', 'type': 'block', 'children': ['7', '20', '38']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'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': 'self'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '14', 'type': 'argument_list', 'children': ['15', '16', '19']}; {'id': '15', 'type': 'string', 'children': [], 'value': '"scene_command: Group %s Command %s"'}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'group_id'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'command'}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}; {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'command_url'}; {'id': '23', 'type': 'binary_operator', 'children': ['24', '37'], 'value': '+'}; {'id': '24', 'type': 'binary_operator', 'children': ['25', '34'], 'value': '+'}; {'id': '25', 'type': 'binary_operator', 'children': ['26', '33'], 'value': '+'}; {'id': '26', 'type': 'binary_operator', 'children': ['27', '32'], 'value': '+'}; {'id': '27', 'type': 'attribute', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'hub'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'hub_url'}; {'id': '32', 'type': 'string', 'children': [], 'value': "'/0?'"}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'command'}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'group_id'}; {'id': '37', 'type': 'string', 'children': [], 'value': '"=I=0"'}; {'id': '38', 'type': 'return_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': 'hub'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'post_direct_command'}; {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'command_url'}
|
Wrapper to send posted scene command and get response
|
def r_date_num(obj, multiple=False):
if isinstance(obj, (list, tuple)):
it = iter
else:
it = LinesIterator
if multiple:
datasets = {}
for line in it(obj):
label = line[2]
if label not in datasets:
datasets[label] = Dataset([Dataset.DATE, Dataset.FLOAT])
datasets[label].name = label
datasets[label].parse_elements(line[0:2])
return datasets.values()
dataset = Dataset([Dataset.DATE, Dataset.FLOAT])
return dataset.load(it(obj))
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'r_date_num'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'multiple'}; {'id': '7', 'type': 'False', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '28', '96', '109']}; {'id': '9', 'type': 'if_statement', 'children': ['10', '17', '22']}; {'id': '10', 'type': 'call', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '12', 'type': 'argument_list', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '14', 'type': 'tuple', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'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': 'it'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'iter'}; {'id': '22', 'type': 'else_clause', 'children': ['23']}; {'id': '23', 'type': 'block', 'children': ['24']}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}; {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'it'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'LinesIterator'}; {'id': '28', 'type': 'if_statement', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'multiple'}; {'id': '30', 'type': 'block', 'children': ['31', '35', '90']}; {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'datasets'}; {'id': '34', 'type': 'dictionary', 'children': []}; {'id': '35', 'type': 'for_statement', 'children': ['36', '37', '41']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'it'}; {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '41', 'type': 'block', 'children': ['42', '48', '76']}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}; {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '45', 'type': 'subscript', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '47', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '48', 'type': 'if_statement', 'children': ['49', '52']}; {'id': '49', 'type': 'comparison_operator', 'children': ['50', '51'], 'value': 'not in'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'datasets'}; {'id': '52', 'type': 'block', 'children': ['53', '68']}; {'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': 'datasets'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '58', 'type': 'call', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'Dataset'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}; {'id': '61', 'type': 'list', 'children': ['62', '65'], 'value': '[Dataset.DATE, Dataset.FLOAT]'}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'Dataset'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'DATE'}; {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'Dataset'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'FLOAT'}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}; {'id': '69', 'type': 'assignment', 'children': ['70', '75']}; {'id': '70', 'type': 'attribute', 'children': ['71', '74']}; {'id': '71', 'type': 'subscript', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'datasets'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}; {'id': '77', 'type': 'call', 'children': ['78', '83']}; {'id': '78', 'type': 'attribute', 'children': ['79', '82']}; {'id': '79', 'type': 'subscript', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'datasets'}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'parse_elements'}; {'id': '83', 'type': 'argument_list', 'children': ['84']}; {'id': '84', 'type': 'subscript', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '86', 'type': 'slice', 'children': ['87', '88', '89']}; {'id': '87', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '88', 'type': 'colon', 'children': []}; {'id': '89', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '90', 'type': 'return_statement', 'children': ['91']}; {'id': '91', 'type': 'call', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'datasets'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '95', 'type': 'argument_list', 'children': []}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}; {'id': '97', 'type': 'assignment', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'dataset'}; {'id': '99', 'type': 'call', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'Dataset'}; {'id': '101', 'type': 'argument_list', 'children': ['102']}; {'id': '102', 'type': 'list', 'children': ['103', '106'], 'value': '[Dataset.DATE, Dataset.FLOAT]'}; {'id': '103', 'type': 'attribute', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'Dataset'}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'DATE'}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'Dataset'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'FLOAT'}; {'id': '109', 'type': 'return_statement', 'children': ['110']}; {'id': '110', 'type': 'call', 'children': ['111', '114']}; {'id': '111', 'type': 'attribute', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'dataset'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'load'}; {'id': '114', 'type': 'argument_list', 'children': ['115']}; {'id': '115', 'type': 'call', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'it'}; {'id': '117', 'type': 'argument_list', 'children': ['118']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'obj'}
|
Read date-value table.
|
def resize(self, height, width, **kwargs):
self.client.exec_resize(self.exec_id, height=height, width=width)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'resize'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'height'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'width'}; {'id': '7', 'type': 'dictionary_splat_pattern', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '9', 'type': 'block', 'children': ['10']}; {'id': '10', 'type': 'expression_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': 'client'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'exec_resize'}; {'id': '17', 'type': 'argument_list', 'children': ['18', '21', '24']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'exec_id'}; {'id': '21', 'type': 'keyword_argument', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'height'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'height'}; {'id': '24', 'type': 'keyword_argument', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'width'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'width'}
|
resize pty of an execed process
|
def removeSubEditor(self, subEditor):
if subEditor is self.focusProxy():
self.setFocusProxy(None)
subEditor.removeEventFilter(self)
self._subEditors.remove(subEditor)
self.hBoxLayout.removeWidget(subEditor)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'removeSubEditor'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'subEditor'}; {'id': '6', 'type': 'block', 'children': ['7', '23', '30', '39']}; {'id': '7', 'type': 'if_statement', 'children': ['8', '15']}; {'id': '8', 'type': 'comparison_operator', 'children': ['9', '10'], 'value': 'is'}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'subEditor'}; {'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': 'focusProxy'}; {'id': '14', 'type': 'argument_list', 'children': []}; {'id': '15', 'type': 'block', 'children': ['16']}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}; {'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': 'setFocusProxy'}; {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'None', 'children': []}; {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'call', 'children': ['25', '28']}; {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'subEditor'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'removeEventFilter'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}; {'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': '_subEditors'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'remove'}; {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'subEditor'}; {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'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': 'self'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'hBoxLayout'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'removeWidget'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'subEditor'}
|
Removes the subEditor from the layout and removes the event filter.
|
async def open(
self,
cmd: List[str],
input_source: Optional[str],
output: Optional[str] = "-",
extra_cmd: Optional[str] = None,
stdout_pipe: bool = True,
stderr_pipe: bool = False,
) -> bool:
stdout = subprocess.PIPE if stdout_pipe else subprocess.DEVNULL
stderr = subprocess.PIPE if stderr_pipe else subprocess.DEVNULL
if self.is_running:
_LOGGER.warning("FFmpeg is already running!")
return True
self._generate_ffmpeg_cmd(cmd, input_source, output, extra_cmd)
_LOGGER.debug("Start FFmpeg with %s", str(self._argv))
try:
proc_func = functools.partial(
subprocess.Popen,
self._argv,
bufsize=0,
stdin=subprocess.PIPE,
stdout=stdout,
stderr=stderr,
)
self._proc = await self._loop.run_in_executor(None, proc_func)
except Exception as err:
_LOGGER.exception("FFmpeg fails %s", err)
self._clear()
return False
return self._proc is not None
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '49', '51']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'open'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '13', '21', '30', '39', '44']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'typed_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '7', 'type': 'type', 'children': ['8']}; {'id': '8', 'type': 'generic_type', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'List'}; {'id': '10', 'type': 'type_parameter', 'children': ['11']}; {'id': '11', 'type': 'type', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '13', 'type': 'typed_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'input_source'}; {'id': '15', 'type': 'type', 'children': ['16']}; {'id': '16', 'type': 'generic_type', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'Optional'}; {'id': '18', 'type': 'type_parameter', 'children': ['19']}; {'id': '19', 'type': 'type', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '21', 'type': 'typed_default_parameter', 'children': ['22', '23', '29']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'output'}; {'id': '23', 'type': 'type', 'children': ['24']}; {'id': '24', 'type': 'generic_type', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'Optional'}; {'id': '26', 'type': 'type_parameter', 'children': ['27']}; {'id': '27', 'type': 'type', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '29', 'type': 'string', 'children': [], 'value': '"-"'}; {'id': '30', 'type': 'typed_default_parameter', 'children': ['31', '32', '38']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'extra_cmd'}; {'id': '32', 'type': 'type', 'children': ['33']}; {'id': '33', 'type': 'generic_type', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'Optional'}; {'id': '35', 'type': 'type_parameter', 'children': ['36']}; {'id': '36', 'type': 'type', 'children': ['37']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '38', 'type': 'None', 'children': []}; {'id': '39', 'type': 'typed_default_parameter', 'children': ['40', '41', '43']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'stdout_pipe'}; {'id': '41', 'type': 'type', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'bool'}; {'id': '43', 'type': 'True', 'children': []}; {'id': '44', 'type': 'typed_default_parameter', 'children': ['45', '46', '48']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'stderr_pipe'}; {'id': '46', 'type': 'type', 'children': ['47']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'bool'}; {'id': '48', 'type': 'False', 'children': []}; {'id': '49', 'type': 'type', 'children': ['50']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'bool'}; {'id': '51', 'type': 'block', 'children': ['52', '63', '74', '88', '98', '111', '178']}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}; {'id': '53', 'type': 'assignment', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'stdout'}; {'id': '55', 'type': 'conditional_expression', 'children': ['56', '59', '60'], 'value': 'if'}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'subprocess'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'PIPE'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'stdout_pipe'}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'subprocess'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'DEVNULL'}; {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'stderr'}; {'id': '66', 'type': 'conditional_expression', 'children': ['67', '70', '71'], 'value': 'if'}; {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'subprocess'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'PIPE'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'stderr_pipe'}; {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'subprocess'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'DEVNULL'}; {'id': '74', 'type': 'if_statement', 'children': ['75', '78']}; {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'is_running'}; {'id': '78', 'type': 'block', 'children': ['79', '86']}; {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'call', 'children': ['81', '84']}; {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': '_LOGGER'}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '84', 'type': 'argument_list', 'children': ['85']}; {'id': '85', 'type': 'string', 'children': [], 'value': '"FFmpeg is already running!"'}; {'id': '86', 'type': 'return_statement', 'children': ['87']}; {'id': '87', 'type': 'True', 'children': []}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}; {'id': '89', 'type': 'call', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': '_generate_ffmpeg_cmd'}; {'id': '93', 'type': 'argument_list', 'children': ['94', '95', '96', '97']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'input_source'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'output'}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'extra_cmd'}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}; {'id': '99', 'type': 'call', 'children': ['100', '103']}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': '_LOGGER'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '103', 'type': 'argument_list', 'children': ['104', '105']}; {'id': '104', 'type': 'string', 'children': [], 'value': '"Start FFmpeg with %s"'}; {'id': '105', 'type': 'call', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '107', 'type': 'argument_list', 'children': ['108']}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': '_argv'}; {'id': '111', 'type': 'try_statement', 'children': ['112', '156']}; {'id': '112', 'type': 'block', 'children': ['113', '141']}; {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'assignment', 'children': ['115', '116']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'proc_func'}; {'id': '116', 'type': 'call', 'children': ['117', '120']}; {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'functools'}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'partial'}; {'id': '120', 'type': 'argument_list', 'children': ['121', '124', '127', '130', '135', '138']}; {'id': '121', 'type': 'attribute', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'subprocess'}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'Popen'}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': '_argv'}; {'id': '127', 'type': 'keyword_argument', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'bufsize'}; {'id': '129', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '130', 'type': 'keyword_argument', 'children': ['131', '132']}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'stdin'}; {'id': '132', 'type': 'attribute', 'children': ['133', '134']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'subprocess'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'PIPE'}; {'id': '135', 'type': 'keyword_argument', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'stdout'}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'stdout'}; {'id': '138', 'type': 'keyword_argument', 'children': ['139', '140']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'stderr'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'stderr'}; {'id': '141', 'type': 'expression_statement', 'children': ['142']}; {'id': '142', 'type': 'assignment', 'children': ['143', '146']}; {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '145', 'type': 'identifier', 'children': [], 'value': '_proc'}; {'id': '146', 'type': 'await', 'children': ['147']}; {'id': '147', 'type': 'call', 'children': ['148', '153']}; {'id': '148', 'type': 'attribute', 'children': ['149', '152']}; {'id': '149', 'type': 'attribute', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '151', 'type': 'identifier', 'children': [], 'value': '_loop'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'run_in_executor'}; {'id': '153', 'type': 'argument_list', 'children': ['154', '155']}; {'id': '154', 'type': 'None', 'children': []}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'proc_func'}; {'id': '156', 'type': 'except_clause', 'children': ['157', '161']}; {'id': '157', 'type': 'as_pattern', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '159', 'type': 'as_pattern_target', 'children': ['160']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'err'}; {'id': '161', 'type': 'block', 'children': ['162', '170', '176']}; {'id': '162', 'type': 'expression_statement', 'children': ['163']}; {'id': '163', 'type': 'call', 'children': ['164', '167']}; {'id': '164', 'type': 'attribute', 'children': ['165', '166']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': '_LOGGER'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'exception'}; {'id': '167', 'type': 'argument_list', 'children': ['168', '169']}; {'id': '168', 'type': 'string', 'children': [], 'value': '"FFmpeg fails %s"'}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'err'}; {'id': '170', 'type': 'expression_statement', 'children': ['171']}; {'id': '171', 'type': 'call', 'children': ['172', '175']}; {'id': '172', 'type': 'attribute', 'children': ['173', '174']}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': '_clear'}; {'id': '175', 'type': 'argument_list', 'children': []}; {'id': '176', 'type': 'return_statement', 'children': ['177']}; {'id': '177', 'type': 'False', 'children': []}; {'id': '178', 'type': 'return_statement', 'children': ['179']}; {'id': '179', 'type': 'comparison_operator', 'children': ['180', '183'], 'value': 'is not'}; {'id': '180', 'type': 'attribute', 'children': ['181', '182']}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': '_proc'}; {'id': '183', 'type': 'None', 'children': []}
|
Start a ffmpeg instance and pipe output.
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.