code
stringlengths 51
2.34k
| sequence
stringlengths 1.16k
13.1k
| docstring
stringlengths 11
171
|
|---|---|---|
def shell(ctx):
shell = code.InteractiveConsole({"engineer": getattr(ctx.parent, "widget", None)})
shell.interact("\n".join([
"Engineer connected to %s" % ctx.parent.params["host"],
"Dispatch available through the 'engineer' object"
]))
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'shell'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'ctx'}; {'id': '5', 'type': 'block', 'children': ['6', '25']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'shell'}; {'id': '9', 'type': 'call', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'code'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'InteractiveConsole'}; {'id': '13', 'type': 'argument_list', 'children': ['14']}; {'id': '14', 'type': 'dictionary', 'children': ['15']}; {'id': '15', 'type': 'pair', 'children': ['16', '17']}; {'id': '16', 'type': 'string', 'children': [], 'value': '"engineer"'}; {'id': '17', 'type': 'call', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '19', 'type': 'argument_list', 'children': ['20', '23', '24']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'ctx'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '23', 'type': 'string', 'children': [], 'value': '"widget"'}; {'id': '24', 'type': 'None', 'children': []}; {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'call', 'children': ['27', '30']}; {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'shell'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'interact'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}; {'id': '31', 'type': 'call', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}; {'id': '33', 'type': 'string', 'children': [], 'value': '"\\n"'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'list', 'children': ['37', '46'], 'value': '[\n "Engineer connected to %s" % ctx.parent.params["host"],\n "Dispatch available through the \'engineer\' object"\n ]'}; {'id': '37', 'type': 'binary_operator', 'children': ['38', '39'], 'value': '%'}; {'id': '38', 'type': 'string', 'children': [], 'value': '"Engineer connected to %s"'}; {'id': '39', 'type': 'subscript', 'children': ['40', '45']}; {'id': '40', 'type': 'attribute', 'children': ['41', '44']}; {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'ctx'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '45', 'type': 'string', 'children': [], 'value': '"host"'}; {'id': '46', 'type': 'string', 'children': [], 'value': '"Dispatch available through the \'engineer\' object"'}
|
open an engineer shell
|
def getOverlayFlag(self, ulOverlayHandle, eOverlayFlag):
fn = self.function_table.getOverlayFlag
pbEnabled = openvr_bool()
result = fn(ulOverlayHandle, eOverlayFlag, byref(pbEnabled))
return result, pbEnabled
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'getOverlayFlag'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'ulOverlayHandle'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'eOverlayFlag'}; {'id': '7', 'type': 'block', 'children': ['8', '16', '22', '34']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'fn'}; {'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': 'function_table'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'getOverlayFlag'}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}; {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'pbEnabled'}; {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'openvr_bool'}; {'id': '21', 'type': 'argument_list', 'children': []}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}; {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'fn'}; {'id': '27', 'type': 'argument_list', 'children': ['28', '29', '30']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'ulOverlayHandle'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'eOverlayFlag'}; {'id': '30', 'type': 'call', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'byref'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'pbEnabled'}; {'id': '34', 'type': 'return_statement', 'children': ['35']}; {'id': '35', 'type': 'expression_list', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'pbEnabled'}
|
Sets flag setting for a given overlay
|
def draw(self):
if self.state > 0:
self.renderer.draw_background(self.surface, self.layout.position, self.layout.size)
for row in self.layout.rows:
for key in row.keys:
self.renderer.draw_key(self.surface, key)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'draw'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '12']}; {'id': '7', 'type': 'comparison_operator', 'children': ['8', '11'], 'value': '>'}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'state'}; {'id': '11', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '12', 'type': 'block', 'children': ['13', '34']}; {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'call', 'children': ['15', '20']}; {'id': '15', 'type': 'attribute', 'children': ['16', '19']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'renderer'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'draw_background'}; {'id': '20', 'type': 'argument_list', 'children': ['21', '24', '29']}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'surface'}; {'id': '24', 'type': 'attribute', 'children': ['25', '28']}; {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'layout'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'position'}; {'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': 'layout'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'size'}; {'id': '34', 'type': 'for_statement', 'children': ['35', '36', '41']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '36', 'type': 'attribute', 'children': ['37', '40']}; {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'layout'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'rows'}; {'id': '41', 'type': 'block', 'children': ['42']}; {'id': '42', 'type': 'for_statement', 'children': ['43', '44', '47']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '47', 'type': 'block', 'children': ['48']}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}; {'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': 'self'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'renderer'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'draw_key'}; {'id': '55', 'type': 'argument_list', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'surface'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'key'}
|
Draw the virtual keyboard into the delegate surface object if enabled.
|
def surviors_are_inconsistent(survivor_mapping: Mapping[BaseEntity, Set[BaseEntity]]) -> Set[BaseEntity]:
victim_mapping = set()
for victim in itt.chain.from_iterable(survivor_mapping.values()):
if victim in survivor_mapping:
victim_mapping.add(victim)
return victim_mapping
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '18', '24']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'surviors_are_inconsistent'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'survivor_mapping'}; {'id': '6', 'type': 'type', 'children': ['7']}; {'id': '7', 'type': 'generic_type', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'Mapping'}; {'id': '9', 'type': 'type_parameter', 'children': ['10', '12']}; {'id': '10', 'type': 'type', 'children': ['11']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'BaseEntity'}; {'id': '12', 'type': 'type', 'children': ['13']}; {'id': '13', 'type': 'generic_type', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'Set'}; {'id': '15', 'type': 'type_parameter', 'children': ['16']}; {'id': '16', 'type': 'type', 'children': ['17']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'BaseEntity'}; {'id': '18', 'type': 'type', 'children': ['19']}; {'id': '19', 'type': 'generic_type', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'Set'}; {'id': '21', 'type': 'type_parameter', 'children': ['22']}; {'id': '22', 'type': 'type', 'children': ['23']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'BaseEntity'}; {'id': '24', 'type': 'block', 'children': ['25', '31', '58']}; {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'victim_mapping'}; {'id': '28', 'type': 'call', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '30', 'type': 'argument_list', 'children': []}; {'id': '31', 'type': 'for_statement', 'children': ['32', '33', '45']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'victim'}; {'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': 'itt'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'chain'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'from_iterable'}; {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'call', 'children': ['41', '44']}; {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'survivor_mapping'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '44', 'type': 'argument_list', 'children': []}; {'id': '45', 'type': 'block', 'children': ['46']}; {'id': '46', 'type': 'if_statement', 'children': ['47', '50']}; {'id': '47', 'type': 'comparison_operator', 'children': ['48', '49'], 'value': 'in'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'victim'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'survivor_mapping'}; {'id': '50', 'type': 'block', 'children': ['51']}; {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'call', 'children': ['53', '56']}; {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'victim_mapping'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'victim'}; {'id': '58', 'type': 'return_statement', 'children': ['59']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'victim_mapping'}
|
Check that there's no transitive shit going on.
|
def const(const):
try:
return getattr(_c, const)
except AttributeError:
raise FSQEnvError(errno.EINVAL, u'No such constant:'\
u' {0}'.format(const))
except TypeError:
raise TypeError(errno.EINVAL, u'const name must be a string or'\
u' unicode object, not:'\
u' {0}'.format(const.__class__.__name__))
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'const'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'const'}; {'id': '5', 'type': 'block', 'children': ['6']}; {'id': '6', 'type': 'try_statement', 'children': ['7', '14', '32']}; {'id': '7', 'type': 'block', 'children': ['8']}; {'id': '8', 'type': 'return_statement', 'children': ['9']}; {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '11', 'type': 'argument_list', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': '_c'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'const'}; {'id': '14', 'type': 'except_clause', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'AttributeError'}; {'id': '16', 'type': 'block', 'children': ['17']}; {'id': '17', 'type': 'raise_statement', 'children': ['18']}; {'id': '18', 'type': 'call', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'FSQEnvError'}; {'id': '20', 'type': 'argument_list', 'children': ['21', '24']}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'errno'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'EINVAL'}; {'id': '24', 'type': 'call', 'children': ['25', '30']}; {'id': '25', 'type': 'attribute', 'children': ['26', '29']}; {'id': '26', 'type': 'concatenated_string', 'children': ['27', '28']}; {'id': '27', 'type': 'string', 'children': [], 'value': "u'No such constant:'"}; {'id': '28', 'type': 'string', 'children': [], 'value': "u' {0}'"}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'const'}; {'id': '32', 'type': 'except_clause', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'TypeError'}; {'id': '34', 'type': 'block', 'children': ['35']}; {'id': '35', 'type': 'raise_statement', 'children': ['36']}; {'id': '36', 'type': 'call', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'TypeError'}; {'id': '38', 'type': 'argument_list', 'children': ['39', '42']}; {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'errno'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'EINVAL'}; {'id': '42', 'type': 'call', 'children': ['43', '49']}; {'id': '43', 'type': 'attribute', 'children': ['44', '48']}; {'id': '44', 'type': 'concatenated_string', 'children': ['45', '46', '47']}; {'id': '45', 'type': 'string', 'children': [], 'value': "u'const name must be a string or'"}; {'id': '46', 'type': 'string', 'children': [], 'value': "u' unicode object, not:'"}; {'id': '47', 'type': 'string', 'children': [], 'value': "u' {0}'"}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'attribute', 'children': ['51', '54']}; {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'const'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': '__class__'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': '__name__'}
|
Convenience wrapper to yield the value of a constant
|
def install_plugin(username, repo):
print("Installing plugin from " + username + "/" + repo)
pip.main(['install', '-U', "git+git://github.com/" +
username + "/" + repo + ".git"])
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'install_plugin'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'username'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'repo'}; {'id': '6', 'type': 'block', 'children': ['7', '18']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'call', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '10', 'type': 'argument_list', 'children': ['11']}; {'id': '11', 'type': 'binary_operator', 'children': ['12', '17'], 'value': '+'}; {'id': '12', 'type': 'binary_operator', 'children': ['13', '16'], 'value': '+'}; {'id': '13', 'type': 'binary_operator', 'children': ['14', '15'], 'value': '+'}; {'id': '14', 'type': 'string', 'children': [], 'value': '"Installing plugin from "'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'username'}; {'id': '16', 'type': 'string', 'children': [], 'value': '"/"'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'repo'}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}; {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'pip'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'main'}; {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'list', 'children': ['25', '26', '27'], 'value': '[\'install\', \'-U\', "git+git://github.com/" +\n username + "/" + repo + ".git"]'}; {'id': '25', 'type': 'string', 'children': [], 'value': "'install'"}; {'id': '26', 'type': 'string', 'children': [], 'value': "'-U'"}; {'id': '27', 'type': 'binary_operator', 'children': ['28', '35'], 'value': '+'}; {'id': '28', 'type': 'binary_operator', 'children': ['29', '34'], 'value': '+'}; {'id': '29', 'type': 'binary_operator', 'children': ['30', '33'], 'value': '+'}; {'id': '30', 'type': 'binary_operator', 'children': ['31', '32'], 'value': '+'}; {'id': '31', 'type': 'string', 'children': [], 'value': '"git+git://github.com/"'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'username'}; {'id': '33', 'type': 'string', 'children': [], 'value': '"/"'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'repo'}; {'id': '35', 'type': 'string', 'children': [], 'value': '".git"'}
|
Installs a Blended plugin from GitHub
|
def _convert_number(self, number):
number = float(number)
return int(number) if number.is_integer() else float(number)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_convert_number'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'number'}; {'id': '6', 'type': 'block', 'children': ['7', '14']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'number'}; {'id': '10', 'type': 'call', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '12', 'type': 'argument_list', 'children': ['13']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'number'}; {'id': '14', 'type': 'return_statement', 'children': ['15']}; {'id': '15', 'type': 'conditional_expression', 'children': ['16', '20', '25'], 'value': 'if'}; {'id': '16', 'type': 'call', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'number'}; {'id': '20', 'type': 'call', 'children': ['21', '24']}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'number'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'is_integer'}; {'id': '24', 'type': 'argument_list', 'children': []}; {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'number'}
|
Converts a number to float or int as appropriate
|
def write(self, s):
for line in re.split(r'\n+', s):
if line != '':
self._logger.log(self._level, line)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'write'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '6', 'type': 'block', 'children': ['7']}; {'id': '7', 'type': 'for_statement', 'children': ['8', '9', '16']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '9', 'type': 'call', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '13', 'type': 'argument_list', 'children': ['14', '15']}; {'id': '14', 'type': 'string', 'children': [], 'value': "r'\\n+'"}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '16', 'type': 'block', 'children': ['17']}; {'id': '17', 'type': 'if_statement', 'children': ['18', '21']}; {'id': '18', 'type': 'comparison_operator', 'children': ['19', '20'], 'value': '!='}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '20', 'type': 'string', 'children': [], 'value': "''"}; {'id': '21', 'type': 'block', 'children': ['22']}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}; {'id': '23', 'type': 'call', 'children': ['24', '29']}; {'id': '24', 'type': 'attribute', 'children': ['25', '28']}; {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': '_logger'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'log'}; {'id': '29', 'type': 'argument_list', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': '_level'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'line'}
|
Write message to logger.
|
def _preloading_env(self):
ctx = self.env.globals
try:
ctx['random_model'] = lambda *a, **kw: None
ctx['random_models'] = lambda *a, **kw: None
yield self.env
finally:
ctx['random_model'] = jinja2.contextfunction(random_model)
ctx['random_models'] = jinja2.contextfunction(random_models)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_preloading_env'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '14']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'ctx'}; {'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': 'env'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'globals'}; {'id': '14', 'type': 'try_statement', 'children': ['15', '45']}; {'id': '15', 'type': 'block', 'children': ['16', '28', '40']}; {'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': 'ctx'}; {'id': '20', 'type': 'string', 'children': [], 'value': "'random_model'"}; {'id': '21', 'type': 'lambda', 'children': ['22', '27']}; {'id': '22', 'type': 'lambda_parameters', 'children': ['23', '25']}; {'id': '23', 'type': 'list_splat_pattern', 'children': ['24']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '25', 'type': 'dictionary_splat_pattern', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'kw'}; {'id': '27', 'type': 'None', 'children': []}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}; {'id': '29', 'type': 'assignment', 'children': ['30', '33']}; {'id': '30', 'type': 'subscript', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'ctx'}; {'id': '32', 'type': 'string', 'children': [], 'value': "'random_models'"}; {'id': '33', 'type': 'lambda', 'children': ['34', '39']}; {'id': '34', 'type': 'lambda_parameters', 'children': ['35', '37']}; {'id': '35', 'type': 'list_splat_pattern', 'children': ['36']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '37', 'type': 'dictionary_splat_pattern', 'children': ['38']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'kw'}; {'id': '39', 'type': 'None', 'children': []}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}; {'id': '41', 'type': 'yield', 'children': ['42']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'env'}; {'id': '45', 'type': 'finally_clause', 'children': ['46']}; {'id': '46', 'type': 'block', 'children': ['47', '58']}; {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'assignment', 'children': ['49', '52']}; {'id': '49', 'type': 'subscript', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'ctx'}; {'id': '51', 'type': 'string', 'children': [], 'value': "'random_model'"}; {'id': '52', 'type': 'call', 'children': ['53', '56']}; {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'jinja2'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'contextfunction'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'random_model'}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}; {'id': '59', 'type': 'assignment', 'children': ['60', '63']}; {'id': '60', 'type': 'subscript', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'ctx'}; {'id': '62', 'type': 'string', 'children': [], 'value': "'random_models'"}; {'id': '63', 'type': 'call', 'children': ['64', '67']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'jinja2'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'contextfunction'}; {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'random_models'}
|
A "stripped" jinja environment.
|
def _calc_footprint(self):
corners = [self.corner(corner) for corner in self.corner_types()]
coords = []
for corner in corners:
shape = corner.get_shape(corner.crs)
coords.append([shape.x, shape.y])
shp = Polygon(coords)
self._footprint = GeoVector(shp, self.crs)
return self._footprint
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_calc_footprint'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '23', '27', '55', '62', '74']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'corners'}; {'id': '9', 'type': 'list_comprehension', 'children': ['10', '16']}; {'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': 'corner'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'corner'}; {'id': '16', 'type': 'for_in_clause', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'corner'}; {'id': '18', 'type': 'call', 'children': ['19', '22']}; {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'corner_types'}; {'id': '22', 'type': 'argument_list', 'children': []}; {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'coords'}; {'id': '26', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '27', 'type': 'for_statement', 'children': ['28', '29', '30']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'corner'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'corners'}; {'id': '30', 'type': 'block', 'children': ['31', '42']}; {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '34', 'type': 'call', 'children': ['35', '38']}; {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'corner'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'get_shape'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}; {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'corner'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'crs'}; {'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': 'coords'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'list', 'children': ['49', '52'], 'value': '[shape.x, shape.y]'}; {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'shp'}; {'id': '58', 'type': 'call', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'Polygon'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'coords'}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}; {'id': '63', 'type': 'assignment', 'children': ['64', '67']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': '_footprint'}; {'id': '67', 'type': 'call', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'GeoVector'}; {'id': '69', 'type': 'argument_list', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'shp'}; {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'crs'}; {'id': '74', 'type': 'return_statement', 'children': ['75']}; {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '77', 'type': 'identifier', 'children': [], 'value': '_footprint'}
|
Return rectangle in world coordinates, as GeoVector.
|
def _get_filepaths(self):
self._printer(str(self.__len__()) + " file paths have been parsed in " + str(self.timer.end))
if self._hash_files:
return pool_hash(self.filepaths)
else:
return self.filepaths
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_filepaths'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '31']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'call', 'children': ['8', '11']}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': '_printer'}; {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'binary_operator', 'children': ['13', '23'], 'value': '+'}; {'id': '13', 'type': 'binary_operator', 'children': ['14', '22'], 'value': '+'}; {'id': '14', 'type': 'call', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'str'}; {'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': 'self'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': '__len__'}; {'id': '21', 'type': 'argument_list', 'children': []}; {'id': '22', 'type': 'string', 'children': [], 'value': '" file paths have been parsed in "'}; {'id': '23', 'type': 'call', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'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': 'timer'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '31', 'type': 'if_statement', 'children': ['32', '35', '43']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': '_hash_files'}; {'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': 'pool_hash'}; {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'filepaths'}; {'id': '43', 'type': 'else_clause', 'children': ['44']}; {'id': '44', 'type': 'block', 'children': ['45']}; {'id': '45', 'type': 'return_statement', 'children': ['46']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'filepaths'}
|
Filters list of file paths to remove non-included, remove excluded files and concatenate full paths.
|
def sha256sum(filename):
sha256 = hashlib.sha256()
mem_view = memoryview(bytearray(128*1024))
with open(filename, 'rb', buffering=0) as stream:
for i in iter(lambda: stream.readinto(mem_view), 0):
sha256.update(mem_view[:i])
return sha256.hexdigest()
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sha256sum'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '5', 'type': 'block', 'children': ['6', '14', '26', '66']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'sha256'}; {'id': '9', 'type': 'call', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'hashlib'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'sha256'}; {'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': 'mem_view'}; {'id': '17', 'type': 'call', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'memoryview'}; {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'call', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'bytearray'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}; {'id': '23', 'type': 'binary_operator', 'children': ['24', '25'], 'value': '*'}; {'id': '24', 'type': 'integer', 'children': [], 'value': '128'}; {'id': '25', 'type': 'integer', 'children': [], 'value': '1024'}; {'id': '26', 'type': 'with_statement', 'children': ['27', '40']}; {'id': '27', 'type': 'with_clause', 'children': ['28']}; {'id': '28', 'type': 'with_item', 'children': ['29']}; {'id': '29', 'type': 'as_pattern', 'children': ['30', '38']}; {'id': '30', 'type': 'call', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '32', 'type': 'argument_list', 'children': ['33', '34', '35']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '34', 'type': 'string', 'children': [], 'value': "'rb'"}; {'id': '35', 'type': 'keyword_argument', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'buffering'}; {'id': '37', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '38', 'type': 'as_pattern_target', 'children': ['39']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'stream'}; {'id': '40', 'type': 'block', 'children': ['41']}; {'id': '41', 'type': 'for_statement', 'children': ['42', '43', '54']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '43', 'type': 'call', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'iter'}; {'id': '45', 'type': 'argument_list', 'children': ['46', '53']}; {'id': '46', 'type': 'lambda', 'children': ['47']}; {'id': '47', 'type': 'call', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'stream'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'readinto'}; {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'mem_view'}; {'id': '53', 'type': 'integer', 'children': [], 'value': '0'}; {'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': 'sha256'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}; {'id': '61', 'type': 'subscript', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'mem_view'}; {'id': '63', 'type': 'slice', 'children': ['64', '65']}; {'id': '64', 'type': 'colon', 'children': []}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '66', 'type': 'return_statement', 'children': ['67']}; {'id': '67', 'type': 'call', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'sha256'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'hexdigest'}; {'id': '71', 'type': 'argument_list', 'children': []}
|
Return SHA256 hash of file.
|
def _reduce(self, op, name, axis=0, skipna=True, numeric_only=None,
filter_type=None, **kwds):
func = getattr(self, name, None)
if func is None:
raise TypeError("{klass} cannot perform the operation {op}".format(
klass=self.__class__.__name__, op=name))
return func(skipna=skipna, **kwds)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '21']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_reduce'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13', '16', '19']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'op'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'axis'}; {'id': '9', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'skipna'}; {'id': '12', 'type': 'True', 'children': []}; {'id': '13', 'type': 'default_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'numeric_only'}; {'id': '15', 'type': 'None', 'children': []}; {'id': '16', 'type': 'default_parameter', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'filter_type'}; {'id': '18', 'type': 'None', 'children': []}; {'id': '19', 'type': 'dictionary_splat_pattern', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'kwds'}; {'id': '21', 'type': 'block', 'children': ['22', '31', '55']}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}; {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '27', 'type': 'argument_list', 'children': ['28', '29', '30']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '30', 'type': 'None', 'children': []}; {'id': '31', 'type': 'if_statement', 'children': ['32', '35']}; {'id': '32', 'type': 'comparison_operator', 'children': ['33', '34'], 'value': 'is'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '34', 'type': 'None', 'children': []}; {'id': '35', 'type': 'block', 'children': ['36']}; {'id': '36', 'type': 'raise_statement', 'children': ['37']}; {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'TypeError'}; {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'call', 'children': ['41', '44']}; {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'string', 'children': [], 'value': '"{klass} cannot perform the operation {op}"'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '44', 'type': 'argument_list', 'children': ['45', '52']}; {'id': '45', 'type': 'keyword_argument', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'klass'}; {'id': '47', 'type': 'attribute', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': '__class__'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': '__name__'}; {'id': '52', 'type': 'keyword_argument', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'op'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '55', 'type': 'return_statement', 'children': ['56']}; {'id': '56', 'type': 'call', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '58', 'type': 'argument_list', 'children': ['59', '62']}; {'id': '59', 'type': 'keyword_argument', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'skipna'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'skipna'}; {'id': '62', 'type': 'dictionary_splat', 'children': ['63']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'kwds'}
|
perform the reduction type operation if we can
|
def increase_last(self, k):
idx = self._last_idx
if idx is not None:
self.results[idx] += k
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'increase_last'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '6', 'type': 'block', 'children': ['7', '13']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': '_last_idx'}; {'id': '13', 'type': 'if_statement', 'children': ['14', '17']}; {'id': '14', 'type': 'comparison_operator', 'children': ['15', '16'], 'value': 'is not'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '16', 'type': 'None', 'children': []}; {'id': '17', 'type': 'block', 'children': ['18']}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}; {'id': '19', 'type': 'augmented_assignment', 'children': ['20', '25'], 'value': '+='}; {'id': '20', 'type': 'subscript', 'children': ['21', '24']}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'k'}
|
Increase the last result by k.
|
def parameters(self):
parameters = {}
for name in self.PARAMETERS:
try:
parameters[name] = self.get_parameter(name)
except AttributeError:
pass
return parameters
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'parameters'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '10', '33']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'parameters'}; {'id': '9', 'type': 'dictionary', 'children': []}; {'id': '10', 'type': 'for_statement', 'children': ['11', '12', '15']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'PARAMETERS'}; {'id': '15', 'type': 'block', 'children': ['16']}; {'id': '16', 'type': 'try_statement', 'children': ['17', '29']}; {'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': 'parameters'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'name'}; {'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': 'get_parameter'}; {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '29', 'type': 'except_clause', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'AttributeError'}; {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'pass_statement', 'children': []}; {'id': '33', 'type': 'return_statement', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'parameters'}
|
Get dict with all set parameters.
|
def exists_query(expression):
def _exists(index, expression=expression):
ev = expression() if callable(expression) else expression
if ev:
return [
store_key
for store_keys
in index.get_index().values()
for store_key in store_keys
]
else:
return index.get_undefined_keys()
return _exists
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'exists_query'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'expression'}; {'id': '5', 'type': 'block', 'children': ['6', '54']}; {'id': '6', 'type': 'function_definition', 'children': ['7', '8', '13']}; {'id': '7', 'type': 'function_name', 'children': [], 'value': '_exists'}; {'id': '8', 'type': 'parameters', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'expression'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'expression'}; {'id': '13', 'type': 'block', 'children': ['14', '26']}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}; {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'ev'}; {'id': '17', 'type': 'conditional_expression', 'children': ['18', '21', '25'], 'value': 'if'}; {'id': '18', 'type': 'call', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'expression'}; {'id': '20', 'type': 'argument_list', 'children': []}; {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'callable'}; {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'expression'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'expression'}; {'id': '26', 'type': 'if_statement', 'children': ['27', '28', '46']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'ev'}; {'id': '28', 'type': 'block', 'children': ['29']}; {'id': '29', 'type': 'return_statement', 'children': ['30']}; {'id': '30', 'type': 'list_comprehension', 'children': ['31', '32', '43']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'store_key'}; {'id': '32', 'type': 'for_in_clause', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'store_keys'}; {'id': '34', 'type': 'call', 'children': ['35', '42']}; {'id': '35', 'type': 'attribute', 'children': ['36', '41']}; {'id': '36', 'type': 'call', 'children': ['37', '40']}; {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'get_index'}; {'id': '40', 'type': 'argument_list', 'children': []}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '42', 'type': 'argument_list', 'children': []}; {'id': '43', 'type': 'for_in_clause', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'store_key'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'store_keys'}; {'id': '46', 'type': 'else_clause', 'children': ['47']}; {'id': '47', 'type': 'block', 'children': ['48']}; {'id': '48', 'type': 'return_statement', 'children': ['49']}; {'id': '49', 'type': 'call', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'get_undefined_keys'}; {'id': '53', 'type': 'argument_list', 'children': []}; {'id': '54', 'type': 'return_statement', 'children': ['55']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': '_exists'}
|
Check that documents have a key that satisfies expression.
|
def _active_cli(self):
cli = self.cli
while cli._sub_cli:
cli = cli._sub_cli
return cli
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_active_cli'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '12', '23']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'cli'}; {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'cli'}; {'id': '12', 'type': 'while_statement', 'children': ['13', '16']}; {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'cli'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': '_sub_cli'}; {'id': '16', 'type': 'block', 'children': ['17']}; {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'cli'}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'cli'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': '_sub_cli'}; {'id': '23', 'type': 'return_statement', 'children': ['24']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'cli'}
|
Return the active `CommandLineInterface`.
|
def _new_from_cdata(cls, cdata: Any) -> "Color":
return cls(cdata.r, cdata.g, cdata.b)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_new_from_cdata'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '5', 'type': 'typed_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'cdata'}; {'id': '7', 'type': 'type', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'Any'}; {'id': '9', 'type': 'type', 'children': ['10']}; {'id': '10', 'type': 'string', 'children': [], 'value': '"Color"'}; {'id': '11', 'type': 'block', 'children': ['12']}; {'id': '12', 'type': 'return_statement', 'children': ['13']}; {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '15', 'type': 'argument_list', 'children': ['16', '19', '22']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'cdata'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'cdata'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'cdata'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'b'}
|
new in libtcod-cffi
|
def unpad(cls, data):
if sys.version_info > (3, 0):
return data[:-ord(data[len(data)-1:])].decode()
else:
return data[:-ord(data[len(data)-1:])]
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'unpad'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '6', 'type': 'block', 'children': ['7']}; {'id': '7', 'type': 'if_statement', 'children': ['8', '15', '39']}; {'id': '8', 'type': 'comparison_operator', 'children': ['9', '12'], 'value': '>'}; {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'version_info'}; {'id': '12', 'type': 'tuple', 'children': ['13', '14']}; {'id': '13', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '14', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '15', 'type': 'block', 'children': ['16']}; {'id': '16', 'type': 'return_statement', 'children': ['17']}; {'id': '17', 'type': 'call', 'children': ['18', '38']}; {'id': '18', 'type': 'attribute', 'children': ['19', '37']}; {'id': '19', 'type': 'subscript', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '21', 'type': 'slice', 'children': ['22', '23']}; {'id': '22', 'type': 'colon', 'children': []}; {'id': '23', 'type': 'unary_operator', 'children': ['24'], 'value': '-'}; {'id': '24', 'type': 'call', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'ord'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}; {'id': '27', 'type': 'subscript', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '29', 'type': 'slice', 'children': ['30', '36']}; {'id': '30', 'type': 'binary_operator', 'children': ['31', '35'], 'value': '-'}; {'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': 'data'}; {'id': '35', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '36', 'type': 'colon', 'children': []}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'decode'}; {'id': '38', 'type': 'argument_list', 'children': []}; {'id': '39', 'type': 'else_clause', 'children': ['40']}; {'id': '40', 'type': 'block', 'children': ['41']}; {'id': '41', 'type': 'return_statement', 'children': ['42']}; {'id': '42', 'type': 'subscript', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '44', 'type': 'slice', 'children': ['45', '46']}; {'id': '45', 'type': 'colon', 'children': []}; {'id': '46', 'type': 'unary_operator', 'children': ['47'], 'value': '-'}; {'id': '47', 'type': 'call', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'ord'}; {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'subscript', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '52', 'type': 'slice', 'children': ['53', '59']}; {'id': '53', 'type': 'binary_operator', 'children': ['54', '58'], 'value': '-'}; {'id': '54', 'type': 'call', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '58', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '59', 'type': 'colon', 'children': []}
|
Unpads data that has been padded
|
def usage(title, message, tutorial_message, tutorial, css_path=CSS_PATH):
env = Environment()
env.loader = FileSystemLoader(osp.join(CONFDIR_PATH, 'templates'))
usage = env.get_template("usage.html")
return usage.render(css_path=css_path, title=title, intro_message=message,
tutorial_message=tutorial_message, tutorial=tutorial)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'usage'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'title'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'tutorial_message'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'tutorial'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'css_path'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'CSS_PATH'}; {'id': '11', 'type': 'block', 'children': ['12', '18', '33', '42']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}; {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'env'}; {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'Environment'}; {'id': '17', 'type': 'argument_list', 'children': []}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}; {'id': '19', 'type': 'assignment', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'env'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'loader'}; {'id': '23', 'type': 'call', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'FileSystemLoader'}; {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'call', 'children': ['27', '30']}; {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'osp'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '30', 'type': 'argument_list', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'CONFDIR_PATH'}; {'id': '32', 'type': 'string', 'children': [], 'value': "'templates'"}; {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'usage'}; {'id': '36', 'type': 'call', 'children': ['37', '40']}; {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'env'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'get_template'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}; {'id': '41', 'type': 'string', 'children': [], 'value': '"usage.html"'}; {'id': '42', 'type': 'return_statement', 'children': ['43']}; {'id': '43', 'type': 'call', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'usage'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'render'}; {'id': '47', 'type': 'argument_list', 'children': ['48', '51', '54', '57', '60']}; {'id': '48', 'type': 'keyword_argument', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'css_path'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'css_path'}; {'id': '51', 'type': 'keyword_argument', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'title'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'title'}; {'id': '54', 'type': 'keyword_argument', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'intro_message'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '57', 'type': 'keyword_argument', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'tutorial_message'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'tutorial_message'}; {'id': '60', 'type': 'keyword_argument', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'tutorial'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'tutorial'}
|
Print a usage message on the rich text view
|
def json(self):
if self.search_results is None:
return None
result = []
for row in self.search_results['rows']:
obj = {}
for index in range(0, len(self.search_results['fields'])):
obj[self.search_results['fields'][index]] = row[index]
result.append(obj)
return result
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'json'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '15', '19', '67']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '12']}; {'id': '7', 'type': 'comparison_operator', 'children': ['8', '11'], 'value': 'is'}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'search_results'}; {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'block', 'children': ['13']}; {'id': '13', 'type': 'return_statement', 'children': ['14']}; {'id': '14', 'type': 'None', 'children': []}; {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '18', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '19', 'type': 'for_statement', 'children': ['20', '21', '26']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '21', 'type': 'subscript', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'search_results'}; {'id': '25', 'type': 'string', 'children': [], 'value': "'rows'"}; {'id': '26', 'type': 'block', 'children': ['27', '31', '60']}; {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '30', 'type': 'dictionary', 'children': []}; {'id': '31', 'type': 'for_statement', 'children': ['32', '33', '45']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '33', 'type': 'call', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '35', 'type': 'argument_list', 'children': ['36', '37']}; {'id': '36', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'subscript', 'children': ['41', '44']}; {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'search_results'}; {'id': '44', 'type': 'string', 'children': [], 'value': "'fields'"}; {'id': '45', 'type': 'block', 'children': ['46']}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}; {'id': '47', 'type': 'assignment', 'children': ['48', '57']}; {'id': '48', 'type': 'subscript', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '50', 'type': 'subscript', 'children': ['51', '56']}; {'id': '51', 'type': 'subscript', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'search_results'}; {'id': '55', 'type': 'string', 'children': [], 'value': "'fields'"}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '57', 'type': 'subscript', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'index'}; {'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': 'result'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '67', 'type': 'return_statement', 'children': ['68']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'result'}
|
Returns the search results as a list of JSON objects.
|
def _make_read_func(file_obj):
@ffi.callback("cairo_read_func_t", error=constants.STATUS_READ_ERROR)
def read_func(_closure, data, length):
string = file_obj.read(length)
if len(string) < length:
return constants.STATUS_READ_ERROR
ffi.buffer(data, length)[:len(string)] = string
return constants.STATUS_SUCCESS
return read_func
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_make_read_func'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'file_obj'}; {'id': '5', 'type': 'block', 'children': ['6', '68']}; {'id': '6', 'type': 'decorated_definition', 'children': ['7', '19']}; {'id': '7', 'type': 'decorator', 'children': ['8']}; {'id': '8', 'type': 'call', 'children': ['9', '12']}; {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'ffi'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'callback'}; {'id': '12', 'type': 'argument_list', 'children': ['13', '14']}; {'id': '13', 'type': 'string', 'children': [], 'value': '"cairo_read_func_t"'}; {'id': '14', 'type': 'keyword_argument', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'constants'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'STATUS_READ_ERROR'}; {'id': '19', 'type': 'function_definition', 'children': ['20', '21', '25']}; {'id': '20', 'type': 'function_name', 'children': [], 'value': 'read_func'}; {'id': '21', 'type': 'parameters', 'children': ['22', '23', '24']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': '_closure'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'length'}; {'id': '25', 'type': 'block', 'children': ['26', '35', '47', '64']}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}; {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'string'}; {'id': '29', 'type': 'call', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'file_obj'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'read'}; {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'length'}; {'id': '35', 'type': 'if_statement', 'children': ['36', '42']}; {'id': '36', 'type': 'comparison_operator', 'children': ['37', '41'], 'value': '<'}; {'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': 'string'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'length'}; {'id': '42', 'type': 'block', 'children': ['43']}; {'id': '43', 'type': 'return_statement', 'children': ['44']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'constants'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'STATUS_READ_ERROR'}; {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'assignment', 'children': ['49', '63']}; {'id': '49', 'type': 'subscript', 'children': ['50', '57']}; {'id': '50', 'type': 'call', 'children': ['51', '54']}; {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'ffi'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'buffer'}; {'id': '54', 'type': 'argument_list', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'length'}; {'id': '57', 'type': 'slice', 'children': ['58', '59']}; {'id': '58', 'type': 'colon', 'children': []}; {'id': '59', 'type': 'call', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '61', 'type': 'argument_list', 'children': ['62']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'string'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'string'}; {'id': '64', 'type': 'return_statement', 'children': ['65']}; {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'constants'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'STATUS_SUCCESS'}; {'id': '68', 'type': 'return_statement', 'children': ['69']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'read_func'}
|
Return a CFFI callback that reads from a file-like object.
|
def cli(env, identifier, enable):
mgr = SoftLayer.HardwareManager(env.client)
hw_id = helpers.resolve_id(mgr.resolve_ids, identifier, 'hardware')
result = env.client['Hardware_Server'].toggleManagementInterface(enable, id=hw_id)
env.fout(result)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'cli'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'env'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'identifier'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'enable'}; {'id': '7', 'type': 'block', 'children': ['8', '19', '32', '48']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'mgr'}; {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'SoftLayer'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'HardwareManager'}; {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'env'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'client'}; {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'hw_id'}; {'id': '22', 'type': 'call', 'children': ['23', '26']}; {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'helpers'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'resolve_id'}; {'id': '26', 'type': 'argument_list', 'children': ['27', '30', '31']}; {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'mgr'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'resolve_ids'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'identifier'}; {'id': '31', 'type': 'string', 'children': [], 'value': "'hardware'"}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}; {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '35', 'type': 'call', 'children': ['36', '43']}; {'id': '36', 'type': 'attribute', 'children': ['37', '42']}; {'id': '37', 'type': 'subscript', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'env'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'client'}; {'id': '41', 'type': 'string', 'children': [], 'value': "'Hardware_Server'"}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'toggleManagementInterface'}; {'id': '43', 'type': 'argument_list', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'enable'}; {'id': '45', 'type': 'keyword_argument', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'hw_id'}; {'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': 'env'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'fout'}; {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'result'}
|
Toggle the IPMI interface on and off
|
def draw_image(self, image, item, source):
top, left = item['top'], item['left']
width, height = item['width'], item['height']
image_file = item['image']
img = Image.open(source)
img = self.rotate(img)
iwidth, iheight = img.size
wratio = width / iwidth
hratio = height / iheight
ratio = min(wratio, hratio)
img = img.resize((int(iwidth * ratio),
int(iheight * ratio)),
Image.ANTIALIAS)
iwidth, iheight = img.size
top += (height - iheight) // 2
left += (width - iwidth) // 2
image.paste(img, (left, top))
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'draw_image'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'image'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'source'}; {'id': '8', 'type': 'block', 'children': ['9', '21', '33', '39', '48', '57', '65', '71', '77', '85', '109', '117', '126', '135']}; {'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': 'top'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'left'}; {'id': '14', 'type': 'expression_list', 'children': ['15', '18']}; {'id': '15', 'type': 'subscript', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '17', 'type': 'string', 'children': [], 'value': "'top'"}; {'id': '18', 'type': 'subscript', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '20', 'type': 'string', 'children': [], 'value': "'left'"}; {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '26']}; {'id': '23', 'type': 'pattern_list', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'width'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'height'}; {'id': '26', 'type': 'expression_list', 'children': ['27', '30']}; {'id': '27', 'type': 'subscript', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '29', 'type': 'string', 'children': [], 'value': "'width'"}; {'id': '30', 'type': 'subscript', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '32', 'type': 'string', 'children': [], 'value': "'height'"}; {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'image_file'}; {'id': '36', 'type': 'subscript', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '38', 'type': 'string', 'children': [], 'value': "'image'"}; {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'img'}; {'id': '42', 'type': 'call', 'children': ['43', '46']}; {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'Image'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'source'}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}; {'id': '49', 'type': 'assignment', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'img'}; {'id': '51', 'type': 'call', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'rotate'}; {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'img'}; {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '62']}; {'id': '59', 'type': 'pattern_list', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'iwidth'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'iheight'}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'img'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'size'}; {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'wratio'}; {'id': '68', 'type': 'binary_operator', 'children': ['69', '70'], 'value': '/'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'width'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'iwidth'}; {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'assignment', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'hratio'}; {'id': '74', 'type': 'binary_operator', 'children': ['75', '76'], 'value': '/'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'height'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'iheight'}; {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'ratio'}; {'id': '80', 'type': 'call', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'min'}; {'id': '82', 'type': 'argument_list', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'wratio'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'hratio'}; {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'assignment', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'img'}; {'id': '88', 'type': 'call', 'children': ['89', '92']}; {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'img'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'resize'}; {'id': '92', 'type': 'argument_list', 'children': ['93', '106']}; {'id': '93', 'type': 'tuple', 'children': ['94', '100']}; {'id': '94', 'type': 'call', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '96', 'type': 'argument_list', 'children': ['97']}; {'id': '97', 'type': 'binary_operator', 'children': ['98', '99'], 'value': '*'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'iwidth'}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'ratio'}; {'id': '100', 'type': 'call', 'children': ['101', '102']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '102', 'type': 'argument_list', 'children': ['103']}; {'id': '103', 'type': 'binary_operator', 'children': ['104', '105'], 'value': '*'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'iheight'}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'ratio'}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'Image'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'ANTIALIAS'}; {'id': '109', 'type': 'expression_statement', 'children': ['110']}; {'id': '110', 'type': 'assignment', 'children': ['111', '114']}; {'id': '111', 'type': 'pattern_list', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'iwidth'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'iheight'}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'img'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'size'}; {'id': '117', 'type': 'expression_statement', 'children': ['118']}; {'id': '118', 'type': 'augmented_assignment', 'children': ['119', '120'], 'value': '+='}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'top'}; {'id': '120', 'type': 'binary_operator', 'children': ['121', '125'], 'value': '//'}; {'id': '121', 'type': '()', 'children': ['122']}; {'id': '122', 'type': 'binary_operator', 'children': ['123', '124'], 'value': '-'}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'height'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'iheight'}; {'id': '125', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '126', 'type': 'expression_statement', 'children': ['127']}; {'id': '127', 'type': 'augmented_assignment', 'children': ['128', '129'], 'value': '+='}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'left'}; {'id': '129', 'type': 'binary_operator', 'children': ['130', '134'], 'value': '//'}; {'id': '130', 'type': '()', 'children': ['131']}; {'id': '131', 'type': 'binary_operator', 'children': ['132', '133'], 'value': '-'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'width'}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'iwidth'}; {'id': '134', 'type': 'integer', 'children': [], 'value': '2'}; {'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': 'image'}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'paste'}; {'id': '140', 'type': 'argument_list', 'children': ['141', '142']}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'img'}; {'id': '142', 'type': 'tuple', 'children': ['143', '144']}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'left'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'top'}
|
Add an image to the image
|
def should_reschedule(self, iteration, bracket_iteration):
bracket = self.get_bracket(iteration=iteration)
if bracket_iteration < bracket:
return False
return self.get_bracket(iteration=iteration + 1) >= 0
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'should_reschedule'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'iteration'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'bracket_iteration'}; {'id': '7', 'type': 'block', 'children': ['8', '19', '26']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'bracket'}; {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'get_bracket'}; {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'keyword_argument', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'iteration'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'iteration'}; {'id': '19', 'type': 'if_statement', 'children': ['20', '23']}; {'id': '20', 'type': 'comparison_operator', 'children': ['21', '22'], 'value': '<'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'bracket_iteration'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'bracket'}; {'id': '23', 'type': 'block', 'children': ['24']}; {'id': '24', 'type': 'return_statement', 'children': ['25']}; {'id': '25', 'type': 'False', 'children': []}; {'id': '26', 'type': 'return_statement', 'children': ['27']}; {'id': '27', 'type': 'comparison_operator', 'children': ['28', '38'], 'value': '>='}; {'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': 'get_bracket'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}; {'id': '33', 'type': 'keyword_argument', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'iteration'}; {'id': '35', 'type': 'binary_operator', 'children': ['36', '37'], 'value': '+'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'iteration'}; {'id': '37', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '38', 'type': 'integer', 'children': [], 'value': '0'}
|
Return a boolean to indicate if we need to reschedule another iteration.
|
def db_for_write(self, model, **hints):
if model._meta.app_label in self._apps:
return getattr(model, '_db_alias', model._meta.app_label)
return None
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'db_for_write'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '6', 'type': 'dictionary_splat_pattern', 'children': ['7']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'hints'}; {'id': '8', 'type': 'block', 'children': ['9', '31']}; {'id': '9', 'type': 'if_statement', 'children': ['10', '19']}; {'id': '10', 'type': 'comparison_operator', 'children': ['11', '16'], 'value': 'in'}; {'id': '11', 'type': 'attribute', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': '_meta'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'app_label'}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': '_apps'}; {'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': 'getattr'}; {'id': '23', 'type': 'argument_list', 'children': ['24', '25', '26']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '25', 'type': 'string', 'children': [], 'value': "'_db_alias'"}; {'id': '26', 'type': 'attribute', 'children': ['27', '30']}; {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': '_meta'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'app_label'}; {'id': '31', 'type': 'return_statement', 'children': ['32']}; {'id': '32', 'type': 'None', 'children': []}
|
If the app has its own database, use it for writes
|
def _valid_numpy_subdtype(x, numpy_types):
for t in numpy_types:
assert not np.issubdtype(np.generic, t)
return any(np.issubdtype(x.dtype, t) for t in numpy_types)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_valid_numpy_subdtype'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'numpy_types'}; {'id': '6', 'type': 'block', 'children': ['7', '22']}; {'id': '7', 'type': 'for_statement', 'children': ['8', '9', '10']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'numpy_types'}; {'id': '10', 'type': 'block', 'children': ['11']}; {'id': '11', 'type': 'assert_statement', 'children': ['12']}; {'id': '12', 'type': 'not_operator', 'children': ['13']}; {'id': '13', 'type': 'call', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'issubdtype'}; {'id': '17', 'type': 'argument_list', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'generic'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '22', 'type': 'return_statement', 'children': ['23']}; {'id': '23', 'type': 'call', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'any'}; {'id': '25', 'type': 'generator_expression', 'children': ['26', '35']}; {'id': '26', 'type': 'call', 'children': ['27', '30']}; {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'issubdtype'}; {'id': '30', 'type': 'argument_list', 'children': ['31', '34']}; {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '35', 'type': 'for_in_clause', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'numpy_types'}
|
Is any dtype from numpy_types superior to the dtype of x?
|
def section(title, bar=OVERLINE, strm=sys.stdout):
width = utils.term.width
printy(bold(title.center(width)))
printy(bold((bar * width)[:width]))
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'section'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'title'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'bar'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'OVERLINE'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'strm'}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'stdout'}; {'id': '13', 'type': 'block', 'children': ['14', '22', '35']}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}; {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'width'}; {'id': '17', 'type': 'attribute', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'term'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'width'}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}; {'id': '23', 'type': 'call', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'printy'}; {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'call', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'bold'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}; {'id': '29', 'type': 'call', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'title'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'center'}; {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'width'}; {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'call', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'printy'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}; {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'bold'}; {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'subscript', 'children': ['43', '47']}; {'id': '43', 'type': '()', 'children': ['44']}; {'id': '44', 'type': 'binary_operator', 'children': ['45', '46'], 'value': '*'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'bar'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'width'}; {'id': '47', 'type': 'slice', 'children': ['48', '49']}; {'id': '48', 'type': 'colon', 'children': []}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'width'}
|
Helper function for testing demo routines
|
def validate_response(self):
if self.response is None:
logger.error("Failed to submit")
return False
if not self.response:
logger.error(
"HTTP status %d: failed to submit to %s",
self.response.status_code,
self.response.url,
)
return False
if not self.parsed_response:
logger.error("Submit to %s failed, invalid response received", self.response.url)
return False
error_message = self.get_error_message()
if error_message:
logger.error("Submit to %s failed with error", self.response.url)
logger.debug("Error message: %s", error_message)
return False
if not self.job_ids:
logger.error("Submit to %s failed to get job id", self.response.url)
return False
logger.info("Results received by the Importer (HTTP status %d)", self.response.status_code)
logger.info("Job IDs: %s", self.job_ids)
return True
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'validate_response'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '22', '47', '67', '75', '100', '120', '132', '142']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '12']}; {'id': '7', 'type': 'comparison_operator', 'children': ['8', '11'], 'value': 'is'}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'block', 'children': ['13', '20']}; {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'call', 'children': ['15', '18']}; {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}; {'id': '19', 'type': 'string', 'children': [], 'value': '"Failed to submit"'}; {'id': '20', 'type': 'return_statement', 'children': ['21']}; {'id': '21', 'type': 'False', 'children': []}; {'id': '22', 'type': 'if_statement', 'children': ['23', '27']}; {'id': '23', 'type': 'not_operator', 'children': ['24']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '27', 'type': 'block', 'children': ['28', '45']}; {'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': 'logger'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '33', 'type': 'argument_list', 'children': ['34', '35', '40']}; {'id': '34', 'type': 'string', 'children': [], 'value': '"HTTP status %d: failed to submit to %s"'}; {'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': 'response'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'status_code'}; {'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': 'response'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '45', 'type': 'return_statement', 'children': ['46']}; {'id': '46', 'type': 'False', 'children': []}; {'id': '47', 'type': 'if_statement', 'children': ['48', '52']}; {'id': '48', 'type': 'not_operator', 'children': ['49']}; {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'parsed_response'}; {'id': '52', 'type': 'block', 'children': ['53', '65']}; {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'call', 'children': ['55', '58']}; {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '58', 'type': 'argument_list', 'children': ['59', '60']}; {'id': '59', 'type': 'string', 'children': [], 'value': '"Submit to %s failed, invalid response received"'}; {'id': '60', 'type': 'attribute', 'children': ['61', '64']}; {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '65', 'type': 'return_statement', 'children': ['66']}; {'id': '66', 'type': 'False', 'children': []}; {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'assignment', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'error_message'}; {'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': 'get_error_message'}; {'id': '74', 'type': 'argument_list', 'children': []}; {'id': '75', 'type': 'if_statement', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'error_message'}; {'id': '77', 'type': 'block', 'children': ['78', '90', '98']}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}; {'id': '79', 'type': 'call', 'children': ['80', '83']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '83', 'type': 'argument_list', 'children': ['84', '85']}; {'id': '84', 'type': 'string', 'children': [], 'value': '"Submit to %s failed with error"'}; {'id': '85', 'type': 'attribute', 'children': ['86', '89']}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}; {'id': '91', 'type': 'call', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '95', 'type': 'argument_list', 'children': ['96', '97']}; {'id': '96', 'type': 'string', 'children': [], 'value': '"Error message: %s"'}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'error_message'}; {'id': '98', 'type': 'return_statement', 'children': ['99']}; {'id': '99', 'type': 'False', 'children': []}; {'id': '100', 'type': 'if_statement', 'children': ['101', '105']}; {'id': '101', 'type': 'not_operator', 'children': ['102']}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'job_ids'}; {'id': '105', 'type': 'block', 'children': ['106', '118']}; {'id': '106', 'type': 'expression_statement', 'children': ['107']}; {'id': '107', 'type': 'call', 'children': ['108', '111']}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '111', 'type': 'argument_list', 'children': ['112', '113']}; {'id': '112', 'type': 'string', 'children': [], 'value': '"Submit to %s failed to get job id"'}; {'id': '113', 'type': 'attribute', 'children': ['114', '117']}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '118', 'type': 'return_statement', 'children': ['119']}; {'id': '119', 'type': 'False', 'children': []}; {'id': '120', 'type': 'expression_statement', 'children': ['121']}; {'id': '121', 'type': 'call', 'children': ['122', '125']}; {'id': '122', 'type': 'attribute', 'children': ['123', '124']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '125', 'type': 'argument_list', 'children': ['126', '127']}; {'id': '126', 'type': 'string', 'children': [], 'value': '"Results received by the Importer (HTTP status %d)"'}; {'id': '127', 'type': 'attribute', 'children': ['128', '131']}; {'id': '128', 'type': 'attribute', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'status_code'}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}; {'id': '133', 'type': 'call', 'children': ['134', '137']}; {'id': '134', 'type': 'attribute', 'children': ['135', '136']}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '137', 'type': 'argument_list', 'children': ['138', '139']}; {'id': '138', 'type': 'string', 'children': [], 'value': '"Job IDs: %s"'}; {'id': '139', 'type': 'attribute', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'job_ids'}; {'id': '142', 'type': 'return_statement', 'children': ['143']}; {'id': '143', 'type': 'True', 'children': []}
|
Checks that the response is valid and import succeeded.
|
def import_eit_fzj(self, filename, configfile, correction_file=None,
timestep=None, **kwargs):
df_emd, dummy1, dummy2 = eit_fzj.read_3p_data(
filename,
configfile,
**kwargs
)
if correction_file is not None:
eit_fzj_utils.apply_correction_factors(df_emd, correction_file)
if timestep is not None:
df_emd['timestep'] = timestep
self._add_to_container(df_emd)
print('Summary:')
self._describe_data(df_emd)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'import_eit_fzj'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'configfile'}; {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'correction_file'}; {'id': '9', 'type': 'None', 'children': []}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'timestep'}; {'id': '12', 'type': 'None', 'children': []}; {'id': '13', 'type': 'dictionary_splat_pattern', 'children': ['14']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '15', 'type': 'block', 'children': ['16', '31', '44', '55', '62', '67']}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}; {'id': '17', 'type': 'assignment', 'children': ['18', '22']}; {'id': '18', 'type': 'pattern_list', 'children': ['19', '20', '21']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'df_emd'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'dummy1'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'dummy2'}; {'id': '22', 'type': 'call', 'children': ['23', '26']}; {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'eit_fzj'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'read_3p_data'}; {'id': '26', 'type': 'argument_list', 'children': ['27', '28', '29']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'configfile'}; {'id': '29', 'type': 'dictionary_splat', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '31', 'type': 'if_statement', 'children': ['32', '35']}; {'id': '32', 'type': 'comparison_operator', 'children': ['33', '34'], 'value': 'is not'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'correction_file'}; {'id': '34', 'type': 'None', 'children': []}; {'id': '35', 'type': 'block', 'children': ['36']}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}; {'id': '37', 'type': 'call', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'eit_fzj_utils'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'apply_correction_factors'}; {'id': '41', 'type': 'argument_list', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'df_emd'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'correction_file'}; {'id': '44', 'type': 'if_statement', 'children': ['45', '48']}; {'id': '45', 'type': 'comparison_operator', 'children': ['46', '47'], 'value': 'is not'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'timestep'}; {'id': '47', 'type': 'None', 'children': []}; {'id': '48', 'type': 'block', 'children': ['49']}; {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '54']}; {'id': '51', 'type': 'subscript', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'df_emd'}; {'id': '53', 'type': 'string', 'children': [], 'value': "'timestep'"}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'timestep'}; {'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': 'self'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': '_add_to_container'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'df_emd'}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}; {'id': '63', 'type': 'call', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'string', 'children': [], 'value': "'Summary:'"}; {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'call', 'children': ['69', '72']}; {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': '_describe_data'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'df_emd'}
|
EIT data import for FZJ Medusa systems
|
def _setup_piddir(self):
if self.pidfile is None:
return
piddir = os.path.dirname(self.pidfile)
if not os.path.isdir(piddir):
os.makedirs(piddir, 0o777 & ~self.umask)
os.chown(piddir, self.uid, self.gid)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_setup_piddir'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '14', '27']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '12']}; {'id': '7', 'type': 'comparison_operator', 'children': ['8', '11'], 'value': 'is'}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'pidfile'}; {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'block', 'children': ['13']}; {'id': '13', 'type': 'return_statement', 'children': []}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}; {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'piddir'}; {'id': '17', 'type': 'call', 'children': ['18', '23']}; {'id': '18', 'type': 'attribute', 'children': ['19', '22']}; {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'dirname'}; {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'pidfile'}; {'id': '27', 'type': 'if_statement', 'children': ['28', '37']}; {'id': '28', 'type': 'not_operator', 'children': ['29']}; {'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': 'isdir'}; {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'piddir'}; {'id': '37', 'type': 'block', 'children': ['38', '51']}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}; {'id': '39', 'type': 'call', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'makedirs'}; {'id': '43', 'type': 'argument_list', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'piddir'}; {'id': '45', 'type': 'binary_operator', 'children': ['46', '47'], 'value': '&'}; {'id': '46', 'type': 'integer', 'children': [], 'value': '0o777'}; {'id': '47', 'type': 'unary_operator', 'children': ['48'], 'value': '~'}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'umask'}; {'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': 'os'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'chown'}; {'id': '56', 'type': 'argument_list', 'children': ['57', '58', '61']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'piddir'}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'uid'}; {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'gid'}
|
Create the directory for the PID file if necessary.
|
def split_pieces(piece_list, segments, num):
piece_groups = []
pieces = list(piece_list)
while pieces:
for i in range(segments):
p = pieces[i::segments][:num]
if not p:
break
piece_groups.append(p)
pieces = pieces[num * segments:]
return piece_groups
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'split_pieces'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'piece_list'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'segments'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'num'}; {'id': '7', 'type': 'block', 'children': ['8', '12', '19', '65']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'piece_groups'}; {'id': '11', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}; {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'pieces'}; {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '17', 'type': 'argument_list', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'piece_list'}; {'id': '19', 'type': 'while_statement', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'pieces'}; {'id': '21', 'type': 'block', 'children': ['22', '55']}; {'id': '22', 'type': 'for_statement', 'children': ['23', '24', '28']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '24', 'type': 'call', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'segments'}; {'id': '28', 'type': 'block', 'children': ['29', '43', '48']}; {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '32', 'type': 'subscript', 'children': ['33', '40']}; {'id': '33', 'type': 'subscript', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'pieces'}; {'id': '35', 'type': 'slice', 'children': ['36', '37', '38', '39']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '37', 'type': 'colon', 'children': []}; {'id': '38', 'type': 'colon', 'children': []}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'segments'}; {'id': '40', 'type': 'slice', 'children': ['41', '42']}; {'id': '41', 'type': 'colon', 'children': []}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'num'}; {'id': '43', 'type': 'if_statement', 'children': ['44', '46']}; {'id': '44', 'type': 'not_operator', 'children': ['45']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '46', 'type': 'block', 'children': ['47']}; {'id': '47', 'type': 'break_statement', 'children': []}; {'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': 'piece_groups'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'pieces'}; {'id': '58', 'type': 'subscript', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'pieces'}; {'id': '60', 'type': 'slice', 'children': ['61', '64']}; {'id': '61', 'type': 'binary_operator', 'children': ['62', '63'], 'value': '*'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'num'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'segments'}; {'id': '64', 'type': 'colon', 'children': []}; {'id': '65', 'type': 'return_statement', 'children': ['66']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'piece_groups'}
|
Prepare a list of all pieces grouped together
|
def neighborhood(self, node, degree=4):
assert self.by_name[node.name] == node
already_visited = frontier = set([node.name])
for _ in range(degree):
neighbor_names = set()
for node_name in frontier:
outgoing = set(n.name for n in self.by_input[node_name])
incoming = set(self.by_name[node_name].input)
neighbor_names |= incoming | outgoing
frontier = neighbor_names - already_visited
already_visited |= neighbor_names
return [self.by_name[name] for name in already_visited]
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'neighborhood'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'degree'}; {'id': '8', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '9', 'type': 'block', 'children': ['10', '20', '32', '94']}; {'id': '10', 'type': 'assert_statement', 'children': ['11']}; {'id': '11', 'type': 'comparison_operator', 'children': ['12', '19'], 'value': '=='}; {'id': '12', 'type': 'subscript', 'children': ['13', '16']}; {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'by_name'}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}; {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'already_visited'}; {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'frontier'}; {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'list', 'children': ['29'], 'value': '[node.name]'}; {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '32', 'type': 'for_statement', 'children': ['33', '34', '38']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '34', 'type': 'call', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'degree'}; {'id': '38', 'type': 'block', 'children': ['39', '45', '84', '90']}; {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'neighbor_names'}; {'id': '42', 'type': 'call', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '44', 'type': 'argument_list', 'children': []}; {'id': '45', 'type': 'for_statement', 'children': ['46', '47', '48']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'node_name'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'frontier'}; {'id': '48', 'type': 'block', 'children': ['49', '65', '78']}; {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'outgoing'}; {'id': '52', 'type': 'call', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '54', 'type': 'generator_expression', 'children': ['55', '58']}; {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '58', 'type': 'for_in_clause', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '60', 'type': 'subscript', 'children': ['61', '64']}; {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'by_input'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'node_name'}; {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'incoming'}; {'id': '68', 'type': 'call', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}; {'id': '71', 'type': 'attribute', 'children': ['72', '77']}; {'id': '72', 'type': 'subscript', 'children': ['73', '76']}; {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'by_name'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'node_name'}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'input'}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}; {'id': '79', 'type': 'augmented_assignment', 'children': ['80', '81'], 'value': '|='}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'neighbor_names'}; {'id': '81', 'type': 'binary_operator', 'children': ['82', '83'], 'value': '|'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'incoming'}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'outgoing'}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}; {'id': '85', 'type': 'assignment', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'frontier'}; {'id': '87', 'type': 'binary_operator', 'children': ['88', '89'], 'value': '-'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'neighbor_names'}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'already_visited'}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}; {'id': '91', 'type': 'augmented_assignment', 'children': ['92', '93'], 'value': '|='}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'already_visited'}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'neighbor_names'}; {'id': '94', 'type': 'return_statement', 'children': ['95']}; {'id': '95', 'type': 'list_comprehension', 'children': ['96', '101']}; {'id': '96', 'type': 'subscript', 'children': ['97', '100']}; {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'by_name'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '101', 'type': 'for_in_clause', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'already_visited'}
|
Am I really handcoding graph traversal please no
|
def generate_trajs(self, M, N, start=None, stop=None, dt=1):
from msmtools.generation import generate_trajs
return generate_trajs(self._P, M, N, start=start, stop=stop, dt=dt)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'generate_trajs'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'M'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'N'}; {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '9', 'type': 'None', 'children': []}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'stop'}; {'id': '12', 'type': 'None', 'children': []}; {'id': '13', 'type': 'default_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'dt'}; {'id': '15', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '16', 'type': 'block', 'children': ['17', '23']}; {'id': '17', 'type': 'import_from_statement', 'children': ['18', '21']}; {'id': '18', 'type': 'dotted_name', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'msmtools'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'generation'}; {'id': '21', 'type': 'dotted_name', 'children': ['22']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'generate_trajs'}; {'id': '23', 'type': 'return_statement', 'children': ['24']}; {'id': '24', 'type': 'call', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'generate_trajs'}; {'id': '26', 'type': 'argument_list', 'children': ['27', '30', '31', '32', '35', '38']}; {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': '_P'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'M'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'N'}; {'id': '32', 'type': 'keyword_argument', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '35', 'type': 'keyword_argument', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'stop'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'stop'}; {'id': '38', 'type': 'keyword_argument', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'dt'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'dt'}
|
Generates M random trajectories of length N each with time step dt
|
def count(self):
return functools.reduce(lambda x, y: x * y, (x.count for x in self.bounds))
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'count'}; {'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': 'call', 'children': ['8', '11']}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'functools'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'reduce'}; {'id': '11', 'type': 'argument_list', 'children': ['12', '19']}; {'id': '12', 'type': 'lambda', 'children': ['13', '16']}; {'id': '13', 'type': 'lambda_parameters', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '16', 'type': 'binary_operator', 'children': ['17', '18'], 'value': '*'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '19', 'type': 'generator_expression', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '23', 'type': 'for_in_clause', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'bounds'}
|
Total number of array cells
|
def hijack_require_http_methods(fn):
required_methods = ['POST']
if hijack_settings.HIJACK_ALLOW_GET_REQUESTS:
required_methods.append('GET')
return require_http_methods(required_methods)(fn)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'hijack_require_http_methods'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'fn'}; {'id': '5', 'type': 'block', 'children': ['6', '11', '23']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'required_methods'}; {'id': '9', 'type': 'list', 'children': ['10'], 'value': "['POST']"}; {'id': '10', 'type': 'string', 'children': [], 'value': "'POST'"}; {'id': '11', 'type': 'if_statement', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'hijack_settings'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'HIJACK_ALLOW_GET_REQUESTS'}; {'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': 'required_methods'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'string', 'children': [], 'value': "'GET'"}; {'id': '23', 'type': 'return_statement', 'children': ['24']}; {'id': '24', 'type': 'call', 'children': ['25', '29']}; {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'require_http_methods'}; {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'required_methods'}; {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'fn'}
|
Wrapper for "require_http_methods" decorator. POST required by default, GET can optionally be allowed
|
def to_dict(self):
attributes = dict(self.attributes.items())
if self.style:
attributes.update({"style": dict(self.style.items())})
vdom_dict = {'tagName': self.tag_name, 'attributes': attributes}
if self.event_handlers:
event_handlers = dict(self.event_handlers.items())
for key, value in event_handlers.items():
value = create_event_handler(key, value)
event_handlers[key] = value
vdom_dict['eventHandlers'] = event_handlers
if self.key:
vdom_dict['key'] = self.key
vdom_dict['children'] = [c.to_dict() if isinstance(c, VDOM) else c for c in self.children]
return vdom_dict
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'to_dict'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '19', '43', '55', '103', '116', '139']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'attributes'}; {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '11', 'type': 'argument_list', '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': 'attributes'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '18', 'type': 'argument_list', 'children': []}; {'id': '19', 'type': 'if_statement', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'style'}; {'id': '23', 'type': 'block', 'children': ['24']}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}; {'id': '25', 'type': 'call', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'attributes'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'dictionary', 'children': ['31']}; {'id': '31', 'type': 'pair', 'children': ['32', '33']}; {'id': '32', 'type': 'string', 'children': [], 'value': '"style"'}; {'id': '33', 'type': 'call', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'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': 'style'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'items'}; {'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': 'vdom_dict'}; {'id': '46', 'type': 'dictionary', 'children': ['47', '52']}; {'id': '47', 'type': 'pair', 'children': ['48', '49']}; {'id': '48', 'type': 'string', 'children': [], 'value': "'tagName'"}; {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'tag_name'}; {'id': '52', 'type': 'pair', 'children': ['53', '54']}; {'id': '53', 'type': 'string', 'children': [], 'value': "'attributes'"}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'attributes'}; {'id': '55', 'type': 'if_statement', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'event_handlers'}; {'id': '59', 'type': 'block', 'children': ['60', '73', '97']}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}; {'id': '61', 'type': 'assignment', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'event_handlers'}; {'id': '63', 'type': 'call', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'call', 'children': ['67', '72']}; {'id': '67', 'type': 'attribute', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'event_handlers'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '72', 'type': 'argument_list', 'children': []}; {'id': '73', 'type': 'for_statement', 'children': ['74', '77', '82']}; {'id': '74', 'type': 'pattern_list', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '77', 'type': 'call', 'children': ['78', '81']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'event_handlers'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '81', 'type': 'argument_list', 'children': []}; {'id': '82', 'type': 'block', 'children': ['83', '91']}; {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'assignment', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '86', 'type': 'call', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'create_event_handler'}; {'id': '88', 'type': 'argument_list', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'value'}; {'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': 'event_handlers'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'assignment', 'children': ['99', '102']}; {'id': '99', 'type': 'subscript', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'vdom_dict'}; {'id': '101', 'type': 'string', 'children': [], 'value': "'eventHandlers'"}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'event_handlers'}; {'id': '103', 'type': 'if_statement', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '107', 'type': 'block', 'children': ['108']}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}; {'id': '109', 'type': 'assignment', 'children': ['110', '113']}; {'id': '110', 'type': 'subscript', 'children': ['111', '112']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'vdom_dict'}; {'id': '112', 'type': 'string', 'children': [], 'value': "'key'"}; {'id': '113', 'type': 'attribute', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '116', 'type': 'expression_statement', 'children': ['117']}; {'id': '117', 'type': 'assignment', 'children': ['118', '121']}; {'id': '118', 'type': 'subscript', 'children': ['119', '120']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'vdom_dict'}; {'id': '120', 'type': 'string', 'children': [], 'value': "'children'"}; {'id': '121', 'type': 'list_comprehension', 'children': ['122', '134']}; {'id': '122', 'type': 'conditional_expression', 'children': ['123', '128', '133'], 'value': 'if'}; {'id': '123', 'type': 'call', 'children': ['124', '127']}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'to_dict'}; {'id': '127', 'type': 'argument_list', 'children': []}; {'id': '128', 'type': 'call', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '130', 'type': 'argument_list', 'children': ['131', '132']}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'VDOM'}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '134', 'type': 'for_in_clause', 'children': ['135', '136']}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'children'}; {'id': '139', 'type': 'return_statement', 'children': ['140']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'vdom_dict'}
|
Converts VDOM object to a dictionary that passes our schema
|
def _check_frames(self, frames, fill_value):
if self.seekable():
remaining_frames = self.frames - self.tell()
if frames < 0 or (frames > remaining_frames and
fill_value is None):
frames = remaining_frames
elif frames < 0:
raise ValueError("frames must be specified for non-seekable files")
return frames
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_check_frames'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'frames'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'fill_value'}; {'id': '7', 'type': 'block', 'children': ['8', '55']}; {'id': '8', 'type': 'if_statement', 'children': ['9', '14', '45']}; {'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': 'seekable'}; {'id': '13', 'type': 'argument_list', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15', '27']}; {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'remaining_frames'}; {'id': '18', 'type': 'binary_operator', 'children': ['19', '22'], 'value': '-'}; {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'frames'}; {'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': 'tell'}; {'id': '26', 'type': 'argument_list', 'children': []}; {'id': '27', 'type': 'if_statement', 'children': ['28', '40']}; {'id': '28', 'type': 'boolean_operator', 'children': ['29', '32'], 'value': 'or'}; {'id': '29', 'type': 'comparison_operator', 'children': ['30', '31'], 'value': '<'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'frames'}; {'id': '31', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '32', 'type': '()', 'children': ['33']}; {'id': '33', 'type': 'boolean_operator', 'children': ['34', '37'], 'value': 'and'}; {'id': '34', 'type': 'comparison_operator', 'children': ['35', '36'], 'value': '>'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'frames'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'remaining_frames'}; {'id': '37', 'type': 'comparison_operator', 'children': ['38', '39'], 'value': 'is'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'fill_value'}; {'id': '39', 'type': 'None', 'children': []}; {'id': '40', 'type': 'block', 'children': ['41']}; {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'frames'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'remaining_frames'}; {'id': '45', 'type': 'elif_clause', 'children': ['46', '49']}; {'id': '46', 'type': 'comparison_operator', 'children': ['47', '48'], 'value': '<'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'frames'}; {'id': '48', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '49', 'type': 'block', 'children': ['50']}; {'id': '50', 'type': 'raise_statement', 'children': ['51']}; {'id': '51', 'type': 'call', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'string', 'children': [], 'value': '"frames must be specified for non-seekable files"'}; {'id': '55', 'type': 'return_statement', 'children': ['56']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'frames'}
|
Reduce frames to no more than are available in the file.
|
def partial_trace(self, qubits: Qubits) -> 'QubitVector':
N = self.qubit_nb
R = self.rank
if R == 1:
raise ValueError('Cannot take trace of vector')
new_qubits: List[Qubit] = list(self.qubits)
for q in qubits:
new_qubits.remove(q)
if not new_qubits:
raise ValueError('Cannot remove all qubits with partial_trace.')
indices = [self.qubits.index(qubit) for qubit in qubits]
subscripts = list(EINSUM_SUBSCRIPTS)[0:N*R]
for idx in indices:
for r in range(1, R):
subscripts[r * N + idx] = subscripts[idx]
subscript_str = ''.join(subscripts)
tensor = self.asarray()
tensor = np.einsum(subscript_str, tensor)
return QubitVector(tensor, new_qubits)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'partial_trace'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'typed_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'qubits'}; {'id': '7', 'type': 'type', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'Qubits'}; {'id': '9', 'type': 'type', 'children': ['10']}; {'id': '10', 'type': 'string', 'children': [], 'value': "'QubitVector'"}; {'id': '11', 'type': 'block', 'children': ['12', '18', '24', '34', '49', '60', '69', '84', '98', '122', '131', '139', '149']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}; {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'N'}; {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'qubit_nb'}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}; {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'R'}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'rank'}; {'id': '24', 'type': 'if_statement', 'children': ['25', '28']}; {'id': '25', 'type': 'comparison_operator', 'children': ['26', '27'], 'value': '=='}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'R'}; {'id': '27', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '28', 'type': 'block', 'children': ['29']}; {'id': '29', 'type': 'raise_statement', 'children': ['30']}; {'id': '30', 'type': 'call', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}; {'id': '33', 'type': 'string', 'children': [], 'value': "'Cannot take trace of vector'"}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}; {'id': '35', 'type': 'assignment', 'children': ['36', '37', '43']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'new_qubits'}; {'id': '37', 'type': 'type', 'children': ['38']}; {'id': '38', 'type': 'generic_type', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'List'}; {'id': '40', 'type': 'type_parameter', 'children': ['41']}; {'id': '41', 'type': 'type', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'Qubit'}; {'id': '43', 'type': 'call', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'qubits'}; {'id': '49', 'type': 'for_statement', 'children': ['50', '51', '52']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'q'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'qubits'}; {'id': '52', 'type': 'block', 'children': ['53']}; {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'call', 'children': ['55', '58']}; {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'new_qubits'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'remove'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'q'}; {'id': '60', 'type': 'if_statement', 'children': ['61', '63']}; {'id': '61', 'type': 'not_operator', 'children': ['62']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'new_qubits'}; {'id': '63', 'type': 'block', 'children': ['64']}; {'id': '64', 'type': 'raise_statement', 'children': ['65']}; {'id': '65', 'type': 'call', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'string', 'children': [], 'value': "'Cannot remove all qubits with partial_trace.'"}; {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'indices'}; {'id': '72', 'type': 'list_comprehension', 'children': ['73', '81']}; {'id': '73', 'type': 'call', 'children': ['74', '79']}; {'id': '74', 'type': 'attribute', 'children': ['75', '78']}; {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'qubits'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'qubit'}; {'id': '81', 'type': 'for_in_clause', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'qubit'}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'qubits'}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}; {'id': '85', 'type': 'assignment', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'subscripts'}; {'id': '87', 'type': 'subscript', 'children': ['88', '92']}; {'id': '88', 'type': 'call', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '90', 'type': 'argument_list', 'children': ['91']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'EINSUM_SUBSCRIPTS'}; {'id': '92', 'type': 'slice', 'children': ['93', '94', '95']}; {'id': '93', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '94', 'type': 'colon', 'children': []}; {'id': '95', 'type': 'binary_operator', 'children': ['96', '97'], 'value': '*'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'N'}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'R'}; {'id': '98', 'type': 'for_statement', 'children': ['99', '100', '101']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'indices'}; {'id': '101', 'type': 'block', 'children': ['102']}; {'id': '102', 'type': 'for_statement', 'children': ['103', '104', '109']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '104', 'type': 'call', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '106', 'type': 'argument_list', 'children': ['107', '108']}; {'id': '107', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'R'}; {'id': '109', 'type': 'block', 'children': ['110']}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}; {'id': '111', 'type': 'assignment', 'children': ['112', '119']}; {'id': '112', 'type': 'subscript', 'children': ['113', '114']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'subscripts'}; {'id': '114', 'type': 'binary_operator', 'children': ['115', '118'], 'value': '+'}; {'id': '115', 'type': 'binary_operator', 'children': ['116', '117'], 'value': '*'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'N'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '119', 'type': 'subscript', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'subscripts'}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '122', 'type': 'expression_statement', 'children': ['123']}; {'id': '123', 'type': 'assignment', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'subscript_str'}; {'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': 'subscripts'}; {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'assignment', 'children': ['133', '134']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'tensor'}; {'id': '134', 'type': 'call', 'children': ['135', '138']}; {'id': '135', 'type': 'attribute', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'asarray'}; {'id': '138', 'type': 'argument_list', 'children': []}; {'id': '139', 'type': 'expression_statement', 'children': ['140']}; {'id': '140', 'type': 'assignment', 'children': ['141', '142']}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'tensor'}; {'id': '142', 'type': 'call', 'children': ['143', '146']}; {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'einsum'}; {'id': '146', 'type': 'argument_list', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'subscript_str'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'tensor'}; {'id': '149', 'type': 'return_statement', 'children': ['150']}; {'id': '150', 'type': 'call', 'children': ['151', '152']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'QubitVector'}; {'id': '152', 'type': 'argument_list', 'children': ['153', '154']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'tensor'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'new_qubits'}
|
Return the partial trace over some subset of qubits
|
def manage_file_analysis(args: argparse.Namespace, filename: str, data: object) -> None:
key = DataStore.hashfile(filename)
print('Analyzing {} --> {}'.format(filename, key))
if data.check_key(key):
fit = LineFit(filename, data=data.get_data(key))
else:
fit = LineFit(filename)
if args.time:
noise, curvature, rnge, domn = fit.analyze(time=args.time)
newrow = [args.time, noise, curvature,
rnge, domn, fit.accepts[args.time]]
data.update1(key, newrow, len(fit.noises))
else:
fit.analyze_full()
newrows = np.array([range(len(fit.noises)), fit.noises,
fit.curves, fit.ranges, fit.domains, fit.accepts])
data.update(key, newrows)
data.save()
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '18', '20']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'manage_file_analysis'}; {'id': '3', 'type': 'parameters', 'children': ['4', '10', '14']}; {'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '6', 'type': 'type', 'children': ['7']}; {'id': '7', 'type': 'attribute', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'argparse'}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'Namespace'}; {'id': '10', 'type': 'typed_parameter', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '12', 'type': 'type', 'children': ['13']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '14', 'type': 'typed_parameter', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '16', 'type': 'type', 'children': ['17']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'object'}; {'id': '18', 'type': 'type', 'children': ['19']}; {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'block', 'children': ['21', '30', '41', '73', '176']}; {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '24', 'type': 'call', 'children': ['25', '28']}; {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'DataStore'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'hashfile'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}; {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'call', 'children': ['35', '38']}; {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'string', 'children': [], 'value': "'Analyzing {} --> {}'"}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '38', 'type': 'argument_list', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '41', 'type': 'if_statement', 'children': ['42', '48', '64']}; {'id': '42', 'type': 'call', 'children': ['43', '46']}; {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'check_key'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '48', 'type': 'block', 'children': ['49']}; {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'fit'}; {'id': '52', 'type': 'call', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'LineFit'}; {'id': '54', 'type': 'argument_list', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '56', 'type': 'keyword_argument', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '58', 'type': 'call', 'children': ['59', '62']}; {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'get_data'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '64', 'type': 'else_clause', 'children': ['65']}; {'id': '65', 'type': 'block', 'children': ['66']}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}; {'id': '67', 'type': 'assignment', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'fit'}; {'id': '69', 'type': 'call', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'LineFit'}; {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '73', 'type': 'if_statement', 'children': ['74', '77', '127']}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '77', 'type': 'block', 'children': ['78', '95', '113']}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}; {'id': '79', 'type': 'assignment', 'children': ['80', '85']}; {'id': '80', 'type': 'pattern_list', 'children': ['81', '82', '83', '84']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'noise'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'curvature'}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'rnge'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'domn'}; {'id': '85', 'type': 'call', 'children': ['86', '89']}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'fit'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'analyze'}; {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'keyword_argument', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'assignment', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'newrow'}; {'id': '98', 'type': 'list', 'children': ['99', '102', '103', '104', '105', '106'], 'value': '[args.time, noise, curvature,\n rnge, domn, fit.accepts[args.time]]'}; {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'noise'}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'curvature'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'rnge'}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'domn'}; {'id': '106', 'type': 'subscript', 'children': ['107', '110']}; {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'fit'}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'accepts'}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'time'}; {'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': 'data'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'update1'}; {'id': '118', 'type': 'argument_list', 'children': ['119', '120', '121']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'newrow'}; {'id': '121', 'type': 'call', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '123', 'type': 'argument_list', 'children': ['124']}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'fit'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'noises'}; {'id': '127', 'type': 'else_clause', 'children': ['128']}; {'id': '128', 'type': 'block', 'children': ['129', '135', '168']}; {'id': '129', 'type': 'expression_statement', 'children': ['130']}; {'id': '130', 'type': 'call', 'children': ['131', '134']}; {'id': '131', 'type': 'attribute', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'fit'}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'analyze_full'}; {'id': '134', 'type': 'argument_list', 'children': []}; {'id': '135', 'type': 'expression_statement', 'children': ['136']}; {'id': '136', 'type': 'assignment', 'children': ['137', '138']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'newrows'}; {'id': '138', 'type': 'call', 'children': ['139', '142']}; {'id': '139', 'type': 'attribute', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '142', 'type': 'argument_list', 'children': ['143']}; {'id': '143', 'type': 'list', 'children': ['144', '153', '156', '159', '162', '165'], 'value': '[range(len(fit.noises)), fit.noises,\n fit.curves, fit.ranges, fit.domains, fit.accepts]'}; {'id': '144', 'type': 'call', 'children': ['145', '146']}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '146', 'type': 'argument_list', 'children': ['147']}; {'id': '147', 'type': 'call', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '149', 'type': 'argument_list', 'children': ['150']}; {'id': '150', 'type': 'attribute', 'children': ['151', '152']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'fit'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'noises'}; {'id': '153', 'type': 'attribute', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'fit'}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'noises'}; {'id': '156', 'type': 'attribute', 'children': ['157', '158']}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'fit'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'curves'}; {'id': '159', 'type': 'attribute', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'fit'}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'ranges'}; {'id': '162', 'type': 'attribute', 'children': ['163', '164']}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'fit'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'domains'}; {'id': '165', 'type': 'attribute', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'fit'}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'accepts'}; {'id': '168', 'type': 'expression_statement', 'children': ['169']}; {'id': '169', 'type': 'call', 'children': ['170', '173']}; {'id': '170', 'type': 'attribute', 'children': ['171', '172']}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '173', 'type': 'argument_list', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'newrows'}; {'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': 'data'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'save'}; {'id': '181', 'type': 'argument_list', 'children': []}
|
Take care of the analysis of a datafile
|
def match_file(apikey, path, metadata=None):
import audioread
with audioread.audio_open(path) as f:
return match(apikey, iter(f), f.samplerate, int(f.duration),
f.channels, metadata)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'match_file'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'apikey'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'metadata'}; {'id': '8', 'type': 'None', 'children': []}; {'id': '9', 'type': 'block', 'children': ['10', '13']}; {'id': '10', 'type': 'import_statement', 'children': ['11']}; {'id': '11', 'type': 'dotted_name', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'audioread'}; {'id': '13', 'type': 'with_statement', 'children': ['14', '25']}; {'id': '14', 'type': 'with_clause', 'children': ['15']}; {'id': '15', 'type': 'with_item', 'children': ['16']}; {'id': '16', 'type': 'as_pattern', 'children': ['17', '23']}; {'id': '17', 'type': 'call', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'audioread'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'audio_open'}; {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '23', 'type': 'as_pattern_target', 'children': ['24']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '25', 'type': 'block', 'children': ['26']}; {'id': '26', 'type': 'return_statement', 'children': ['27']}; {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '29', 'type': 'argument_list', 'children': ['30', '31', '35', '38', '44', '47']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'apikey'}; {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'iter'}; {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'samplerate'}; {'id': '38', 'type': 'call', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}; {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'duration'}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'channels'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'metadata'}
|
Uses the audioread library to decode an audio file and match it.
|
def dict_to_xml(xml_dict):
import lxml.etree as etree
root_tag = list(xml_dict.keys())[0]
root = etree.Element(root_tag)
_dict_to_xml_recurse(root, xml_dict[root_tag])
return root
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'dict_to_xml'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'xml_dict'}; {'id': '5', 'type': 'block', 'children': ['6', '12', '25', '34', '42']}; {'id': '6', 'type': 'import_statement', 'children': ['7']}; {'id': '7', 'type': 'aliased_import', 'children': ['8', '11']}; {'id': '8', 'type': 'dotted_name', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'lxml'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'etree'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'etree'}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}; {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'root_tag'}; {'id': '15', 'type': 'subscript', 'children': ['16', '24']}; {'id': '16', 'type': 'call', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}; {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'xml_dict'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '23', 'type': 'argument_list', 'children': []}; {'id': '24', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '28', 'type': 'call', 'children': ['29', '32']}; {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'etree'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'Element'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'root_tag'}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}; {'id': '35', 'type': 'call', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': '_dict_to_xml_recurse'}; {'id': '37', 'type': 'argument_list', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '39', 'type': 'subscript', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'xml_dict'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'root_tag'}; {'id': '42', 'type': 'return_statement', 'children': ['43']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'root'}
|
Converts a dictionary to an XML ElementTree Element
|
def _mirbase_stats(data, out_dir):
utils.safe_makedir(out_dir)
out_file = os.path.join(out_dir, "%s_bcbio_mirbase.txt" % dd.get_sample_name(data))
out_file_novel = os.path.join(out_dir, "%s_bcbio_mirdeeep2.txt" % dd.get_sample_name(data))
mirbase_fn = data.get("seqbuster", None)
if mirbase_fn:
_get_stats_from_miraligner(mirbase_fn, out_file, "seqbuster")
mirdeep_fn = data.get("seqbuster_novel", None)
if mirdeep_fn:
_get_stats_from_miraligner(mirdeep_fn, out_file_novel, "mirdeep2")
return {"base": out_file, "secondary": [out_file_novel]}
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_mirbase_stats'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'out_dir'}; {'id': '6', 'type': 'block', 'children': ['7', '14', '33', '52', '62', '72', '82', '92']}; {'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': 'utils'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'safe_makedir'}; {'id': '12', 'type': 'argument_list', 'children': ['13']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'out_dir'}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}; {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'out_file'}; {'id': '17', 'type': 'call', 'children': ['18', '23']}; {'id': '18', 'type': 'attribute', 'children': ['19', '22']}; {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '23', 'type': 'argument_list', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'out_dir'}; {'id': '25', 'type': 'binary_operator', 'children': ['26', '27'], 'value': '%'}; {'id': '26', 'type': 'string', 'children': [], 'value': '"%s_bcbio_mirbase.txt"'}; {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'dd'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'get_sample_name'}; {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'out_file_novel'}; {'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': 'os'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '42', 'type': 'argument_list', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'out_dir'}; {'id': '44', 'type': 'binary_operator', 'children': ['45', '46'], 'value': '%'}; {'id': '45', 'type': 'string', 'children': [], 'value': '"%s_bcbio_mirdeeep2.txt"'}; {'id': '46', 'type': 'call', 'children': ['47', '50']}; {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'dd'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'get_sample_name'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}; {'id': '53', 'type': 'assignment', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'mirbase_fn'}; {'id': '55', 'type': 'call', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '59', 'type': 'argument_list', 'children': ['60', '61']}; {'id': '60', 'type': 'string', 'children': [], 'value': '"seqbuster"'}; {'id': '61', 'type': 'None', 'children': []}; {'id': '62', 'type': 'if_statement', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'mirbase_fn'}; {'id': '64', 'type': 'block', 'children': ['65']}; {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'call', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': '_get_stats_from_miraligner'}; {'id': '68', 'type': 'argument_list', 'children': ['69', '70', '71']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'mirbase_fn'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'out_file'}; {'id': '71', 'type': 'string', 'children': [], 'value': '"seqbuster"'}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}; {'id': '73', 'type': 'assignment', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'mirdeep_fn'}; {'id': '75', 'type': 'call', 'children': ['76', '79']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '79', 'type': 'argument_list', 'children': ['80', '81']}; {'id': '80', 'type': 'string', 'children': [], 'value': '"seqbuster_novel"'}; {'id': '81', 'type': 'None', 'children': []}; {'id': '82', 'type': 'if_statement', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'mirdeep_fn'}; {'id': '84', 'type': 'block', 'children': ['85']}; {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'call', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': '_get_stats_from_miraligner'}; {'id': '88', 'type': 'argument_list', 'children': ['89', '90', '91']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'mirdeep_fn'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'out_file_novel'}; {'id': '91', 'type': 'string', 'children': [], 'value': '"mirdeep2"'}; {'id': '92', 'type': 'return_statement', 'children': ['93']}; {'id': '93', 'type': 'dictionary', 'children': ['94', '97']}; {'id': '94', 'type': 'pair', 'children': ['95', '96']}; {'id': '95', 'type': 'string', 'children': [], 'value': '"base"'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'out_file'}; {'id': '97', 'type': 'pair', 'children': ['98', '99']}; {'id': '98', 'type': 'string', 'children': [], 'value': '"secondary"'}; {'id': '99', 'type': 'list', 'children': ['100'], 'value': '[out_file_novel]'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'out_file_novel'}
|
Create stats from miraligner
|
def _glob_events_files(self, paths, recursive):
event_files = []
for path in paths:
dirs = tf.gfile.Glob(path)
dirs = filter(lambda x: tf.gfile.IsDirectory(x), dirs)
for dir in dirs:
if recursive:
dir_files_pair = [(root, filenames) for root, _, filenames in tf.gfile.Walk(dir)]
else:
dir_files_pair = [(dir, tf.gfile.ListDirectory(dir))]
for root, filenames in dir_files_pair:
file_names = fnmatch.filter(filenames, '*.tfevents.*')
file_paths = [os.path.join(root, x) for x in file_names]
file_paths = filter(lambda x: not tf.gfile.IsDirectory(x), file_paths)
event_files += file_paths
return event_files
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_glob_events_files'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'paths'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'recursive'}; {'id': '7', 'type': 'block', 'children': ['8', '12', '143']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'event_files'}; {'id': '11', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '12', 'type': 'for_statement', 'children': ['13', '14', '15']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'paths'}; {'id': '15', 'type': 'block', 'children': ['16', '27', '45']}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}; {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'dirs'}; {'id': '19', 'type': 'call', 'children': ['20', '25']}; {'id': '20', 'type': 'attribute', 'children': ['21', '24']}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'tf'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'gfile'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'Glob'}; {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'dirs'}; {'id': '30', 'type': 'call', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'filter'}; {'id': '32', 'type': 'argument_list', 'children': ['33', '44']}; {'id': '33', 'type': 'lambda', 'children': ['34', '36']}; {'id': '34', 'type': 'lambda_parameters', 'children': ['35']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'x'}; {'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': 'tf'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'gfile'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'IsDirectory'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'dirs'}; {'id': '45', 'type': 'for_statement', 'children': ['46', '47', '48']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'dir'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'dirs'}; {'id': '48', 'type': 'block', 'children': ['49', '88']}; {'id': '49', 'type': 'if_statement', 'children': ['50', '51', '72']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'recursive'}; {'id': '51', 'type': 'block', 'children': ['52']}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}; {'id': '53', 'type': 'assignment', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'dir_files_pair'}; {'id': '55', 'type': 'list_comprehension', 'children': ['56', '59']}; {'id': '56', 'type': 'tuple', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'filenames'}; {'id': '59', 'type': 'for_in_clause', 'children': ['60', '64']}; {'id': '60', 'type': 'pattern_list', 'children': ['61', '62', '63']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'filenames'}; {'id': '64', 'type': 'call', 'children': ['65', '70']}; {'id': '65', 'type': 'attribute', 'children': ['66', '69']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'tf'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'gfile'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'Walk'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'dir'}; {'id': '72', 'type': 'else_clause', 'children': ['73']}; {'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': 'dir_files_pair'}; {'id': '77', 'type': 'list', 'children': ['78'], 'value': '[(dir, tf.gfile.ListDirectory(dir))]'}; {'id': '78', 'type': 'tuple', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'dir'}; {'id': '80', 'type': 'call', 'children': ['81', '86']}; {'id': '81', 'type': 'attribute', 'children': ['82', '85']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'tf'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'gfile'}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'ListDirectory'}; {'id': '86', 'type': 'argument_list', 'children': ['87']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'dir'}; {'id': '88', 'type': 'for_statement', 'children': ['89', '92', '93']}; {'id': '89', 'type': 'pattern_list', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'filenames'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'dir_files_pair'}; {'id': '93', 'type': 'block', 'children': ['94', '104', '120', '139']}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}; {'id': '95', 'type': 'assignment', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'file_names'}; {'id': '97', 'type': 'call', 'children': ['98', '101']}; {'id': '98', 'type': 'attribute', 'children': ['99', '100']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'fnmatch'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'filter'}; {'id': '101', 'type': 'argument_list', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'filenames'}; {'id': '103', 'type': 'string', 'children': [], 'value': "'*.tfevents.*'"}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}; {'id': '105', 'type': 'assignment', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'file_paths'}; {'id': '107', 'type': 'list_comprehension', 'children': ['108', '117']}; {'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': 'os'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '114', 'type': 'argument_list', 'children': ['115', '116']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '117', 'type': 'for_in_clause', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'file_names'}; {'id': '120', 'type': 'expression_statement', 'children': ['121']}; {'id': '121', 'type': 'assignment', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'file_paths'}; {'id': '123', 'type': 'call', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'filter'}; {'id': '125', 'type': 'argument_list', 'children': ['126', '138']}; {'id': '126', 'type': 'lambda', 'children': ['127', '129']}; {'id': '127', 'type': 'lambda_parameters', 'children': ['128']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '129', 'type': 'not_operator', 'children': ['130']}; {'id': '130', 'type': 'call', 'children': ['131', '136']}; {'id': '131', 'type': 'attribute', 'children': ['132', '135']}; {'id': '132', 'type': 'attribute', 'children': ['133', '134']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'tf'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'gfile'}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'IsDirectory'}; {'id': '136', 'type': 'argument_list', 'children': ['137']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'file_paths'}; {'id': '139', 'type': 'expression_statement', 'children': ['140']}; {'id': '140', 'type': 'augmented_assignment', 'children': ['141', '142'], 'value': '+='}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'event_files'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'file_paths'}; {'id': '143', 'type': 'return_statement', 'children': ['144']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'event_files'}
|
Find all tf events files under a list of paths recursively.
|
def guess_python_env():
version, major, minor = get_version_info()
if 'PyPy' in version:
return 'pypy3' if major == 3 else 'pypy'
return 'py{major}{minor}'.format(major=major, minor=minor)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '4']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'guess_python_env'}; {'id': '3', 'type': 'parameters', 'children': []}; {'id': '4', 'type': 'block', 'children': ['5', '14', '26']}; {'id': '5', 'type': 'expression_statement', 'children': ['6']}; {'id': '6', 'type': 'assignment', 'children': ['7', '11']}; {'id': '7', 'type': 'pattern_list', 'children': ['8', '9', '10']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'version'}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'major'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'minor'}; {'id': '11', 'type': 'call', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'get_version_info'}; {'id': '13', 'type': 'argument_list', 'children': []}; {'id': '14', 'type': 'if_statement', 'children': ['15', '18']}; {'id': '15', 'type': 'comparison_operator', 'children': ['16', '17'], 'value': 'in'}; {'id': '16', 'type': 'string', 'children': [], 'value': "'PyPy'"}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'version'}; {'id': '18', 'type': 'block', 'children': ['19']}; {'id': '19', 'type': 'return_statement', 'children': ['20']}; {'id': '20', 'type': 'conditional_expression', 'children': ['21', '22', '25'], 'value': 'if'}; {'id': '21', 'type': 'string', 'children': [], 'value': "'pypy3'"}; {'id': '22', 'type': 'comparison_operator', 'children': ['23', '24'], 'value': '=='}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'major'}; {'id': '24', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '25', 'type': 'string', 'children': [], 'value': "'pypy'"}; {'id': '26', 'type': 'return_statement', 'children': ['27']}; {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'string', 'children': [], 'value': "'py{major}{minor}'"}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '31', 'type': 'argument_list', 'children': ['32', '35']}; {'id': '32', 'type': 'keyword_argument', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'major'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'major'}; {'id': '35', 'type': 'keyword_argument', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'minor'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'minor'}
|
Guess the default python env to use.
|
def edit_line(self, line):
for code, code_obj in self.code_objs.items():
line = self.__edit_line(line, code, code_obj)
return line
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'edit_line'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '6', 'type': 'block', 'children': ['7', '30']}; {'id': '7', 'type': 'for_statement', 'children': ['8', '11', '18']}; {'id': '8', 'type': 'pattern_list', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'code'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'code_obj'}; {'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': 'code_objs'}; {'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': 'assignment', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'line'}; {'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': '__edit_line'}; {'id': '26', 'type': 'argument_list', 'children': ['27', '28', '29']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'code'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'code_obj'}; {'id': '30', 'type': 'return_statement', 'children': ['31']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'line'}
|
Edit a single line using the code expression.
|
def _LogInvalidRunLevels(states, valid):
invalid = set()
for state in states:
if state not in valid:
invalid.add(state)
if invalid:
logging.warning("Invalid init runlevel(s) encountered: %s",
", ".join(invalid))
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_LogInvalidRunLevels'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'states'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'valid'}; {'id': '6', 'type': 'block', 'children': ['7', '13', '29']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'invalid'}; {'id': '10', 'type': 'call', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '12', 'type': 'argument_list', 'children': []}; {'id': '13', 'type': 'for_statement', 'children': ['14', '15', '16']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'state'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'states'}; {'id': '16', 'type': 'block', 'children': ['17']}; {'id': '17', 'type': 'if_statement', 'children': ['18', '21']}; {'id': '18', 'type': 'comparison_operator', 'children': ['19', '20'], 'value': 'not in'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'state'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'valid'}; {'id': '21', 'type': 'block', 'children': ['22']}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}; {'id': '23', 'type': 'call', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'invalid'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'state'}; {'id': '29', 'type': 'if_statement', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'invalid'}; {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}; {'id': '33', 'type': 'call', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '37', 'type': 'argument_list', 'children': ['38', '39']}; {'id': '38', 'type': 'string', 'children': [], 'value': '"Invalid init runlevel(s) encountered: %s"'}; {'id': '39', 'type': 'call', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}; {'id': '41', 'type': 'string', 'children': [], 'value': '", "'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'invalid'}
|
Log any invalid run states found.
|
def allows_simple_recursion(self):
rec_level = self.aggregate.config["recursionlevel"]
if rec_level >= 0 and self.recursion_level >= rec_level:
log.debug(LOG_CHECK, "... no, maximum recursion level reached.")
return False
if self.extern[0]:
log.debug(LOG_CHECK, "... no, extern.")
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': 'allows_simple_recursion'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '16', '37', '54']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'rec_level'}; {'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': 'aggregate'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '15', 'type': 'string', 'children': [], 'value': '"recursionlevel"'}; {'id': '16', 'type': 'if_statement', 'children': ['17', '26']}; {'id': '17', 'type': 'boolean_operator', 'children': ['18', '21'], 'value': 'and'}; {'id': '18', 'type': 'comparison_operator', 'children': ['19', '20'], 'value': '>='}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'rec_level'}; {'id': '20', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '21', 'type': 'comparison_operator', 'children': ['22', '25'], 'value': '>='}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'recursion_level'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'rec_level'}; {'id': '26', 'type': 'block', 'children': ['27', '35']}; {'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': 'log'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '32', 'type': 'argument_list', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'LOG_CHECK'}; {'id': '34', 'type': 'string', 'children': [], 'value': '"... no, maximum recursion level reached."'}; {'id': '35', 'type': 'return_statement', 'children': ['36']}; {'id': '36', 'type': 'False', 'children': []}; {'id': '37', 'type': 'if_statement', 'children': ['38', '43']}; {'id': '38', 'type': 'subscript', 'children': ['39', '42']}; {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'extern'}; {'id': '42', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '43', 'type': 'block', 'children': ['44', '52']}; {'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': 'log'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '49', 'type': 'argument_list', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'LOG_CHECK'}; {'id': '51', 'type': 'string', 'children': [], 'value': '"... no, extern."'}; {'id': '52', 'type': 'return_statement', 'children': ['53']}; {'id': '53', 'type': 'False', 'children': []}; {'id': '54', 'type': 'return_statement', 'children': ['55']}; {'id': '55', 'type': 'True', 'children': []}
|
Check recursion level and extern status.
|
def extract_fields(d, fields, delimiter='|'):
rd = {}
for f in fields:
v = d.get(f, None)
if isinstance(v, (str, unicode)):
v = v.encode('utf8')
elif isinstance(v, list):
v = delimiter.join(v)
rd[f] = v
return rd
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'extract_fields'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'fields'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'delimiter'}; {'id': '8', 'type': 'string', 'children': [], 'value': "'|'"}; {'id': '9', 'type': 'block', 'children': ['10', '14', '68']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}; {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'rd'}; {'id': '13', 'type': 'dictionary', 'children': []}; {'id': '14', 'type': 'for_statement', 'children': ['15', '16', '17']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'fields'}; {'id': '17', 'type': 'block', 'children': ['18', '28', '62']}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}; {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '21', 'type': 'call', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '25', 'type': 'argument_list', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '27', 'type': 'None', 'children': []}; {'id': '28', 'type': 'if_statement', 'children': ['29', '36', '46']}; {'id': '29', 'type': 'call', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '31', 'type': 'argument_list', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '33', 'type': 'tuple', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'unicode'}; {'id': '36', 'type': 'block', 'children': ['37']}; {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '40', 'type': 'call', 'children': ['41', '44']}; {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'encode'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}; {'id': '45', 'type': 'string', 'children': [], 'value': "'utf8'"}; {'id': '46', 'type': 'elif_clause', 'children': ['47', '52']}; {'id': '47', 'type': 'call', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '49', 'type': 'argument_list', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'list'}; {'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': 'v'}; {'id': '56', 'type': 'call', 'children': ['57', '60']}; {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'delimiter'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}; {'id': '63', 'type': 'assignment', 'children': ['64', '67']}; {'id': '64', 'type': 'subscript', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'rd'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '68', 'type': 'return_statement', 'children': ['69']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'rd'}
|
get values out of an object ``d`` for saving to a csv
|
def middleware_class(api=None):
def decorator(middleware_class):
apply_to_api = hug.API(api) if api else hug.api.from_object(middleware_class)
apply_to_api.http.add_middleware(middleware_class())
return middleware_class
return decorator
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'middleware_class'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'default_parameter', 'children': ['5', '6']}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'api'}; {'id': '6', 'type': 'None', 'children': []}; {'id': '7', 'type': 'block', 'children': ['8', '45']}; {'id': '8', 'type': 'function_definition', 'children': ['9', '10', '12']}; {'id': '9', 'type': 'function_name', 'children': [], 'value': 'decorator'}; {'id': '10', 'type': 'parameters', 'children': ['11']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'middleware_class'}; {'id': '12', 'type': 'block', 'children': ['13', '32', '43']}; {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'apply_to_api'}; {'id': '16', 'type': 'conditional_expression', 'children': ['17', '23', '24'], 'value': 'if'}; {'id': '17', 'type': 'call', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'hug'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'API'}; {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'api'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'api'}; {'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': 'hug'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'api'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'from_object'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'middleware_class'}; {'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': 'apply_to_api'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'http'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'add_middleware'}; {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'call', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'middleware_class'}; {'id': '42', 'type': 'argument_list', 'children': []}; {'id': '43', 'type': 'return_statement', 'children': ['44']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'middleware_class'}; {'id': '45', 'type': 'return_statement', 'children': ['46']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'decorator'}
|
Registers a middleware class
|
def dinfflowdir(np, filleddem, flowangle, slope, workingdir=None, mpiexedir=None, exedir=None,
log_file=None, runtime_file=None, hostfile=None):
fname = TauDEM.func_name('dinfflowdir')
return TauDEM.run(FileClass.get_executable_fullpath(fname, exedir),
{'-fel': filleddem}, workingdir,
None,
{'-ang': flowangle, '-slp': slope},
{'mpipath': mpiexedir, 'hostfile': hostfile, 'n': np},
{'logfile': log_file, 'runtimefile': runtime_file})
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '26']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'dinfflowdir'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '11', '14', '17', '20', '23']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'filleddem'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'flowangle'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'slope'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'workingdir'}; {'id': '10', 'type': 'None', 'children': []}; {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'mpiexedir'}; {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'exedir'}; {'id': '16', 'type': 'None', 'children': []}; {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'log_file'}; {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'runtime_file'}; {'id': '22', 'type': 'None', 'children': []}; {'id': '23', 'type': 'default_parameter', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'hostfile'}; {'id': '25', 'type': 'None', 'children': []}; {'id': '26', 'type': 'block', 'children': ['27', '36']}; {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'fname'}; {'id': '30', 'type': 'call', 'children': ['31', '34']}; {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'TauDEM'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'func_name'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}; {'id': '35', 'type': 'string', 'children': [], 'value': "'dinfflowdir'"}; {'id': '36', 'type': 'return_statement', 'children': ['37']}; {'id': '37', 'type': 'call', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'TauDEM'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'run'}; {'id': '41', 'type': 'argument_list', 'children': ['42', '49', '53', '54', '55', '62', '72']}; {'id': '42', 'type': 'call', 'children': ['43', '46']}; {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'FileClass'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'get_executable_fullpath'}; {'id': '46', 'type': 'argument_list', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'fname'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'exedir'}; {'id': '49', 'type': 'dictionary', 'children': ['50']}; {'id': '50', 'type': 'pair', 'children': ['51', '52']}; {'id': '51', 'type': 'string', 'children': [], 'value': "'-fel'"}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'filleddem'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'workingdir'}; {'id': '54', 'type': 'None', 'children': []}; {'id': '55', 'type': 'dictionary', 'children': ['56', '59']}; {'id': '56', 'type': 'pair', 'children': ['57', '58']}; {'id': '57', 'type': 'string', 'children': [], 'value': "'-ang'"}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'flowangle'}; {'id': '59', 'type': 'pair', 'children': ['60', '61']}; {'id': '60', 'type': 'string', 'children': [], 'value': "'-slp'"}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'slope'}; {'id': '62', 'type': 'dictionary', 'children': ['63', '66', '69']}; {'id': '63', 'type': 'pair', 'children': ['64', '65']}; {'id': '64', 'type': 'string', 'children': [], 'value': "'mpipath'"}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'mpiexedir'}; {'id': '66', 'type': 'pair', 'children': ['67', '68']}; {'id': '67', 'type': 'string', 'children': [], 'value': "'hostfile'"}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'hostfile'}; {'id': '69', 'type': 'pair', 'children': ['70', '71']}; {'id': '70', 'type': 'string', 'children': [], 'value': "'n'"}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '72', 'type': 'dictionary', 'children': ['73', '76']}; {'id': '73', 'type': 'pair', 'children': ['74', '75']}; {'id': '74', 'type': 'string', 'children': [], 'value': "'logfile'"}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'log_file'}; {'id': '76', 'type': 'pair', 'children': ['77', '78']}; {'id': '77', 'type': 'string', 'children': [], 'value': "'runtimefile'"}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'runtime_file'}
|
Run Dinf flow direction
|
def stick_perm(presenter, egg, dist_dict, strategy):
np.random.seed()
egg_pres, egg_rec, egg_features, egg_dist_funcs = parse_egg(egg)
regg = order_stick(presenter, egg, dist_dict, strategy)
regg_pres, regg_rec, regg_features, regg_dist_funcs = parse_egg(regg)
regg_pres = list(regg_pres)
egg_pres = list(egg_pres)
idx = [egg_pres.index(r) for r in regg_pres]
weights = compute_feature_weights_dict(list(regg_pres), list(regg_pres), list(regg_features), dist_dict)
orders = idx
return weights, orders
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'stick_perm'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'presenter'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'egg'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'dist_dict'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'strategy'}; {'id': '8', 'type': 'block', 'children': ['9', '17', '28', '38', '49', '56', '63', '76', '95', '99']}; {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'call', 'children': ['11', '16']}; {'id': '11', 'type': 'attribute', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'random'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'seed'}; {'id': '16', 'type': 'argument_list', 'children': []}; {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '24']}; {'id': '19', 'type': 'pattern_list', 'children': ['20', '21', '22', '23']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'egg_pres'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'egg_rec'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'egg_features'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'egg_dist_funcs'}; {'id': '24', 'type': 'call', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'parse_egg'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'egg'}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}; {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'regg'}; {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'order_stick'}; {'id': '33', 'type': 'argument_list', 'children': ['34', '35', '36', '37']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'presenter'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'egg'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'dist_dict'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'strategy'}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}; {'id': '39', 'type': 'assignment', 'children': ['40', '45']}; {'id': '40', 'type': 'pattern_list', 'children': ['41', '42', '43', '44']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'regg_pres'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'regg_rec'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'regg_features'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'regg_dist_funcs'}; {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'parse_egg'}; {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'regg'}; {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'regg_pres'}; {'id': '52', 'type': 'call', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'regg_pres'}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}; {'id': '57', 'type': 'assignment', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'egg_pres'}; {'id': '59', 'type': 'call', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '61', 'type': 'argument_list', 'children': ['62']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'egg_pres'}; {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '66', 'type': 'list_comprehension', 'children': ['67', '73']}; {'id': '67', 'type': 'call', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'egg_pres'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '73', 'type': 'for_in_clause', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'regg_pres'}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}; {'id': '77', 'type': 'assignment', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'weights'}; {'id': '79', 'type': 'call', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'compute_feature_weights_dict'}; {'id': '81', 'type': 'argument_list', 'children': ['82', '86', '90', '94']}; {'id': '82', 'type': 'call', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '84', 'type': 'argument_list', 'children': ['85']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'regg_pres'}; {'id': '86', 'type': 'call', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '88', 'type': 'argument_list', 'children': ['89']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'regg_pres'}; {'id': '90', 'type': 'call', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '92', 'type': 'argument_list', 'children': ['93']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'regg_features'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'dist_dict'}; {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'assignment', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'orders'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '99', 'type': 'return_statement', 'children': ['100']}; {'id': '100', 'type': 'expression_list', 'children': ['101', '102']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'weights'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'orders'}
|
Computes weights for one reordering using stick-breaking method
|
def create(model_config, batch_size, normalize=True, num_workers=0, augmentations=None):
path = model_config.data_dir('mnist')
train_dataset = datasets.MNIST(path, train=True, download=True)
test_dataset = datasets.MNIST(path, train=False, download=True)
augmentations = [ToArray()] + (augmentations if augmentations is not None else [])
if normalize:
train_data = train_dataset.train_data
mean_value = (train_data.double() / 255).mean().item()
std_value = (train_data.double() / 255).std().item()
augmentations.append(Normalize(mean=mean_value, std=std_value, tags=['train', 'val']))
augmentations.append(ToTensor())
return TrainingData(
train_dataset,
test_dataset,
num_workers=num_workers,
batch_size=batch_size,
augmentations=augmentations
)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'create'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'model_config'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'batch_size'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'normalize'}; {'id': '8', 'type': 'True', 'children': []}; {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'num_workers'}; {'id': '11', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'augmentations'}; {'id': '14', 'type': 'None', 'children': []}; {'id': '15', 'type': 'block', 'children': ['16', '25', '40', '55', '70', '137', '146']}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}; {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'model_config'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'data_dir'}; {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'string', 'children': [], 'value': "'mnist'"}; {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'train_dataset'}; {'id': '28', 'type': 'call', 'children': ['29', '32']}; {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'datasets'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'MNIST'}; {'id': '32', 'type': 'argument_list', 'children': ['33', '34', '37']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '34', 'type': 'keyword_argument', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'train'}; {'id': '36', 'type': 'True', 'children': []}; {'id': '37', 'type': 'keyword_argument', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'download'}; {'id': '39', 'type': 'True', 'children': []}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}; {'id': '41', 'type': 'assignment', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'test_dataset'}; {'id': '43', 'type': 'call', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'datasets'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'MNIST'}; {'id': '47', 'type': 'argument_list', 'children': ['48', '49', '52']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '49', 'type': 'keyword_argument', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'train'}; {'id': '51', 'type': 'False', 'children': []}; {'id': '52', 'type': 'keyword_argument', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'download'}; {'id': '54', 'type': 'True', 'children': []}; {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'augmentations'}; {'id': '58', 'type': 'binary_operator', 'children': ['59', '63'], 'value': '+'}; {'id': '59', 'type': 'list', 'children': ['60'], 'value': '[ToArray()]'}; {'id': '60', 'type': 'call', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'ToArray'}; {'id': '62', 'type': 'argument_list', 'children': []}; {'id': '63', 'type': '()', 'children': ['64']}; {'id': '64', 'type': 'conditional_expression', 'children': ['65', '66', '69'], 'value': 'if'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'augmentations'}; {'id': '66', 'type': 'comparison_operator', 'children': ['67', '68'], 'value': 'is not'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'augmentations'}; {'id': '68', 'type': 'None', 'children': []}; {'id': '69', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '70', 'type': 'if_statement', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'normalize'}; {'id': '72', 'type': 'block', 'children': ['73', '79', '98', '117']}; {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'assignment', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'train_data'}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'train_dataset'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'train_data'}; {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'mean_value'}; {'id': '82', 'type': 'call', 'children': ['83', '97']}; {'id': '83', 'type': 'attribute', 'children': ['84', '96']}; {'id': '84', 'type': 'call', 'children': ['85', '95']}; {'id': '85', 'type': 'attribute', 'children': ['86', '94']}; {'id': '86', 'type': '()', 'children': ['87']}; {'id': '87', 'type': 'binary_operator', 'children': ['88', '93'], 'value': '/'}; {'id': '88', 'type': 'call', 'children': ['89', '92']}; {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'train_data'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'double'}; {'id': '92', 'type': 'argument_list', 'children': []}; {'id': '93', 'type': 'integer', 'children': [], 'value': '255'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'mean'}; {'id': '95', 'type': 'argument_list', 'children': []}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '97', 'type': 'argument_list', 'children': []}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}; {'id': '99', 'type': 'assignment', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'std_value'}; {'id': '101', 'type': 'call', 'children': ['102', '116']}; {'id': '102', 'type': 'attribute', 'children': ['103', '115']}; {'id': '103', 'type': 'call', 'children': ['104', '114']}; {'id': '104', 'type': 'attribute', 'children': ['105', '113']}; {'id': '105', 'type': '()', 'children': ['106']}; {'id': '106', 'type': 'binary_operator', 'children': ['107', '112'], 'value': '/'}; {'id': '107', 'type': 'call', 'children': ['108', '111']}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'train_data'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'double'}; {'id': '111', 'type': 'argument_list', 'children': []}; {'id': '112', 'type': 'integer', 'children': [], 'value': '255'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'std'}; {'id': '114', 'type': 'argument_list', 'children': []}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '116', 'type': 'argument_list', 'children': []}; {'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': 'augmentations'}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '122', 'type': 'argument_list', 'children': ['123']}; {'id': '123', 'type': 'call', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'Normalize'}; {'id': '125', 'type': 'argument_list', 'children': ['126', '129', '132']}; {'id': '126', 'type': 'keyword_argument', 'children': ['127', '128']}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'mean'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'mean_value'}; {'id': '129', 'type': 'keyword_argument', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'std'}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'std_value'}; {'id': '132', 'type': 'keyword_argument', 'children': ['133', '134']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'tags'}; {'id': '134', 'type': 'list', 'children': ['135', '136'], 'value': "['train', 'val']"}; {'id': '135', 'type': 'string', 'children': [], 'value': "'train'"}; {'id': '136', 'type': 'string', 'children': [], 'value': "'val'"}; {'id': '137', 'type': 'expression_statement', 'children': ['138']}; {'id': '138', 'type': 'call', 'children': ['139', '142']}; {'id': '139', 'type': 'attribute', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'augmentations'}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '142', 'type': 'argument_list', 'children': ['143']}; {'id': '143', 'type': 'call', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'ToTensor'}; {'id': '145', 'type': 'argument_list', 'children': []}; {'id': '146', 'type': 'return_statement', 'children': ['147']}; {'id': '147', 'type': 'call', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'TrainingData'}; {'id': '149', 'type': 'argument_list', 'children': ['150', '151', '152', '155', '158']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'train_dataset'}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'test_dataset'}; {'id': '152', 'type': 'keyword_argument', 'children': ['153', '154']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'num_workers'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'num_workers'}; {'id': '155', 'type': 'keyword_argument', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'batch_size'}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'batch_size'}; {'id': '158', 'type': 'keyword_argument', 'children': ['159', '160']}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'augmentations'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'augmentations'}
|
Create a MNIST dataset, normalized
|
def __we_c(cls, calib, tc, temp, we_v):
offset_v = calib.pid_elc_mv / 1000.0
response_v = we_v - offset_v
response_c = tc.correct(temp, response_v)
if response_c is None:
return None
we_c = response_c + offset_v
return we_c
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '__we_c'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'calib'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'tc'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'temp'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'we_v'}; {'id': '9', 'type': 'block', 'children': ['10', '18', '24', '34', '41', '47']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}; {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'offset_v'}; {'id': '13', 'type': 'binary_operator', 'children': ['14', '17'], 'value': '/'}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'calib'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'pid_elc_mv'}; {'id': '17', 'type': 'float', 'children': [], 'value': '1000.0'}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}; {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'response_v'}; {'id': '21', 'type': 'binary_operator', 'children': ['22', '23'], 'value': '-'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'we_v'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'offset_v'}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}; {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'response_c'}; {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'tc'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'correct'}; {'id': '31', 'type': 'argument_list', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'temp'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'response_v'}; {'id': '34', 'type': 'if_statement', 'children': ['35', '38']}; {'id': '35', 'type': 'comparison_operator', 'children': ['36', '37'], 'value': 'is'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'response_c'}; {'id': '37', 'type': 'None', 'children': []}; {'id': '38', 'type': 'block', 'children': ['39']}; {'id': '39', 'type': 'return_statement', 'children': ['40']}; {'id': '40', 'type': 'None', 'children': []}; {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'we_c'}; {'id': '44', 'type': 'binary_operator', 'children': ['45', '46'], 'value': '+'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'response_c'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'offset_v'}; {'id': '47', 'type': 'return_statement', 'children': ['48']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'we_c'}
|
Compute weC from sensor temperature compensation of weV
|
def repackage_var(h):
if IS_TORCH_04: return h.detach() if type(h) == torch.Tensor else tuple(repackage_var(v) for v in h)
else: return Variable(h.data) if type(h) == Variable else tuple(repackage_var(v) for v in h)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'repackage_var'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'h'}; {'id': '5', 'type': 'block', 'children': ['6']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '8', '34']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'IS_TORCH_04'}; {'id': '8', 'type': 'block', 'children': ['9']}; {'id': '9', 'type': 'return_statement', 'children': ['10']}; {'id': '10', 'type': 'conditional_expression', 'children': ['11', '16', '24'], 'value': 'if'}; {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'h'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'detach'}; {'id': '15', 'type': 'argument_list', 'children': []}; {'id': '16', 'type': 'comparison_operator', 'children': ['17', '21'], 'value': '=='}; {'id': '17', 'type': 'call', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'h'}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'torch'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'Tensor'}; {'id': '24', 'type': 'call', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '26', 'type': 'generator_expression', 'children': ['27', '31']}; {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'repackage_var'}; {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '31', 'type': 'for_in_clause', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'h'}; {'id': '34', 'type': 'else_clause', 'children': ['35']}; {'id': '35', 'type': 'block', 'children': ['36']}; {'id': '36', 'type': 'return_statement', 'children': ['37']}; {'id': '37', 'type': 'conditional_expression', 'children': ['38', '44', '50'], 'value': 'if'}; {'id': '38', 'type': 'call', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'Variable'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}; {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'h'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '44', 'type': 'comparison_operator', 'children': ['45', '49'], 'value': '=='}; {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'h'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'Variable'}; {'id': '50', 'type': 'call', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '52', 'type': 'generator_expression', 'children': ['53', '57']}; {'id': '53', 'type': 'call', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'repackage_var'}; {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '57', 'type': 'for_in_clause', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'h'}
|
Wraps h in new Variables, to detach them from their history.
|
def finalize(self, params, rep):
if params.get("saveNet", True):
saveDir = os.path.join(params["path"], params["name"],
"model_{}.pt".format(rep))
torch.save(self.model, saveDir)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'finalize'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'rep'}; {'id': '7', 'type': 'block', 'children': ['8']}; {'id': '8', 'type': 'if_statement', 'children': ['9', '16']}; {'id': '9', 'type': 'call', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '13', 'type': 'argument_list', 'children': ['14', '15']}; {'id': '14', 'type': 'string', 'children': [], 'value': '"saveNet"'}; {'id': '15', 'type': 'True', 'children': []}; {'id': '16', 'type': 'block', 'children': ['17', '39']}; {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'saveDir'}; {'id': '20', 'type': 'call', 'children': ['21', '26']}; {'id': '21', 'type': 'attribute', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '26', 'type': 'argument_list', 'children': ['27', '30', '33']}; {'id': '27', 'type': 'subscript', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '29', 'type': 'string', 'children': [], 'value': '"path"'}; {'id': '30', 'type': 'subscript', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '32', 'type': 'string', 'children': [], 'value': '"name"'}; {'id': '33', 'type': 'call', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}; {'id': '35', 'type': 'string', 'children': [], 'value': '"model_{}.pt"'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'rep'}; {'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': 'torch'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'save'}; {'id': '44', 'type': 'argument_list', 'children': ['45', '48']}; {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'saveDir'}
|
Save the full model once we are done.
|
def _edit_config(xpath, element):
query = {'type': 'config',
'action': 'edit',
'xpath': xpath,
'element': element}
response = __proxy__['panos.call'](query)
return _validate_response(response)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_edit_config'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'xpath'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'element'}; {'id': '6', 'type': 'block', 'children': ['7', '23', '32']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '10', 'type': 'dictionary', 'children': ['11', '14', '17', '20']}; {'id': '11', 'type': 'pair', 'children': ['12', '13']}; {'id': '12', 'type': 'string', 'children': [], 'value': "'type'"}; {'id': '13', 'type': 'string', 'children': [], 'value': "'config'"}; {'id': '14', 'type': 'pair', 'children': ['15', '16']}; {'id': '15', 'type': 'string', 'children': [], 'value': "'action'"}; {'id': '16', 'type': 'string', 'children': [], 'value': "'edit'"}; {'id': '17', 'type': 'pair', 'children': ['18', '19']}; {'id': '18', 'type': 'string', 'children': [], 'value': "'xpath'"}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'xpath'}; {'id': '20', 'type': 'pair', 'children': ['21', '22']}; {'id': '21', 'type': 'string', 'children': [], 'value': "'element'"}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'element'}; {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '26', 'type': 'call', 'children': ['27', '30']}; {'id': '27', 'type': 'subscript', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': '__proxy__'}; {'id': '29', 'type': 'string', 'children': [], 'value': "'panos.call'"}; {'id': '30', 'type': 'argument_list', 'children': ['31']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '32', 'type': 'return_statement', 'children': ['33']}; {'id': '33', 'type': 'call', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': '_validate_response'}; {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'response'}
|
Sends an edit request to the device.
|
def multiply(a, col):
a = a.reshape(4, 4, 4)
col = col.reshape(4, 8)
return fcat(
rowxcol(a[0], col),
rowxcol(a[1], col),
rowxcol(a[2], col),
rowxcol(a[3], col),
)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'multiply'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'col'}; {'id': '6', 'type': 'block', 'children': ['7', '18', '28']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '10', 'type': 'call', 'children': ['11', '14']}; {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'reshape'}; {'id': '14', 'type': 'argument_list', 'children': ['15', '16', '17']}; {'id': '15', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '16', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '17', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}; {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'col'}; {'id': '21', 'type': 'call', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'col'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'reshape'}; {'id': '25', 'type': 'argument_list', 'children': ['26', '27']}; {'id': '26', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '27', 'type': 'integer', 'children': [], 'value': '8'}; {'id': '28', 'type': 'return_statement', 'children': ['29']}; {'id': '29', 'type': 'call', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'fcat'}; {'id': '31', 'type': 'argument_list', 'children': ['32', '39', '46', '53']}; {'id': '32', 'type': 'call', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'rowxcol'}; {'id': '34', 'type': 'argument_list', 'children': ['35', '38']}; {'id': '35', 'type': 'subscript', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '37', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'col'}; {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'rowxcol'}; {'id': '41', 'type': 'argument_list', 'children': ['42', '45']}; {'id': '42', 'type': 'subscript', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '44', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'col'}; {'id': '46', 'type': 'call', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'rowxcol'}; {'id': '48', 'type': 'argument_list', 'children': ['49', '52']}; {'id': '49', 'type': 'subscript', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '51', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'col'}; {'id': '53', 'type': 'call', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'rowxcol'}; {'id': '55', 'type': 'argument_list', 'children': ['56', '59']}; {'id': '56', 'type': 'subscript', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '58', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'col'}
|
Multiply a matrix by one column.
|
def run_get_clusters_from_file(self, clusters_infile, all_ref_seqs, rename_dict=None):
if rename_dict is None:
rename_dict = {}
seq_reader = pyfastaq.sequences.file_reader(self.infile)
names_list_from_fasta_file = [seq.id for seq in seq_reader]
names_set_from_fasta_file = set(names_list_from_fasta_file)
clusters = self._load_user_clusters_file(clusters_infile, all_ref_seqs, rename_dict=rename_dict)
if len(names_set_from_fasta_file) != len(names_list_from_fasta_file):
raise Error('At least one duplicate name in fasta file ' + self.infile + '. Cannot continue')
names_from_clusters_file = set()
for new_names in clusters.values():
names_from_clusters_file.update(new_names)
if not names_set_from_fasta_file.issubset(names_from_clusters_file):
raise Error('Some names in fasta file "' + self.infile + '" not given in cluster file. Cannot continue')
return clusters
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'run_get_clusters_from_file'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'clusters_infile'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'all_ref_seqs'}; {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'rename_dict'}; {'id': '9', 'type': 'None', 'children': []}; {'id': '10', 'type': 'block', 'children': ['11', '20', '33', '43', '50', '63', '85', '91', '106', '126']}; {'id': '11', 'type': 'if_statement', 'children': ['12', '15']}; {'id': '12', 'type': 'comparison_operator', 'children': ['13', '14'], 'value': 'is'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'rename_dict'}; {'id': '14', 'type': 'None', 'children': []}; {'id': '15', 'type': 'block', 'children': ['16']}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}; {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'rename_dict'}; {'id': '19', 'type': 'dictionary', 'children': []}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}; {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'seq_reader'}; {'id': '23', 'type': 'call', 'children': ['24', '29']}; {'id': '24', 'type': 'attribute', 'children': ['25', '28']}; {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'pyfastaq'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'sequences'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'file_reader'}; {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'infile'}; {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'names_list_from_fasta_file'}; {'id': '36', 'type': 'list_comprehension', 'children': ['37', '40']}; {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '40', 'type': 'for_in_clause', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'seq_reader'}; {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'names_set_from_fasta_file'}; {'id': '46', 'type': 'call', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'names_list_from_fasta_file'}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}; {'id': '51', 'type': 'assignment', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'clusters'}; {'id': '53', 'type': 'call', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': '_load_user_clusters_file'}; {'id': '57', 'type': 'argument_list', 'children': ['58', '59', '60']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'clusters_infile'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'all_ref_seqs'}; {'id': '60', 'type': 'keyword_argument', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'rename_dict'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'rename_dict'}; {'id': '63', 'type': 'if_statement', 'children': ['64', '73']}; {'id': '64', 'type': 'comparison_operator', 'children': ['65', '69'], 'value': '!='}; {'id': '65', 'type': 'call', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'names_set_from_fasta_file'}; {'id': '69', 'type': 'call', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'names_list_from_fasta_file'}; {'id': '73', 'type': 'block', 'children': ['74']}; {'id': '74', 'type': 'raise_statement', 'children': ['75']}; {'id': '75', 'type': 'call', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'Error'}; {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'binary_operator', 'children': ['79', '84'], 'value': '+'}; {'id': '79', 'type': 'binary_operator', 'children': ['80', '81'], 'value': '+'}; {'id': '80', 'type': 'string', 'children': [], 'value': "'At least one duplicate name in fasta file '"}; {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'infile'}; {'id': '84', 'type': 'string', 'children': [], 'value': "'. Cannot continue'"}; {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'assignment', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'names_from_clusters_file'}; {'id': '88', 'type': 'call', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '90', 'type': 'argument_list', 'children': []}; {'id': '91', 'type': 'for_statement', 'children': ['92', '93', '98']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'new_names'}; {'id': '93', 'type': 'call', 'children': ['94', '97']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'clusters'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '97', 'type': 'argument_list', 'children': []}; {'id': '98', 'type': 'block', 'children': ['99']}; {'id': '99', 'type': 'expression_statement', 'children': ['100']}; {'id': '100', 'type': 'call', 'children': ['101', '104']}; {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'names_from_clusters_file'}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '104', 'type': 'argument_list', 'children': ['105']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'new_names'}; {'id': '106', 'type': 'if_statement', 'children': ['107', '114']}; {'id': '107', 'type': 'not_operator', 'children': ['108']}; {'id': '108', 'type': 'call', 'children': ['109', '112']}; {'id': '109', 'type': 'attribute', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'names_set_from_fasta_file'}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'issubset'}; {'id': '112', 'type': 'argument_list', 'children': ['113']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'names_from_clusters_file'}; {'id': '114', 'type': 'block', 'children': ['115']}; {'id': '115', 'type': 'raise_statement', 'children': ['116']}; {'id': '116', 'type': 'call', 'children': ['117', '118']}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'Error'}; {'id': '118', 'type': 'argument_list', 'children': ['119']}; {'id': '119', 'type': 'binary_operator', 'children': ['120', '125'], 'value': '+'}; {'id': '120', 'type': 'binary_operator', 'children': ['121', '122'], 'value': '+'}; {'id': '121', 'type': 'string', 'children': [], 'value': '\'Some names in fasta file "\''}; {'id': '122', 'type': 'attribute', 'children': ['123', '124']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'infile'}; {'id': '125', 'type': 'string', 'children': [], 'value': '\'" not given in cluster file. Cannot continue\''}; {'id': '126', 'type': 'return_statement', 'children': ['127']}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'clusters'}
|
Instead of running cdhit, gets the clusters info from the input file.
|
def image_load_time(self):
load_times = self.get_load_times('image')
return round(mean(load_times), self.decimal_precision)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'image_load_time'}; {'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': 'load_times'}; {'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_load_times'}; {'id': '13', 'type': 'argument_list', 'children': ['14']}; {'id': '14', 'type': 'string', 'children': [], 'value': "'image'"}; {'id': '15', 'type': 'return_statement', 'children': ['16']}; {'id': '16', 'type': 'call', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'round'}; {'id': '18', 'type': 'argument_list', 'children': ['19', '23']}; {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'mean'}; {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'load_times'}; {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'decimal_precision'}
|
Returns aggregate image load time for all pages.
|
def run(self, stdscr):
self.win = stdscr
curses.curs_set(0)
stdscr.timeout(0)
curses.init_pair(1, curses.COLOR_CYAN, curses.COLOR_BLACK)
curses.init_pair(2, curses.COLOR_GREEN, curses.COLOR_BLACK)
curses.init_pair(3, curses.COLOR_YELLOW, curses.COLOR_BLACK)
curses.init_pair(4, curses.COLOR_RED, curses.COLOR_BLACK)
while True:
self.refresh(True)
now = time.time()
while time.time() - now < self._refresh_rate:
time.sleep(0.1)
self.refresh(False)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'run'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'stdscr'}; {'id': '6', 'type': 'block', 'children': ['7', '13', '20', '27', '40', '53', '66', '79']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '12']}; {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'win'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'stdscr'}; {'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': 'curses'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'curs_set'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}; {'id': '19', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}; {'id': '21', 'type': 'call', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'stdscr'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'timeout'}; {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'integer', 'children': [], 'value': '0'}; {'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': 'curses'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'init_pair'}; {'id': '32', 'type': 'argument_list', 'children': ['33', '34', '37']}; {'id': '33', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'curses'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'COLOR_CYAN'}; {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'curses'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'COLOR_BLACK'}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}; {'id': '41', 'type': 'call', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'curses'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'init_pair'}; {'id': '45', 'type': 'argument_list', 'children': ['46', '47', '50']}; {'id': '46', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'curses'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'COLOR_GREEN'}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'curses'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'COLOR_BLACK'}; {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'call', 'children': ['55', '58']}; {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'curses'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'init_pair'}; {'id': '58', 'type': 'argument_list', 'children': ['59', '60', '63']}; {'id': '59', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'curses'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'COLOR_YELLOW'}; {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'curses'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'COLOR_BLACK'}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}; {'id': '67', 'type': 'call', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'curses'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'init_pair'}; {'id': '71', 'type': 'argument_list', 'children': ['72', '73', '76']}; {'id': '72', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'curses'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'COLOR_RED'}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'curses'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'COLOR_BLACK'}; {'id': '79', 'type': 'while_statement', 'children': ['80', '81']}; {'id': '80', 'type': 'True', 'children': []}; {'id': '81', 'type': 'block', 'children': ['82', '89', '97']}; {'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': 'self'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'refresh'}; {'id': '87', 'type': 'argument_list', 'children': ['88']}; {'id': '88', 'type': 'True', 'children': []}; {'id': '89', 'type': 'expression_statement', 'children': ['90']}; {'id': '90', 'type': 'assignment', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'now'}; {'id': '92', 'type': 'call', 'children': ['93', '96']}; {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '96', 'type': 'argument_list', 'children': []}; {'id': '97', 'type': 'while_statement', 'children': ['98', '109']}; {'id': '98', 'type': 'comparison_operator', 'children': ['99', '106'], 'value': '<'}; {'id': '99', 'type': 'binary_operator', 'children': ['100', '105'], 'value': '-'}; {'id': '100', 'type': 'call', 'children': ['101', '104']}; {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '104', 'type': 'argument_list', 'children': []}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'now'}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': '_refresh_rate'}; {'id': '109', 'type': 'block', 'children': ['110', '117']}; {'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': 'time'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'sleep'}; {'id': '115', 'type': 'argument_list', 'children': ['116']}; {'id': '116', 'type': 'float', 'children': [], 'value': '0.1'}; {'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': 'self'}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'refresh'}; {'id': '122', 'type': 'argument_list', 'children': ['123']}; {'id': '123', 'type': 'False', 'children': []}
|
Initialize curses and refresh in a loop
|
def configure(self, address):
global nanoconfig_started
if len(self._endpoints):
raise ValueError("Nanoconfig address must be sole endpoint")
endpoint_id = _nn_check_positive_rtn(
wrapper.nc_configure(self.fd, address)
)
if not nanoconfig_started:
nanoconfig_started = True
ep = Socket.NanoconfigEndpoint(self, endpoint_id, address)
self._endpoints.append(ep)
return ep
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'configure'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'address'}; {'id': '6', 'type': 'block', 'children': ['7', '9', '22', '37', '45', '56', '65']}; {'id': '7', 'type': 'global_statement', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'nanoconfig_started'}; {'id': '9', 'type': 'if_statement', 'children': ['10', '16']}; {'id': '10', 'type': 'call', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '12', 'type': 'argument_list', 'children': ['13']}; {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': '_endpoints'}; {'id': '16', 'type': 'block', 'children': ['17']}; {'id': '17', 'type': 'raise_statement', 'children': ['18']}; {'id': '18', 'type': 'call', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}; {'id': '21', 'type': 'string', 'children': [], 'value': '"Nanoconfig address must be sole endpoint"'}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}; {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'endpoint_id'}; {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': '_nn_check_positive_rtn'}; {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'call', 'children': ['29', '32']}; {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'wrapper'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'nc_configure'}; {'id': '32', 'type': 'argument_list', 'children': ['33', '36']}; {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'fd'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'address'}; {'id': '37', 'type': 'if_statement', 'children': ['38', '40']}; {'id': '38', 'type': 'not_operator', 'children': ['39']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'nanoconfig_started'}; {'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': 'nanoconfig_started'}; {'id': '44', 'type': 'True', 'children': []}; {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'ep'}; {'id': '48', 'type': 'call', 'children': ['49', '52']}; {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'Socket'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'NanoconfigEndpoint'}; {'id': '52', 'type': 'argument_list', 'children': ['53', '54', '55']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'endpoint_id'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'address'}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}; {'id': '57', 'type': 'call', 'children': ['58', '63']}; {'id': '58', 'type': 'attribute', 'children': ['59', '62']}; {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': '_endpoints'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'ep'}; {'id': '65', 'type': 'return_statement', 'children': ['66']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'ep'}
|
Configure socket's addresses with nanoconfig
|
def tree_iter_nexson_proxy(nexson_proxy):
nexml_el = nexson_proxy._nexml_el
tg_order = nexml_el['^ot:treesElementOrder']
tgd = nexml_el['treesById']
for tg_id in tg_order:
tg = tgd[tg_id]
tree_order = tg['^ot:treeElementOrder']
tbid = tg['treeById']
otus = tg['@otus']
for k in tree_order:
v = tbid[k]
yield nexson_proxy._create_tree_proxy(tree_id=k, tree=v, otus=otus)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'tree_iter_nexson_proxy'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'nexson_proxy'}; {'id': '5', 'type': 'block', 'children': ['6', '12', '18', '24']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'nexml_el'}; {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'nexson_proxy'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': '_nexml_el'}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}; {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'tg_order'}; {'id': '15', 'type': 'subscript', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'nexml_el'}; {'id': '17', 'type': 'string', 'children': [], 'value': "'^ot:treesElementOrder'"}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}; {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'tgd'}; {'id': '21', 'type': 'subscript', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'nexml_el'}; {'id': '23', 'type': 'string', 'children': [], 'value': "'treesById'"}; {'id': '24', 'type': 'for_statement', 'children': ['25', '26', '27']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'tg_id'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'tg_order'}; {'id': '27', 'type': 'block', 'children': ['28', '34', '40', '46', '52']}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}; {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'tg'}; {'id': '31', 'type': 'subscript', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'tgd'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'tg_id'}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}; {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'tree_order'}; {'id': '37', 'type': 'subscript', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'tg'}; {'id': '39', 'type': 'string', 'children': [], 'value': "'^ot:treeElementOrder'"}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}; {'id': '41', 'type': 'assignment', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'tbid'}; {'id': '43', 'type': 'subscript', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'tg'}; {'id': '45', 'type': 'string', 'children': [], 'value': "'treeById'"}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}; {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'otus'}; {'id': '49', 'type': 'subscript', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'tg'}; {'id': '51', 'type': 'string', 'children': [], 'value': "'@otus'"}; {'id': '52', 'type': 'for_statement', 'children': ['53', '54', '55']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'tree_order'}; {'id': '55', 'type': 'block', 'children': ['56', '62']}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}; {'id': '57', 'type': 'assignment', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '59', 'type': 'subscript', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'tbid'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}; {'id': '63', 'type': 'yield', 'children': ['64']}; {'id': '64', 'type': 'call', 'children': ['65', '68']}; {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'nexson_proxy'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': '_create_tree_proxy'}; {'id': '68', 'type': 'argument_list', 'children': ['69', '72', '75']}; {'id': '69', 'type': 'keyword_argument', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'tree_id'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '72', 'type': 'keyword_argument', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'tree'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '75', 'type': 'keyword_argument', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'otus'}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'otus'}
|
Iterates over NexsonTreeProxy objects in order determined by the nexson blob
|
def cmd_wrapper(cmd_name, **kwds):
cmd = si.Commands(cmd_name)
if not cmd:
raise Exception(cmd_name + " doesnt found!")
for arg in cmd.Arguments:
value = kwds.get(arg.Name)
if value:
arg.Value = value
return cmd.Execute()
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'cmd_wrapper'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cmd_name'}; {'id': '5', 'type': 'dictionary_splat_pattern', 'children': ['6']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'kwds'}; {'id': '7', 'type': 'block', 'children': ['8', '17', '28', '54']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'si'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'Commands'}; {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'cmd_name'}; {'id': '17', 'type': 'if_statement', 'children': ['18', '20']}; {'id': '18', 'type': 'not_operator', 'children': ['19']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '20', 'type': 'block', 'children': ['21']}; {'id': '21', 'type': 'raise_statement', 'children': ['22']}; {'id': '22', 'type': 'call', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}; {'id': '25', 'type': 'binary_operator', 'children': ['26', '27'], 'value': '+'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'cmd_name'}; {'id': '27', 'type': 'string', 'children': [], 'value': '" doesnt found!"'}; {'id': '28', 'type': 'for_statement', 'children': ['29', '30', '33']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'arg'}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'Arguments'}; {'id': '33', 'type': 'block', 'children': ['34', '45']}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}; {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '37', 'type': 'call', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'kwds'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'arg'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'Name'}; {'id': '45', 'type': 'if_statement', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '47', 'type': 'block', 'children': ['48']}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}; {'id': '49', 'type': 'assignment', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'arg'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'Value'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '54', 'type': 'return_statement', 'children': ['55']}; {'id': '55', 'type': 'call', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'Execute'}; {'id': '59', 'type': 'argument_list', 'children': []}
|
Wrap and execute a softimage command accepting named arguments
|
def verify_enroll(self, response):
seed = session.pop('_u2f_enroll_')
try:
new_device, cert = complete_register(seed, response, self.__facets_list)
except Exception as e:
if self.__call_fail_enroll:
self.__call_fail_enroll(e)
return {
'status' : 'failed',
'error' : 'Invalid key handle!'
}
finally:
pass
devices = self.__get_u2f_devices()
new_device['counter'] = 0
new_device['index'] = 0
for device in devices:
if new_device['index'] <= device['index']:
new_device['index'] = device['index'] + 1
devices.append(new_device)
self.__save_u2f_devices(devices)
self.__call_success_enroll()
return {'status': 'ok', 'message': 'Successfully enrolled new U2F device!'}
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'verify_enroll'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '6', 'type': 'block', 'children': ['7', '16', '60', '68', '74', '80', '103', '110', '117', '123']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'seed'}; {'id': '10', 'type': 'call', 'children': ['11', '14']}; {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'session'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}; {'id': '15', 'type': 'string', 'children': [], 'value': "'_u2f_enroll_'"}; {'id': '16', 'type': 'try_statement', 'children': ['17', '31', '57']}; {'id': '17', 'type': 'block', 'children': ['18']}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}; {'id': '19', 'type': 'assignment', 'children': ['20', '23']}; {'id': '20', 'type': 'pattern_list', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'new_device'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'cert'}; {'id': '23', 'type': 'call', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'complete_register'}; {'id': '25', 'type': 'argument_list', 'children': ['26', '27', '28']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'seed'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': '__facets_list'}; {'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': 'e'}; {'id': '36', 'type': 'block', 'children': ['37', '49']}; {'id': '37', 'type': 'if_statement', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': '__call_fail_enroll'}; {'id': '41', 'type': 'block', 'children': ['42']}; {'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': 'self'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': '__call_fail_enroll'}; {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '49', 'type': 'return_statement', 'children': ['50']}; {'id': '50', 'type': 'dictionary', 'children': ['51', '54']}; {'id': '51', 'type': 'pair', 'children': ['52', '53']}; {'id': '52', 'type': 'string', 'children': [], 'value': "'status'"}; {'id': '53', 'type': 'string', 'children': [], 'value': "'failed'"}; {'id': '54', 'type': 'pair', 'children': ['55', '56']}; {'id': '55', 'type': 'string', 'children': [], 'value': "'error'"}; {'id': '56', 'type': 'string', 'children': [], 'value': "'Invalid key handle!'"}; {'id': '57', 'type': 'finally_clause', 'children': ['58']}; {'id': '58', 'type': 'block', 'children': ['59']}; {'id': '59', 'type': 'pass_statement', 'children': []}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}; {'id': '61', 'type': 'assignment', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'devices'}; {'id': '63', 'type': 'call', 'children': ['64', '67']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': '__get_u2f_devices'}; {'id': '67', 'type': 'argument_list', 'children': []}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}; {'id': '69', 'type': 'assignment', 'children': ['70', '73']}; {'id': '70', 'type': 'subscript', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'new_device'}; {'id': '72', 'type': 'string', 'children': [], 'value': "'counter'"}; {'id': '73', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}; {'id': '75', 'type': 'assignment', 'children': ['76', '79']}; {'id': '76', 'type': 'subscript', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'new_device'}; {'id': '78', 'type': 'string', 'children': [], 'value': "'index'"}; {'id': '79', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '80', 'type': 'for_statement', 'children': ['81', '82', '83']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'device'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'devices'}; {'id': '83', 'type': 'block', 'children': ['84']}; {'id': '84', 'type': 'if_statement', 'children': ['85', '92']}; {'id': '85', 'type': 'comparison_operator', 'children': ['86', '89'], 'value': '<='}; {'id': '86', 'type': 'subscript', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'new_device'}; {'id': '88', 'type': 'string', 'children': [], 'value': "'index'"}; {'id': '89', 'type': 'subscript', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'device'}; {'id': '91', 'type': 'string', 'children': [], 'value': "'index'"}; {'id': '92', 'type': 'block', 'children': ['93']}; {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'assignment', 'children': ['95', '98']}; {'id': '95', 'type': 'subscript', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'new_device'}; {'id': '97', 'type': 'string', 'children': [], 'value': "'index'"}; {'id': '98', 'type': 'binary_operator', 'children': ['99', '102'], 'value': '+'}; {'id': '99', 'type': 'subscript', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'device'}; {'id': '101', 'type': 'string', 'children': [], 'value': "'index'"}; {'id': '102', 'type': 'integer', 'children': [], 'value': '1'}; {'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': 'devices'}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '108', 'type': 'argument_list', 'children': ['109']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'new_device'}; {'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': 'self'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': '__save_u2f_devices'}; {'id': '115', 'type': 'argument_list', 'children': ['116']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'devices'}; {'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': 'self'}; {'id': '121', 'type': 'identifier', 'children': [], 'value': '__call_success_enroll'}; {'id': '122', 'type': 'argument_list', 'children': []}; {'id': '123', 'type': 'return_statement', 'children': ['124']}; {'id': '124', 'type': 'dictionary', 'children': ['125', '128']}; {'id': '125', 'type': 'pair', 'children': ['126', '127']}; {'id': '126', 'type': 'string', 'children': [], 'value': "'status'"}; {'id': '127', 'type': 'string', 'children': [], 'value': "'ok'"}; {'id': '128', 'type': 'pair', 'children': ['129', '130']}; {'id': '129', 'type': 'string', 'children': [], 'value': "'message'"}; {'id': '130', 'type': 'string', 'children': [], 'value': "'Successfully enrolled new U2F device!'"}
|
Verifies and saves U2F enroll
|
def info(args):
session = c.Session(args)
if "all" in args["names"]:
feeds = session.list_feeds()
else:
feeds = args["names"]
for feed in feeds:
aux.pretty_print(session, feed)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'info'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '5', 'type': 'block', 'children': ['6', '15', '38']}; {'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', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'Session'}; {'id': '13', 'type': 'argument_list', 'children': ['14']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '15', 'type': 'if_statement', 'children': ['16', '21', '30']}; {'id': '16', 'type': 'comparison_operator', 'children': ['17', '18'], 'value': 'in'}; {'id': '17', 'type': 'string', 'children': [], 'value': '"all"'}; {'id': '18', 'type': 'subscript', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '20', 'type': 'string', 'children': [], 'value': '"names"'}; {'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': 'feeds'}; {'id': '25', 'type': 'call', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'session'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'list_feeds'}; {'id': '29', 'type': 'argument_list', 'children': []}; {'id': '30', 'type': 'else_clause', 'children': ['31']}; {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}; {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'feeds'}; {'id': '35', 'type': 'subscript', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '37', 'type': 'string', 'children': [], 'value': '"names"'}; {'id': '38', 'type': 'for_statement', 'children': ['39', '40', '41']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'feed'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'feeds'}; {'id': '41', 'type': 'block', 'children': ['42']}; {'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': 'aux'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'pretty_print'}; {'id': '47', 'type': 'argument_list', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'session'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'feed'}
|
Provide information of a number of feeds
|
def _raw_weights(self):
if self._debug:
return np.array([[],[],[],[]])
if not self._running:
raise ValueError('Weight sensor is not running!')
if len(self._weight_buffers) == 0:
time.sleep(0.3)
if len(self._weight_buffers) == 0:
raise ValueError('Weight sensor is not retrieving data!')
weights = np.array(self._weight_buffers)
return weights
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_raw_weights'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '22', '33', '65', '76']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '10']}; {'id': '7', 'type': 'attribute', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '9', 'type': 'identifier', 'children': [], 'value': '_debug'}; {'id': '10', 'type': 'block', 'children': ['11']}; {'id': '11', 'type': 'return_statement', 'children': ['12']}; {'id': '12', 'type': 'call', 'children': ['13', '16']}; {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '16', 'type': 'argument_list', 'children': ['17']}; {'id': '17', 'type': 'list', 'children': ['18', '19', '20', '21'], 'value': '[[],[],[],[]]'}; {'id': '18', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '19', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '20', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '21', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '22', 'type': 'if_statement', 'children': ['23', '27']}; {'id': '23', 'type': 'not_operator', 'children': ['24']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': '_running'}; {'id': '27', 'type': 'block', 'children': ['28']}; {'id': '28', 'type': 'raise_statement', 'children': ['29']}; {'id': '29', 'type': 'call', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'string', 'children': [], 'value': "'Weight sensor is not running!'"}; {'id': '33', 'type': 'if_statement', 'children': ['34', '42']}; {'id': '34', 'type': 'comparison_operator', 'children': ['35', '41'], 'value': '=='}; {'id': '35', 'type': 'call', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': '_weight_buffers'}; {'id': '41', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '42', 'type': 'block', 'children': ['43', '50']}; {'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': 'time'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'sleep'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}; {'id': '49', 'type': 'float', 'children': [], 'value': '0.3'}; {'id': '50', 'type': 'if_statement', 'children': ['51', '59']}; {'id': '51', 'type': 'comparison_operator', 'children': ['52', '58'], 'value': '=='}; {'id': '52', 'type': 'call', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}; {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': '_weight_buffers'}; {'id': '58', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '59', 'type': 'block', 'children': ['60']}; {'id': '60', 'type': 'raise_statement', 'children': ['61']}; {'id': '61', 'type': 'call', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'string', 'children': [], 'value': "'Weight sensor is not retrieving data!'"}; {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'weights'}; {'id': '68', 'type': 'call', 'children': ['69', '72']}; {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}; {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': '_weight_buffers'}; {'id': '76', 'type': 'return_statement', 'children': ['77']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'weights'}
|
Create a numpy array containing the raw sensor weights.
|
def binary_to_term(data):
if not isinstance(data, bytes):
raise ParseException('not bytes input')
size = len(data)
if size <= 1:
raise ParseException('null input')
if b_ord(data[0]) != _TAG_VERSION:
raise ParseException('invalid version')
try:
i, term = _binary_to_term(1, data)
if i != size:
raise ParseException('unparsed data')
return term
except struct.error:
raise ParseException('missing data')
except IndexError:
raise ParseException('missing data')
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'binary_to_term'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '5', 'type': 'block', 'children': ['6', '19', '26', '36', '51']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '13']}; {'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', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'bytes'}; {'id': '13', 'type': 'block', 'children': ['14']}; {'id': '14', 'type': 'raise_statement', 'children': ['15']}; {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'ParseException'}; {'id': '17', 'type': 'argument_list', 'children': ['18']}; {'id': '18', 'type': 'string', 'children': [], 'value': "'not bytes input'"}; {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'size'}; {'id': '22', 'type': 'call', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '26', 'type': 'if_statement', 'children': ['27', '30']}; {'id': '27', 'type': 'comparison_operator', 'children': ['28', '29'], 'value': '<='}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'size'}; {'id': '29', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '30', 'type': 'block', 'children': ['31']}; {'id': '31', 'type': 'raise_statement', 'children': ['32']}; {'id': '32', 'type': 'call', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'ParseException'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}; {'id': '35', 'type': 'string', 'children': [], 'value': "'null input'"}; {'id': '36', 'type': 'if_statement', 'children': ['37', '45']}; {'id': '37', 'type': 'comparison_operator', 'children': ['38', '44'], 'value': '!='}; {'id': '38', 'type': 'call', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'b_ord'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}; {'id': '41', 'type': 'subscript', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '43', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': '_TAG_VERSION'}; {'id': '45', 'type': 'block', 'children': ['46']}; {'id': '46', 'type': 'raise_statement', 'children': ['47']}; {'id': '47', 'type': 'call', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'ParseException'}; {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'string', 'children': [], 'value': "'invalid version'"}; {'id': '51', 'type': 'try_statement', 'children': ['52', '75', '85']}; {'id': '52', 'type': 'block', 'children': ['53', '63', '73']}; {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '58']}; {'id': '55', 'type': 'pattern_list', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'term'}; {'id': '58', 'type': 'call', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': '_binary_to_term'}; {'id': '60', 'type': 'argument_list', 'children': ['61', '62']}; {'id': '61', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '63', 'type': 'if_statement', 'children': ['64', '67']}; {'id': '64', 'type': 'comparison_operator', 'children': ['65', '66'], 'value': '!='}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'size'}; {'id': '67', 'type': 'block', 'children': ['68']}; {'id': '68', 'type': 'raise_statement', 'children': ['69']}; {'id': '69', 'type': 'call', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'ParseException'}; {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'string', 'children': [], 'value': "'unparsed data'"}; {'id': '73', 'type': 'return_statement', 'children': ['74']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'term'}; {'id': '75', 'type': 'except_clause', 'children': ['76', '79']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'struct'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '79', 'type': 'block', 'children': ['80']}; {'id': '80', 'type': 'raise_statement', 'children': ['81']}; {'id': '81', 'type': 'call', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'ParseException'}; {'id': '83', 'type': 'argument_list', 'children': ['84']}; {'id': '84', 'type': 'string', 'children': [], 'value': "'missing data'"}; {'id': '85', 'type': 'except_clause', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'IndexError'}; {'id': '87', 'type': 'block', 'children': ['88']}; {'id': '88', 'type': 'raise_statement', 'children': ['89']}; {'id': '89', 'type': 'call', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'ParseException'}; {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'string', 'children': [], 'value': "'missing data'"}
|
Decode Erlang terms within binary data into Python types
|
def geo_to_pixel(geo, level):
lat, lon = float(geo[0]), float(geo[1])
lat = TileSystem.clip(lat, TileSystem.LATITUDE_RANGE)
lon = TileSystem.clip(lon, TileSystem.LONGITUDE_RANGE)
x = (lon + 180) / 360
sin_lat = sin(lat * pi / 180)
y = 0.5 - log((1 + sin_lat) / (1 - sin_lat)) / (4 * pi)
map_size = TileSystem.map_size(level)
pixel_x = int(TileSystem.clip(x * map_size + 0.5, (0, map_size - 1)))
pixel_y = int(TileSystem.clip(y * map_size + 0.5, (0, map_size - 1)))
return pixel_x, pixel_y
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'geo_to_pixel'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'geo'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'level'}; {'id': '6', 'type': 'block', 'children': ['7', '25', '37', '49', '58', '69', '91', '100', '121', '142']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '12']}; {'id': '9', 'type': 'pattern_list', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'lat'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'lon'}; {'id': '12', 'type': 'expression_list', 'children': ['13', '19']}; {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'subscript', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'geo'}; {'id': '18', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'subscript', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'geo'}; {'id': '24', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'lat'}; {'id': '28', 'type': 'call', 'children': ['29', '32']}; {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'TileSystem'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'clip'}; {'id': '32', 'type': 'argument_list', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'lat'}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'TileSystem'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'LATITUDE_RANGE'}; {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'lon'}; {'id': '40', 'type': 'call', 'children': ['41', '44']}; {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'TileSystem'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'clip'}; {'id': '44', 'type': 'argument_list', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'lon'}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'TileSystem'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'LONGITUDE_RANGE'}; {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '52', 'type': 'binary_operator', 'children': ['53', '57'], 'value': '/'}; {'id': '53', 'type': '()', 'children': ['54']}; {'id': '54', 'type': 'binary_operator', 'children': ['55', '56'], 'value': '+'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'lon'}; {'id': '56', 'type': 'integer', 'children': [], 'value': '180'}; {'id': '57', 'type': 'integer', 'children': [], 'value': '360'}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}; {'id': '59', 'type': 'assignment', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'sin_lat'}; {'id': '61', 'type': 'call', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'sin'}; {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'binary_operator', 'children': ['65', '68'], 'value': '/'}; {'id': '65', 'type': 'binary_operator', 'children': ['66', '67'], 'value': '*'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'lat'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'pi'}; {'id': '68', 'type': 'integer', 'children': [], 'value': '180'}; {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '72', 'type': 'binary_operator', 'children': ['73', '74'], 'value': '-'}; {'id': '73', 'type': 'float', 'children': [], 'value': '0.5'}; {'id': '74', 'type': 'binary_operator', 'children': ['75', '87'], 'value': '/'}; {'id': '75', 'type': 'call', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'log'}; {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'binary_operator', 'children': ['79', '83'], 'value': '/'}; {'id': '79', 'type': '()', 'children': ['80']}; {'id': '80', 'type': 'binary_operator', 'children': ['81', '82'], 'value': '+'}; {'id': '81', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'sin_lat'}; {'id': '83', 'type': '()', 'children': ['84']}; {'id': '84', 'type': 'binary_operator', 'children': ['85', '86'], 'value': '-'}; {'id': '85', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'sin_lat'}; {'id': '87', 'type': '()', 'children': ['88']}; {'id': '88', 'type': 'binary_operator', 'children': ['89', '90'], 'value': '*'}; {'id': '89', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'pi'}; {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'map_size'}; {'id': '94', 'type': 'call', 'children': ['95', '98']}; {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'TileSystem'}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'map_size'}; {'id': '98', 'type': 'argument_list', 'children': ['99']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'level'}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}; {'id': '101', 'type': 'assignment', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'pixel_x'}; {'id': '103', 'type': 'call', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '105', 'type': 'argument_list', 'children': ['106']}; {'id': '106', 'type': 'call', 'children': ['107', '110']}; {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'TileSystem'}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'clip'}; {'id': '110', 'type': 'argument_list', 'children': ['111', '116']}; {'id': '111', 'type': 'binary_operator', 'children': ['112', '115'], 'value': '+'}; {'id': '112', 'type': 'binary_operator', 'children': ['113', '114'], 'value': '*'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'map_size'}; {'id': '115', 'type': 'float', 'children': [], 'value': '0.5'}; {'id': '116', 'type': 'tuple', 'children': ['117', '118']}; {'id': '117', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '118', 'type': 'binary_operator', 'children': ['119', '120'], 'value': '-'}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'map_size'}; {'id': '120', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '121', 'type': 'expression_statement', 'children': ['122']}; {'id': '122', 'type': 'assignment', 'children': ['123', '124']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'pixel_y'}; {'id': '124', 'type': 'call', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '126', 'type': 'argument_list', 'children': ['127']}; {'id': '127', 'type': 'call', 'children': ['128', '131']}; {'id': '128', 'type': 'attribute', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'TileSystem'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'clip'}; {'id': '131', 'type': 'argument_list', 'children': ['132', '137']}; {'id': '132', 'type': 'binary_operator', 'children': ['133', '136'], 'value': '+'}; {'id': '133', 'type': 'binary_operator', 'children': ['134', '135'], 'value': '*'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'map_size'}; {'id': '136', 'type': 'float', 'children': [], 'value': '0.5'}; {'id': '137', 'type': 'tuple', 'children': ['138', '139']}; {'id': '138', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '139', 'type': 'binary_operator', 'children': ['140', '141'], 'value': '-'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'map_size'}; {'id': '141', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '142', 'type': 'return_statement', 'children': ['143']}; {'id': '143', 'type': 'expression_list', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'pixel_x'}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'pixel_y'}
|
Transform from geo coordinates to pixel coordinates
|
def check(self, feature):
mapper = feature.as_dataframe_mapper()
mapper.fit_transform(self.X, y=self.y)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'check'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'feature'}; {'id': '6', 'type': 'block', 'children': ['7', '15']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'mapper'}; {'id': '10', 'type': 'call', 'children': ['11', '14']}; {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'feature'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'as_dataframe_mapper'}; {'id': '14', 'type': 'argument_list', 'children': []}; {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'call', 'children': ['17', '20']}; {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'mapper'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'fit_transform'}; {'id': '20', 'type': 'argument_list', 'children': ['21', '24']}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '24', 'type': 'keyword_argument', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'y'}
|
Check that fit_transform can be called on reference data
|
def run_cli(
executable,
mets_url=None,
resolver=None,
workspace=None,
page_id=None,
log_level=None,
input_file_grp=None,
output_file_grp=None,
parameter=None,
working_dir=None,
):
workspace = _get_workspace(workspace, resolver, mets_url, working_dir)
args = [executable, '--working-dir', workspace.directory]
args += ['--mets', mets_url]
if log_level:
args += ['--log-level', log_level]
if page_id:
args += ['--page-id', page_id]
if input_file_grp:
args += ['--input-file-grp', input_file_grp]
if output_file_grp:
args += ['--output-file-grp', output_file_grp]
if parameter:
args += ['--parameter', parameter]
log.debug("Running subprocess '%s'", ' '.join(args))
return subprocess.call(args)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '32']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'run_cli'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26', '29']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'executable'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'mets_url'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'resolver'}; {'id': '10', 'type': 'None', 'children': []}; {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'workspace'}; {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'page_id'}; {'id': '16', 'type': 'None', 'children': []}; {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'log_level'}; {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'input_file_grp'}; {'id': '22', 'type': 'None', 'children': []}; {'id': '23', 'type': 'default_parameter', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'output_file_grp'}; {'id': '25', 'type': 'None', 'children': []}; {'id': '26', 'type': 'default_parameter', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'parameter'}; {'id': '28', 'type': 'None', 'children': []}; {'id': '29', 'type': 'default_parameter', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'working_dir'}; {'id': '31', 'type': 'None', 'children': []}; {'id': '32', 'type': 'block', 'children': ['33', '43', '52', '58', '67', '76', '85', '94', '103', '116']}; {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'workspace'}; {'id': '36', 'type': 'call', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': '_get_workspace'}; {'id': '38', 'type': 'argument_list', 'children': ['39', '40', '41', '42']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'workspace'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'resolver'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'mets_url'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'working_dir'}; {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '46', 'type': 'list', 'children': ['47', '48', '49'], 'value': "[executable, '--working-dir', workspace.directory]"}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'executable'}; {'id': '48', 'type': 'string', 'children': [], 'value': "'--working-dir'"}; {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'workspace'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'directory'}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}; {'id': '53', 'type': 'augmented_assignment', 'children': ['54', '55'], 'value': '+='}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '55', 'type': 'list', 'children': ['56', '57'], 'value': "['--mets', mets_url]"}; {'id': '56', 'type': 'string', 'children': [], 'value': "'--mets'"}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'mets_url'}; {'id': '58', 'type': 'if_statement', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'log_level'}; {'id': '60', 'type': 'block', 'children': ['61']}; {'id': '61', 'type': 'expression_statement', 'children': ['62']}; {'id': '62', 'type': 'augmented_assignment', 'children': ['63', '64'], 'value': '+='}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '64', 'type': 'list', 'children': ['65', '66'], 'value': "['--log-level', log_level]"}; {'id': '65', 'type': 'string', 'children': [], 'value': "'--log-level'"}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'log_level'}; {'id': '67', 'type': 'if_statement', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'page_id'}; {'id': '69', 'type': 'block', 'children': ['70']}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}; {'id': '71', 'type': 'augmented_assignment', 'children': ['72', '73'], 'value': '+='}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '73', 'type': 'list', 'children': ['74', '75'], 'value': "['--page-id', page_id]"}; {'id': '74', 'type': 'string', 'children': [], 'value': "'--page-id'"}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'page_id'}; {'id': '76', 'type': 'if_statement', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'input_file_grp'}; {'id': '78', 'type': 'block', 'children': ['79']}; {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'augmented_assignment', 'children': ['81', '82'], 'value': '+='}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '82', 'type': 'list', 'children': ['83', '84'], 'value': "['--input-file-grp', input_file_grp]"}; {'id': '83', 'type': 'string', 'children': [], 'value': "'--input-file-grp'"}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'input_file_grp'}; {'id': '85', 'type': 'if_statement', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'output_file_grp'}; {'id': '87', 'type': 'block', 'children': ['88']}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}; {'id': '89', 'type': 'augmented_assignment', 'children': ['90', '91'], 'value': '+='}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '91', 'type': 'list', 'children': ['92', '93'], 'value': "['--output-file-grp', output_file_grp]"}; {'id': '92', 'type': 'string', 'children': [], 'value': "'--output-file-grp'"}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'output_file_grp'}; {'id': '94', 'type': 'if_statement', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'parameter'}; {'id': '96', 'type': 'block', 'children': ['97']}; {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'augmented_assignment', 'children': ['99', '100'], 'value': '+='}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '100', 'type': 'list', 'children': ['101', '102'], 'value': "['--parameter', parameter]"}; {'id': '101', 'type': 'string', 'children': [], 'value': "'--parameter'"}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'parameter'}; {'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': 'log'}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '108', 'type': 'argument_list', 'children': ['109', '110']}; {'id': '109', 'type': 'string', 'children': [], 'value': '"Running subprocess \'%s\'"'}; {'id': '110', 'type': 'call', 'children': ['111', '114']}; {'id': '111', 'type': 'attribute', 'children': ['112', '113']}; {'id': '112', 'type': 'string', 'children': [], 'value': "' '"}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '114', 'type': 'argument_list', 'children': ['115']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '116', 'type': 'return_statement', 'children': ['117']}; {'id': '117', 'type': 'call', 'children': ['118', '121']}; {'id': '118', 'type': 'attribute', 'children': ['119', '120']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'subprocess'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'call'}; {'id': '121', 'type': 'argument_list', 'children': ['122']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'args'}
|
Create a workspace for mets_url and run MP CLI through it
|
def addStampAnnot(self, rect, stamp=0):
CheckParent(self)
val = _fitz.Page_addStampAnnot(self, rect, stamp)
if not val: return
val.thisown = True
val.parent = weakref.proxy(self)
self._annot_refs[id(val)] = val
return val
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'addStampAnnot'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'rect'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'stamp'}; {'id': '8', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '9', 'type': 'block', 'children': ['10', '15', '26', '31', '37', '48', '59']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}; {'id': '11', 'type': 'call', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'CheckParent'}; {'id': '13', 'type': 'argument_list', 'children': ['14']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '18', 'type': 'call', 'children': ['19', '22']}; {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': '_fitz'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'Page_addStampAnnot'}; {'id': '22', 'type': 'argument_list', 'children': ['23', '24', '25']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'rect'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'stamp'}; {'id': '26', 'type': 'if_statement', 'children': ['27', '29']}; {'id': '27', 'type': 'not_operator', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '29', 'type': 'block', 'children': ['30']}; {'id': '30', 'type': 'return_statement', 'children': []}; {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '36']}; {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'thisown'}; {'id': '36', 'type': 'True', 'children': []}; {'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': 'val'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '42', 'type': 'call', 'children': ['43', '46']}; {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'weakref'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'proxy'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}; {'id': '49', 'type': 'assignment', 'children': ['50', '58']}; {'id': '50', 'type': 'subscript', 'children': ['51', '54']}; {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': '_annot_refs'}; {'id': '54', 'type': 'call', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '59', 'type': 'return_statement', 'children': ['60']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'val'}
|
Add a 'rubber stamp' in a rectangle.
|
def grace_period(msg='', seconds=10):
import time
print(msg)
override = util_arg.get_argflag(('--yes', '--y', '-y'))
print('starting grace period')
if override:
print('ending based on command line flag')
return True
for count in reversed(range(1, seconds + 1)):
time.sleep(1)
print('%d' % (count,))
print('%d' % (0,))
print('grace period is over')
return True
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'grace_period'}; {'id': '3', 'type': 'parameters', 'children': ['4', '7']}; {'id': '4', 'type': 'default_parameter', 'children': ['5', '6']}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '6', 'type': 'string', 'children': [], 'value': "''"}; {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'seconds'}; {'id': '9', 'type': 'integer', 'children': [], 'value': '10'}; {'id': '10', 'type': 'block', 'children': ['11', '14', '19', '31', '36', '46', '74', '82', '87']}; {'id': '11', 'type': 'import_statement', 'children': ['12']}; {'id': '12', 'type': 'dotted_name', 'children': ['13']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}; {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '17', 'type': 'argument_list', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'override'}; {'id': '22', 'type': 'call', 'children': ['23', '26']}; {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'util_arg'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'get_argflag'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}; {'id': '27', 'type': 'tuple', 'children': ['28', '29', '30']}; {'id': '28', 'type': 'string', 'children': [], 'value': "'--yes'"}; {'id': '29', 'type': 'string', 'children': [], 'value': "'--y'"}; {'id': '30', 'type': 'string', 'children': [], 'value': "'-y'"}; {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'call', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}; {'id': '35', 'type': 'string', 'children': [], 'value': "'starting grace period'"}; {'id': '36', 'type': 'if_statement', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'override'}; {'id': '38', 'type': 'block', 'children': ['39', '44']}; {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'call', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}; {'id': '43', 'type': 'string', 'children': [], 'value': "'ending based on command line flag'"}; {'id': '44', 'type': 'return_statement', 'children': ['45']}; {'id': '45', 'type': 'True', 'children': []}; {'id': '46', 'type': 'for_statement', 'children': ['47', '48', '58']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '48', 'type': 'call', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'reversed'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}; {'id': '51', 'type': 'call', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '53', 'type': 'argument_list', 'children': ['54', '55']}; {'id': '54', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '55', 'type': 'binary_operator', 'children': ['56', '57'], 'value': '+'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'seconds'}; {'id': '57', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '58', 'type': 'block', 'children': ['59', '66']}; {'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': 'time'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'sleep'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}; {'id': '65', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}; {'id': '67', 'type': 'call', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '69', 'type': 'argument_list', 'children': ['70']}; {'id': '70', 'type': 'binary_operator', 'children': ['71', '72'], 'value': '%'}; {'id': '71', 'type': 'string', 'children': [], 'value': "'%d'"}; {'id': '72', 'type': 'tuple', 'children': ['73']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}; {'id': '75', 'type': 'call', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'binary_operator', 'children': ['79', '80'], 'value': '%'}; {'id': '79', 'type': 'string', 'children': [], 'value': "'%d'"}; {'id': '80', 'type': 'tuple', 'children': ['81']}; {'id': '81', 'type': 'integer', 'children': [], 'value': '0'}; {'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': 'string', 'children': [], 'value': "'grace period is over'"}; {'id': '87', 'type': 'return_statement', 'children': ['88']}; {'id': '88', 'type': 'True', 'children': []}
|
Gives user a window to stop a process before it happens
|
def left_button_down(self, obj, event_type):
click_pos = self.iren.GetEventPosition()
picker = vtk.vtkWorldPointPicker()
picker.Pick(click_pos[0], click_pos[1], 0, self.renderer)
self.pickpoint = np.asarray(picker.GetPickPosition()).reshape((-1, 3))
if np.any(np.isnan(self.pickpoint)):
self.pickpoint[:] = 0
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'left_button_down'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'event_type'}; {'id': '7', 'type': 'block', 'children': ['8', '18', '26', '42', '65']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'click_pos'}; {'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': 'iren'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'GetEventPosition'}; {'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': 'picker'}; {'id': '21', 'type': 'call', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'vtk'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'vtkWorldPointPicker'}; {'id': '25', 'type': 'argument_list', 'children': []}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}; {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'picker'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'Pick'}; {'id': '31', 'type': 'argument_list', 'children': ['32', '35', '38', '39']}; {'id': '32', 'type': 'subscript', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'click_pos'}; {'id': '34', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '35', 'type': 'subscript', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'click_pos'}; {'id': '37', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '38', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'renderer'}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}; {'id': '43', 'type': 'assignment', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'pickpoint'}; {'id': '47', 'type': 'call', 'children': ['48', '60']}; {'id': '48', 'type': 'attribute', 'children': ['49', '59']}; {'id': '49', 'type': 'call', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'asarray'}; {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'call', 'children': ['55', '58']}; {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'picker'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'GetPickPosition'}; {'id': '58', 'type': 'argument_list', 'children': []}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'reshape'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}; {'id': '61', 'type': 'tuple', 'children': ['62', '64']}; {'id': '62', 'type': 'unary_operator', 'children': ['63'], 'value': '-'}; {'id': '63', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '64', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '65', 'type': 'if_statement', 'children': ['66', '79']}; {'id': '66', 'type': 'call', 'children': ['67', '70']}; {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'any'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}; {'id': '71', 'type': 'call', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'isnan'}; {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'pickpoint'}; {'id': '79', 'type': 'block', 'children': ['80']}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}; {'id': '81', 'type': 'assignment', 'children': ['82', '88']}; {'id': '82', 'type': 'subscript', 'children': ['83', '86']}; {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'pickpoint'}; {'id': '86', 'type': 'slice', 'children': ['87']}; {'id': '87', 'type': 'colon', 'children': []}; {'id': '88', 'type': 'integer', 'children': [], 'value': '0'}
|
Register the event for a left button down click
|
def list_conditions(self, service_id, version_number):
content = self._fetch("/service/%s/version/%d/condition" % (service_id, version_number))
return map(lambda x: FastlyCondition(self, x), content)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'list_conditions'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'service_id'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'version_number'}; {'id': '7', 'type': 'block', 'children': ['8', '21']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'content'}; {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': '_fetch'}; {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'binary_operator', 'children': ['17', '18'], 'value': '%'}; {'id': '17', 'type': 'string', 'children': [], 'value': '"/service/%s/version/%d/condition"'}; {'id': '18', 'type': 'tuple', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'service_id'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'version_number'}; {'id': '21', 'type': 'return_statement', 'children': ['22']}; {'id': '22', 'type': 'call', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'map'}; {'id': '24', 'type': 'argument_list', 'children': ['25', '33']}; {'id': '25', 'type': 'lambda', 'children': ['26', '28']}; {'id': '26', 'type': 'lambda_parameters', 'children': ['27']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '28', 'type': 'call', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'FastlyCondition'}; {'id': '30', 'type': 'argument_list', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'content'}
|
Gets all conditions for a particular service and version.
|
def entries(self):
Tags = Query()
tag = self.table.get(Tags.name == self.name)
posts = tag['post_ids']
for id in posts:
post = self.db.posts.get(doc_id=id)
if not post:
raise ValueError("No post found for doc_id %s" % id)
yield Entry(os.path.join(CONFIG['content_root'], post['filename']), id)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'entries'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '12', '29', '35']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'Tags'}; {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'Query'}; {'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': 'tag'}; {'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': 'table'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'comparison_operator', 'children': ['23', '26'], 'value': '=='}; {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'Tags'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'posts'}; {'id': '32', 'type': 'subscript', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'id': '34', 'type': 'string', 'children': [], 'value': "'post_ids'"}; {'id': '35', 'type': 'for_statement', 'children': ['36', '37', '38']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'posts'}; {'id': '38', 'type': 'block', 'children': ['39', '54', '65']}; {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'post'}; {'id': '42', 'type': 'call', 'children': ['43', '50']}; {'id': '43', 'type': 'attribute', 'children': ['44', '49']}; {'id': '44', 'type': 'attribute', 'children': ['45', '48']}; {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'db'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'posts'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}; {'id': '51', 'type': 'keyword_argument', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'doc_id'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '54', 'type': 'if_statement', 'children': ['55', '57']}; {'id': '55', 'type': 'not_operator', 'children': ['56']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'post'}; {'id': '57', 'type': 'block', 'children': ['58']}; {'id': '58', 'type': 'raise_statement', 'children': ['59']}; {'id': '59', 'type': 'call', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '61', 'type': 'argument_list', 'children': ['62']}; {'id': '62', 'type': 'binary_operator', 'children': ['63', '64'], 'value': '%'}; {'id': '63', 'type': 'string', 'children': [], 'value': '"No post found for doc_id %s"'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'yield', 'children': ['67']}; {'id': '67', 'type': 'call', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'Entry'}; {'id': '69', 'type': 'argument_list', 'children': ['70', '83']}; {'id': '70', 'type': 'call', 'children': ['71', '76']}; {'id': '71', 'type': 'attribute', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '76', 'type': 'argument_list', 'children': ['77', '80']}; {'id': '77', 'type': 'subscript', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'CONFIG'}; {'id': '79', 'type': 'string', 'children': [], 'value': "'content_root'"}; {'id': '80', 'type': 'subscript', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'post'}; {'id': '82', 'type': 'string', 'children': [], 'value': "'filename'"}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'id'}
|
return the actual lists of entries tagged with
|
def kill(self, block=False, reason="unknown"):
current_greenletid = id(gevent.getcurrent())
trace = "Job killed: %s" % reason
for greenlet, job in context._GLOBAL_CONTEXT["greenlets"].values():
greenletid = id(greenlet)
if job and job.id == self.id and greenletid != current_greenletid:
greenlet.kill(block=block)
trace += "\n\n--- Greenlet %s ---\n" % greenletid
trace += "".join(traceback.format_stack(greenlet.gr_frame))
context._GLOBAL_CONTEXT["greenlets"].pop(greenletid, None)
if reason == "timeout" and self.data["status"] != "timeout":
updates = {
"exceptiontype": "TimeoutInterrupt",
"traceback": trace
}
self._save_status("timeout", updates=updates, exception=False)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'kill'}; {'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': 'False', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'reason'}; {'id': '10', 'type': 'string', 'children': [], 'value': '"unknown"'}; {'id': '11', 'type': 'block', 'children': ['12', '23', '29', '108']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}; {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'current_greenletid'}; {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '17', 'type': 'argument_list', 'children': ['18']}; {'id': '18', 'type': 'call', 'children': ['19', '22']}; {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'gevent'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'getcurrent'}; {'id': '22', 'type': 'argument_list', 'children': []}; {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'trace'}; {'id': '26', 'type': 'binary_operator', 'children': ['27', '28'], 'value': '%'}; {'id': '27', 'type': 'string', 'children': [], 'value': '"Job killed: %s"'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'reason'}; {'id': '29', 'type': 'for_statement', 'children': ['30', '33', '42']}; {'id': '30', 'type': 'pattern_list', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'greenlet'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'job'}; {'id': '33', 'type': 'call', 'children': ['34', '41']}; {'id': '34', 'type': 'attribute', 'children': ['35', '40']}; {'id': '35', 'type': 'subscript', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'context'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': '_GLOBAL_CONTEXT'}; {'id': '39', 'type': 'string', 'children': [], 'value': '"greenlets"'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '41', 'type': 'argument_list', 'children': []}; {'id': '42', 'type': 'block', 'children': ['43', '50', '96']}; {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'greenletid'}; {'id': '46', 'type': 'call', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'greenlet'}; {'id': '50', 'type': 'if_statement', 'children': ['51', '64']}; {'id': '51', 'type': 'boolean_operator', 'children': ['52', '61'], 'value': 'and'}; {'id': '52', 'type': 'boolean_operator', 'children': ['53', '54'], 'value': 'and'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'job'}; {'id': '54', 'type': 'comparison_operator', 'children': ['55', '58'], 'value': '=='}; {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'job'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '61', 'type': 'comparison_operator', 'children': ['62', '63'], 'value': '!='}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'greenletid'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'current_greenletid'}; {'id': '64', 'type': 'block', 'children': ['65', '74', '80']}; {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'call', 'children': ['67', '70']}; {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'greenlet'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'kill'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}; {'id': '71', 'type': 'keyword_argument', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'block'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'block'}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}; {'id': '75', 'type': 'augmented_assignment', 'children': ['76', '77'], 'value': '+='}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'trace'}; {'id': '77', 'type': 'binary_operator', 'children': ['78', '79'], 'value': '%'}; {'id': '78', 'type': 'string', 'children': [], 'value': '"\\n\\n--- Greenlet %s ---\\n"'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'greenletid'}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}; {'id': '81', 'type': 'augmented_assignment', 'children': ['82', '83'], 'value': '+='}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'trace'}; {'id': '83', 'type': 'call', 'children': ['84', '87']}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}; {'id': '85', 'type': 'string', 'children': [], 'value': '""'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '87', 'type': 'argument_list', 'children': ['88']}; {'id': '88', 'type': 'call', 'children': ['89', '92']}; {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'traceback'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'format_stack'}; {'id': '92', 'type': 'argument_list', 'children': ['93']}; {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'greenlet'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'gr_frame'}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}; {'id': '97', 'type': 'call', 'children': ['98', '105']}; {'id': '98', 'type': 'attribute', 'children': ['99', '104']}; {'id': '99', 'type': 'subscript', 'children': ['100', '103']}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'context'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': '_GLOBAL_CONTEXT'}; {'id': '103', 'type': 'string', 'children': [], 'value': '"greenlets"'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '105', 'type': 'argument_list', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'greenletid'}; {'id': '107', 'type': 'None', 'children': []}; {'id': '108', 'type': 'if_statement', 'children': ['109', '120']}; {'id': '109', 'type': 'boolean_operator', 'children': ['110', '113'], 'value': 'and'}; {'id': '110', 'type': 'comparison_operator', 'children': ['111', '112'], 'value': '=='}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'reason'}; {'id': '112', 'type': 'string', 'children': [], 'value': '"timeout"'}; {'id': '113', 'type': 'comparison_operator', 'children': ['114', '119'], 'value': '!='}; {'id': '114', 'type': 'subscript', 'children': ['115', '118']}; {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '118', 'type': 'string', 'children': [], 'value': '"status"'}; {'id': '119', 'type': 'string', 'children': [], 'value': '"timeout"'}; {'id': '120', 'type': 'block', 'children': ['121', '131']}; {'id': '121', 'type': 'expression_statement', 'children': ['122']}; {'id': '122', 'type': 'assignment', 'children': ['123', '124']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'updates'}; {'id': '124', 'type': 'dictionary', 'children': ['125', '128']}; {'id': '125', 'type': 'pair', 'children': ['126', '127']}; {'id': '126', 'type': 'string', 'children': [], 'value': '"exceptiontype"'}; {'id': '127', 'type': 'string', 'children': [], 'value': '"TimeoutInterrupt"'}; {'id': '128', 'type': 'pair', 'children': ['129', '130']}; {'id': '129', 'type': 'string', 'children': [], 'value': '"traceback"'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'trace'}; {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'call', 'children': ['133', '136']}; {'id': '133', 'type': 'attribute', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '135', 'type': 'identifier', 'children': [], 'value': '_save_status'}; {'id': '136', 'type': 'argument_list', 'children': ['137', '138', '141']}; {'id': '137', 'type': 'string', 'children': [], 'value': '"timeout"'}; {'id': '138', 'type': 'keyword_argument', 'children': ['139', '140']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'updates'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'updates'}; {'id': '141', 'type': 'keyword_argument', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'exception'}; {'id': '143', 'type': 'False', 'children': []}
|
Forcefully kill all greenlets associated with this job
|
def svg_html_from_pyplot_figure(fig: "Figure") -> str:
if fig is None:
return ""
memfile = io.BytesIO()
fig.savefig(memfile, format="svg")
return memfile.getvalue().decode("utf-8")
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'svg_html_from_pyplot_figure'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'fig'}; {'id': '6', 'type': 'type', 'children': ['7']}; {'id': '7', 'type': 'string', 'children': [], 'value': '"Figure"'}; {'id': '8', 'type': 'type', 'children': ['9']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '10', 'type': 'block', 'children': ['11', '18', '26', '36']}; {'id': '11', 'type': 'if_statement', 'children': ['12', '15']}; {'id': '12', 'type': 'comparison_operator', 'children': ['13', '14'], 'value': 'is'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'fig'}; {'id': '14', 'type': 'None', 'children': []}; {'id': '15', 'type': 'block', 'children': ['16']}; {'id': '16', 'type': 'return_statement', 'children': ['17']}; {'id': '17', 'type': 'string', 'children': [], 'value': '""'}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}; {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'memfile'}; {'id': '21', 'type': 'call', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'io'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'BytesIO'}; {'id': '25', 'type': 'argument_list', 'children': []}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}; {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'fig'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'savefig'}; {'id': '31', 'type': 'argument_list', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'memfile'}; {'id': '33', 'type': 'keyword_argument', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '35', 'type': 'string', 'children': [], 'value': '"svg"'}; {'id': '36', 'type': 'return_statement', 'children': ['37']}; {'id': '37', 'type': 'call', 'children': ['38', '45']}; {'id': '38', 'type': 'attribute', 'children': ['39', '44']}; {'id': '39', 'type': 'call', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'memfile'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'getvalue'}; {'id': '43', 'type': 'argument_list', 'children': []}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'decode'}; {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'string', 'children': [], 'value': '"utf-8"'}
|
Converts a ``pyplot`` figure to an SVG tag.
|
def load(path):
proto = _parse_saved_model(path)
_merge_assets_key_collection(proto, path)
handler = SavedModelHandler()
handler._proto = proto
return handler
|
{'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': 'path'}; {'id': '5', 'type': 'block', 'children': ['6', '13', '19', '25', '31']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'proto'}; {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': '_parse_saved_model'}; {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'call', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': '_merge_assets_key_collection'}; {'id': '16', 'type': 'argument_list', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'proto'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'handler'}; {'id': '22', 'type': 'call', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'SavedModelHandler'}; {'id': '24', 'type': 'argument_list', 'children': []}; {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '30']}; {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'handler'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': '_proto'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'proto'}; {'id': '31', 'type': 'return_statement', 'children': ['32']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'handler'}
|
Creates a SavedModelHandler from a SavedModel in `path`.
|
def runlogs_policy(log_group_ref):
p = Policy(
Statement=[
Statement(
Effect=Allow,
Resource=[
Join('', [
'arn:aws:logs:*:*:log-group:',
log_group_ref,
':log-stream:*'])],
Action=[
logs.CreateLogStream,
logs.PutLogEvents,
])])
return p
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'runlogs_policy'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'log_group_ref'}; {'id': '5', 'type': 'block', 'children': ['6', '41']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'Policy'}; {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'keyword_argument', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'Statement'}; {'id': '14', 'type': 'list', 'children': ['15'], 'value': "[\n Statement(\n Effect=Allow,\n Resource=[\n Join('', [\n 'arn:aws:logs:*:*:log-group:',\n log_group_ref,\n ':log-stream:*'])],\n Action=[\n logs.CreateLogStream,\n logs.PutLogEvents,\n ])]"}; {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'Statement'}; {'id': '17', 'type': 'argument_list', 'children': ['18', '21', '32']}; {'id': '18', 'type': 'keyword_argument', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'Effect'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'Allow'}; {'id': '21', 'type': 'keyword_argument', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'Resource'}; {'id': '23', 'type': 'list', 'children': ['24'], 'value': "[\n Join('', [\n 'arn:aws:logs:*:*:log-group:',\n log_group_ref,\n ':log-stream:*'])]"}; {'id': '24', 'type': 'call', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'Join'}; {'id': '26', 'type': 'argument_list', 'children': ['27', '28']}; {'id': '27', 'type': 'string', 'children': [], 'value': "''"}; {'id': '28', 'type': 'list', 'children': ['29', '30', '31'], 'value': "[\n 'arn:aws:logs:*:*:log-group:',\n log_group_ref,\n ':log-stream:*']"}; {'id': '29', 'type': 'string', 'children': [], 'value': "'arn:aws:logs:*:*:log-group:'"}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'log_group_ref'}; {'id': '31', 'type': 'string', 'children': [], 'value': "':log-stream:*'"}; {'id': '32', 'type': 'keyword_argument', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'Action'}; {'id': '34', 'type': 'list', 'children': ['35', '38'], 'value': '[\n logs.CreateLogStream,\n logs.PutLogEvents,\n ]'}; {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'logs'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'CreateLogStream'}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'logs'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'PutLogEvents'}; {'id': '41', 'type': 'return_statement', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'p'}
|
Policy needed for Empire -> Cloudwatch logs to record run output.
|
def show_vpnservice(self, vpnservice, **_params):
return self.get(self.vpnservice_path % (vpnservice), params=_params)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'show_vpnservice'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'vpnservice'}; {'id': '6', 'type': 'dictionary_splat_pattern', 'children': ['7']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': '_params'}; {'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': 'self'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '14', 'type': 'argument_list', 'children': ['15', '21']}; {'id': '15', 'type': 'binary_operator', 'children': ['16', '19'], 'value': '%'}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'vpnservice_path'}; {'id': '19', 'type': '()', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'vpnservice'}; {'id': '21', 'type': 'keyword_argument', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': '_params'}
|
Fetches information of a specific VPN service.
|
def json(self):
return {
"id": self.ID,
"steps": self.steps,
"graph_source": self.source,
"errored": self.errored
}
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'json'}; {'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']}; {'id': '8', 'type': 'pair', 'children': ['9', '10']}; {'id': '9', 'type': 'string', 'children': [], 'value': '"id"'}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'ID'}; {'id': '13', 'type': 'pair', 'children': ['14', '15']}; {'id': '14', 'type': 'string', 'children': [], 'value': '"steps"'}; {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'steps'}; {'id': '18', 'type': 'pair', 'children': ['19', '20']}; {'id': '19', 'type': 'string', 'children': [], 'value': '"graph_source"'}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'source'}; {'id': '23', 'type': 'pair', 'children': ['24', '25']}; {'id': '24', 'type': 'string', 'children': [], 'value': '"errored"'}; {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'errored'}
|
Retrun JSON representation for this run
|
def build_valid_keywords_grammar(keywords=None):
from invenio_query_parser.parser import KeywordQuery, KeywordRule, \
NotKeywordValue, SimpleQuery, ValueQuery
if keywords:
KeywordRule.grammar = attr('value', re.compile(
r"(\d\d\d\w{{0,3}}|{0})\b".format("|".join(keywords), re.I)))
NotKeywordValue.grammar = attr('value', re.compile(
r'\b(?!\d\d\d\w{{0,3}}|{0}:)\S+\b:'.format(
":|".join(keywords))))
SimpleQuery.grammar = attr(
'op', [NotKeywordValue, KeywordQuery, ValueQuery])
else:
KeywordRule.grammar = attr('value', re.compile(r"[\w\d]+(\.[\w\d]+)*"))
SimpleQuery.grammar = attr('op', [KeywordQuery, ValueQuery])
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'build_valid_keywords_grammar'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'default_parameter', 'children': ['5', '6']}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'keywords'}; {'id': '6', 'type': 'None', 'children': []}; {'id': '7', 'type': 'block', 'children': ['8', '23']}; {'id': '8', 'type': 'import_from_statement', 'children': ['9', '12', '14', '16', '17', '19', '21']}; {'id': '9', 'type': 'dotted_name', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'invenio_query_parser'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'parser'}; {'id': '12', 'type': 'dotted_name', 'children': ['13']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'KeywordQuery'}; {'id': '14', 'type': 'dotted_name', 'children': ['15']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'KeywordRule'}; {'id': '16', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '17', 'type': 'dotted_name', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'NotKeywordValue'}; {'id': '19', 'type': 'dotted_name', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'SimpleQuery'}; {'id': '21', 'type': 'dotted_name', 'children': ['22']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'ValueQuery'}; {'id': '23', 'type': 'if_statement', 'children': ['24', '25', '92']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'keywords'}; {'id': '25', 'type': 'block', 'children': ['26', '54', '79']}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}; {'id': '27', 'type': 'assignment', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'KeywordRule'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'grammar'}; {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '33', 'type': 'argument_list', 'children': ['34', '35']}; {'id': '34', 'type': 'string', 'children': [], 'value': "'value'"}; {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'compile'}; {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'call', 'children': ['41', '44']}; {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'string', 'children': [], 'value': 'r"(\\d\\d\\d\\w{{0,3}}|{0})\\b"'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '44', 'type': 'argument_list', 'children': ['45', '51']}; {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}; {'id': '47', 'type': 'string', 'children': [], 'value': '"|"'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'keywords'}; {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'I'}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}; {'id': '55', 'type': 'assignment', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'NotKeywordValue'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'grammar'}; {'id': '59', 'type': 'call', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '61', 'type': 'argument_list', 'children': ['62', '63']}; {'id': '62', 'type': 'string', 'children': [], 'value': "'value'"}; {'id': '63', 'type': 'call', 'children': ['64', '67']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'compile'}; {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'call', 'children': ['69', '72']}; {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'string', 'children': [], 'value': "r'\\b(?!\\d\\d\\d\\w{{0,3}}|{0}:)\\S+\\b:'"}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}; {'id': '73', 'type': 'call', 'children': ['74', '77']}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}; {'id': '75', 'type': 'string', 'children': [], 'value': '":|"'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'keywords'}; {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '84']}; {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'SimpleQuery'}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'grammar'}; {'id': '84', 'type': 'call', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '86', 'type': 'argument_list', 'children': ['87', '88']}; {'id': '87', 'type': 'string', 'children': [], 'value': "'op'"}; {'id': '88', 'type': 'list', 'children': ['89', '90', '91'], 'value': '[NotKeywordValue, KeywordQuery, ValueQuery]'}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'NotKeywordValue'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'KeywordQuery'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'ValueQuery'}; {'id': '92', 'type': 'else_clause', 'children': ['93']}; {'id': '93', 'type': 'block', 'children': ['94', '109']}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}; {'id': '95', 'type': 'assignment', 'children': ['96', '99']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'KeywordRule'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'grammar'}; {'id': '99', 'type': 'call', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '101', 'type': 'argument_list', 'children': ['102', '103']}; {'id': '102', 'type': 'string', 'children': [], 'value': "'value'"}; {'id': '103', 'type': 'call', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'compile'}; {'id': '107', 'type': 'argument_list', 'children': ['108']}; {'id': '108', 'type': 'string', 'children': [], 'value': 'r"[\\w\\d]+(\\.[\\w\\d]+)*"'}; {'id': '109', 'type': 'expression_statement', 'children': ['110']}; {'id': '110', 'type': 'assignment', 'children': ['111', '114']}; {'id': '111', 'type': 'attribute', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'SimpleQuery'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'grammar'}; {'id': '114', 'type': 'call', 'children': ['115', '116']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '116', 'type': 'argument_list', 'children': ['117', '118']}; {'id': '117', 'type': 'string', 'children': [], 'value': "'op'"}; {'id': '118', 'type': 'list', 'children': ['119', '120'], 'value': '[KeywordQuery, ValueQuery]'}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'KeywordQuery'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'ValueQuery'}
|
Update parser grammar to add a list of allowed keywords.
|
def prepare_fields_attribute(attribute_name, attributes, class_name):
attribute = attributes.get(attribute_name)
if not attribute:
attribute = tuple()
elif isinstance(attribute, std_collections.Iterable):
attribute = tuple(attribute)
else:
raise errors.Error('{0}.{1} is supposed to be a list of {2}, '
'instead {3} given', class_name, attribute_name,
fields.Field, attribute)
return attribute
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'prepare_fields_attribute'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'attribute_name'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'attributes'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'class_name'}; {'id': '7', 'type': 'block', 'children': ['8', '17', '60']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'attribute'}; {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'attributes'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'attribute_name'}; {'id': '17', 'type': 'if_statement', 'children': ['18', '20', '27', '43']}; {'id': '18', 'type': 'not_operator', 'children': ['19']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'attribute'}; {'id': '20', 'type': 'block', 'children': ['21']}; {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'attribute'}; {'id': '24', 'type': 'call', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '26', 'type': 'argument_list', 'children': []}; {'id': '27', 'type': 'elif_clause', 'children': ['28', '35']}; {'id': '28', 'type': 'call', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '30', 'type': 'argument_list', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'attribute'}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'std_collections'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'Iterable'}; {'id': '35', 'type': 'block', 'children': ['36']}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}; {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'attribute'}; {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'attribute'}; {'id': '43', 'type': 'else_clause', 'children': ['44']}; {'id': '44', 'type': 'block', 'children': ['45']}; {'id': '45', 'type': 'raise_statement', 'children': ['46']}; {'id': '46', 'type': 'call', 'children': ['47', '50']}; {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'Error'}; {'id': '50', 'type': 'argument_list', 'children': ['51', '54', '55', '56', '59']}; {'id': '51', 'type': 'concatenated_string', 'children': ['52', '53']}; {'id': '52', 'type': 'string', 'children': [], 'value': "'{0}.{1} is supposed to be a list of {2}, '"}; {'id': '53', 'type': 'string', 'children': [], 'value': "'instead {3} given'"}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'class_name'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'attribute_name'}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'fields'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'Field'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'attribute'}; {'id': '60', 'type': 'return_statement', 'children': ['61']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'attribute'}
|
Prepare model fields attribute.
|
def put_info(self, key, value):
return self.instance.put_task_info(self.name, key, value)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'put_info'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '7', 'type': 'block', 'children': ['8']}; {'id': '8', 'type': 'return_statement', 'children': ['9']}; {'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': 'instance'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'put_task_info'}; {'id': '15', 'type': 'argument_list', 'children': ['16', '19', '20']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'value'}
|
Put associated information of the task.
|
def css(self, *props, **kwprops):
self._stable = False
styles = {}
if props:
if len(props) == 1 and isinstance(props[0], Mapping):
styles = props[0]
else:
raise WrongContentError(self, props, "Arguments not valid")
elif kwprops:
styles = kwprops
else:
raise WrongContentError(self, None, "args OR wkargs are needed")
return self.attr(style=styles)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'css'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'list_splat_pattern', 'children': ['6']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'props'}; {'id': '7', 'type': 'dictionary_splat_pattern', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'kwprops'}; {'id': '9', 'type': 'block', 'children': ['10', '16', '20', '70']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}; {'id': '11', 'type': 'assignment', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': '_stable'}; {'id': '15', 'type': 'False', 'children': []}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}; {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'styles'}; {'id': '19', 'type': 'dictionary', 'children': []}; {'id': '20', 'type': 'if_statement', 'children': ['21', '22', '54', '61']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'props'}; {'id': '22', 'type': 'block', 'children': ['23']}; {'id': '23', 'type': 'if_statement', 'children': ['24', '38', '45']}; {'id': '24', 'type': 'boolean_operator', 'children': ['25', '31'], 'value': 'and'}; {'id': '25', 'type': 'comparison_operator', 'children': ['26', '30'], 'value': '=='}; {'id': '26', 'type': 'call', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'props'}; {'id': '30', 'type': 'integer', 'children': [], 'value': '1'}; {'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': 'subscript', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'props'}; {'id': '36', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'Mapping'}; {'id': '38', 'type': 'block', 'children': ['39']}; {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'styles'}; {'id': '42', 'type': 'subscript', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'props'}; {'id': '44', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '45', 'type': 'else_clause', 'children': ['46']}; {'id': '46', 'type': 'block', 'children': ['47']}; {'id': '47', 'type': 'raise_statement', 'children': ['48']}; {'id': '48', 'type': 'call', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'WrongContentError'}; {'id': '50', 'type': 'argument_list', 'children': ['51', '52', '53']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'props'}; {'id': '53', 'type': 'string', 'children': [], 'value': '"Arguments not valid"'}; {'id': '54', 'type': 'elif_clause', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'kwprops'}; {'id': '56', 'type': 'block', 'children': ['57']}; {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'styles'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'kwprops'}; {'id': '61', 'type': 'else_clause', 'children': ['62']}; {'id': '62', 'type': 'block', 'children': ['63']}; {'id': '63', 'type': 'raise_statement', 'children': ['64']}; {'id': '64', 'type': 'call', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'WrongContentError'}; {'id': '66', 'type': 'argument_list', 'children': ['67', '68', '69']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '68', 'type': 'None', 'children': []}; {'id': '69', 'type': 'string', 'children': [], 'value': '"args OR wkargs are needed"'}; {'id': '70', 'type': 'return_statement', 'children': ['71']}; {'id': '71', 'type': 'call', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'keyword_argument', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'style'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'styles'}
|
Adds css properties to this element.
|
def request(self, type, command_list):
req = self._build_request(type, command_list)
if self.nxargs['connect_over_uds']:
self.connection.request('POST', req['url'], req['payload'], req['headers'])
response = self.connection.getresponse()
else:
response = self.connection(req['url'],
method='POST',
opts=req['opts'],
data=req['payload'],
header_dict=req['headers'],
decode=True,
decode_type='json',
**self.nxargs)
return self.parse_response(response, command_list)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'request'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'command_list'}; {'id': '7', 'type': 'block', 'children': ['8', '18', '94']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'req'}; {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': '_build_request'}; {'id': '15', 'type': 'argument_list', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'command_list'}; {'id': '18', 'type': 'if_statement', 'children': ['19', '24', '53']}; {'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': 'nxargs'}; {'id': '23', 'type': 'string', 'children': [], 'value': "'connect_over_uds'"}; {'id': '24', 'type': 'block', 'children': ['25', '43']}; {'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': 'connection'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '32', 'type': 'argument_list', 'children': ['33', '34', '37', '40']}; {'id': '33', 'type': 'string', 'children': [], 'value': "'POST'"}; {'id': '34', 'type': 'subscript', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'req'}; {'id': '36', 'type': 'string', 'children': [], 'value': "'url'"}; {'id': '37', 'type': 'subscript', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'req'}; {'id': '39', 'type': 'string', 'children': [], 'value': "'payload'"}; {'id': '40', 'type': 'subscript', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'req'}; {'id': '42', 'type': 'string', 'children': [], 'value': "'headers'"}; {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '46', 'type': 'call', 'children': ['47', '52']}; {'id': '47', 'type': 'attribute', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'connection'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'getresponse'}; {'id': '52', 'type': 'argument_list', 'children': []}; {'id': '53', 'type': 'else_clause', 'children': ['54']}; {'id': '54', 'type': 'block', 'children': ['55']}; {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '58', 'type': 'call', 'children': ['59', '62']}; {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'connection'}; {'id': '62', 'type': 'argument_list', 'children': ['63', '66', '69', '74', '79', '84', '87', '90']}; {'id': '63', 'type': 'subscript', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'req'}; {'id': '65', 'type': 'string', 'children': [], 'value': "'url'"}; {'id': '66', 'type': 'keyword_argument', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '68', 'type': 'string', 'children': [], 'value': "'POST'"}; {'id': '69', 'type': 'keyword_argument', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'opts'}; {'id': '71', 'type': 'subscript', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'req'}; {'id': '73', 'type': 'string', 'children': [], 'value': "'opts'"}; {'id': '74', 'type': 'keyword_argument', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '76', 'type': 'subscript', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'req'}; {'id': '78', 'type': 'string', 'children': [], 'value': "'payload'"}; {'id': '79', 'type': 'keyword_argument', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'header_dict'}; {'id': '81', 'type': 'subscript', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'req'}; {'id': '83', 'type': 'string', 'children': [], 'value': "'headers'"}; {'id': '84', 'type': 'keyword_argument', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'decode'}; {'id': '86', 'type': 'True', 'children': []}; {'id': '87', 'type': 'keyword_argument', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'decode_type'}; {'id': '89', 'type': 'string', 'children': [], 'value': "'json'"}; {'id': '90', 'type': 'dictionary_splat', 'children': ['91']}; {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'nxargs'}; {'id': '94', 'type': 'return_statement', 'children': ['95']}; {'id': '95', 'type': 'call', 'children': ['96', '99']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'parse_response'}; {'id': '99', 'type': 'argument_list', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'command_list'}
|
Send NX-API JSON request to the NX-OS device.
|
def send_message(
self,
title=None,
body=None,
icon=None,
data=None,
sound=None,
badge=None,
api_key=None,
**kwargs):
from .fcm import fcm_send_message
result = fcm_send_message(
registration_id=str(self.registration_id),
title=title,
body=body,
icon=icon,
data=data,
sound=sound,
badge=badge,
api_key=api_key,
**kwargs
)
self._deactivate_device_on_error_result(result)
return result
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '28']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'send_message'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'title'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'body'}; {'id': '10', 'type': 'None', 'children': []}; {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'icon'}; {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '16', 'type': 'None', 'children': []}; {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'sound'}; {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'badge'}; {'id': '22', 'type': 'None', 'children': []}; {'id': '23', 'type': 'default_parameter', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'api_key'}; {'id': '25', 'type': 'None', 'children': []}; {'id': '26', 'type': 'dictionary_splat_pattern', 'children': ['27']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '28', 'type': 'block', 'children': ['29', '36', '73', '80']}; {'id': '29', 'type': 'import_from_statement', 'children': ['30', '34']}; {'id': '30', 'type': 'relative_import', 'children': ['31', '32']}; {'id': '31', 'type': 'import_prefix', 'children': []}; {'id': '32', 'type': 'dotted_name', 'children': ['33']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'fcm'}; {'id': '34', 'type': 'dotted_name', 'children': ['35']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'fcm_send_message'}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}; {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'fcm_send_message'}; {'id': '41', 'type': 'argument_list', 'children': ['42', '50', '53', '56', '59', '62', '65', '68', '71']}; {'id': '42', 'type': 'keyword_argument', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'registration_id'}; {'id': '44', 'type': 'call', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}; {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'registration_id'}; {'id': '50', 'type': 'keyword_argument', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'title'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'title'}; {'id': '53', 'type': 'keyword_argument', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'body'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'body'}; {'id': '56', 'type': 'keyword_argument', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'icon'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'icon'}; {'id': '59', 'type': 'keyword_argument', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '62', 'type': 'keyword_argument', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'sound'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'sound'}; {'id': '65', 'type': 'keyword_argument', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'badge'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'badge'}; {'id': '68', 'type': 'keyword_argument', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'api_key'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'api_key'}; {'id': '71', 'type': 'dictionary_splat', 'children': ['72']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'call', 'children': ['75', '78']}; {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '77', 'type': 'identifier', 'children': [], 'value': '_deactivate_device_on_error_result'}; {'id': '78', 'type': 'argument_list', 'children': ['79']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '80', 'type': 'return_statement', 'children': ['81']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'result'}
|
Send single notification message.
|
def _authorization_code_flow(self):
options = {
'scope': getattr(self, 'scope', 'non-expiring'),
'client_id': self.options.get('client_id'),
'response_type': 'code',
'redirect_uri': self._redirect_uri()
}
url = '%s%s/connect' % (self.scheme, self.host)
self._authorize_url = '%s?%s' % (url, urlencode(options))
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_authorization_code_flow'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '38', '50']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'options'}; {'id': '9', 'type': 'dictionary', 'children': ['10', '18', '28', '31']}; {'id': '10', 'type': 'pair', 'children': ['11', '12']}; {'id': '11', 'type': 'string', 'children': [], 'value': "'scope'"}; {'id': '12', 'type': 'call', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '14', 'type': 'argument_list', 'children': ['15', '16', '17']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '16', 'type': 'string', 'children': [], 'value': "'scope'"}; {'id': '17', 'type': 'string', 'children': [], 'value': "'non-expiring'"}; {'id': '18', 'type': 'pair', 'children': ['19', '20']}; {'id': '19', 'type': 'string', 'children': [], 'value': "'client_id'"}; {'id': '20', 'type': 'call', 'children': ['21', '26']}; {'id': '21', 'type': 'attribute', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'options'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}; {'id': '27', 'type': 'string', 'children': [], 'value': "'client_id'"}; {'id': '28', 'type': 'pair', 'children': ['29', '30']}; {'id': '29', 'type': 'string', 'children': [], 'value': "'response_type'"}; {'id': '30', 'type': 'string', 'children': [], 'value': "'code'"}; {'id': '31', 'type': 'pair', 'children': ['32', '33']}; {'id': '32', 'type': 'string', 'children': [], 'value': "'redirect_uri'"}; {'id': '33', 'type': 'call', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': '_redirect_uri'}; {'id': '37', 'type': 'argument_list', 'children': []}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}; {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '41', 'type': 'binary_operator', 'children': ['42', '43'], 'value': '%'}; {'id': '42', 'type': 'string', 'children': [], 'value': "'%s%s/connect'"}; {'id': '43', 'type': 'tuple', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'scheme'}; {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'host'}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}; {'id': '51', 'type': 'assignment', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': '_authorize_url'}; {'id': '55', 'type': 'binary_operator', 'children': ['56', '57'], 'value': '%'}; {'id': '56', 'type': 'string', 'children': [], 'value': "'%s?%s'"}; {'id': '57', 'type': 'tuple', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '59', 'type': 'call', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'urlencode'}; {'id': '61', 'type': 'argument_list', 'children': ['62']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'options'}
|
Build the the auth URL so the user can authorize the app.
|
def do_list(self, args):
try:
resources = self.resource_manager.list_resources_info()
except Exception as e:
print(e)
else:
self.resources = []
for ndx, (resource_name, value) in enumerate(resources.items()):
if not args:
print('({0:2d}) {1}'.format(ndx, resource_name))
if value.alias:
print(' alias: {}'.format(value.alias))
self.resources.append((resource_name, value.alias or None))
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'do_list'}; {'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']}; {'id': '7', 'type': 'try_statement', 'children': ['8', '19', '30']}; {'id': '8', 'type': 'block', 'children': ['9']}; {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'resources'}; {'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': 'resource_manager'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'list_resources_info'}; {'id': '18', 'type': 'argument_list', 'children': []}; {'id': '19', 'type': 'except_clause', 'children': ['20', '24']}; {'id': '20', 'type': 'as_pattern', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '22', 'type': 'as_pattern_target', 'children': ['23']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '24', 'type': 'block', 'children': ['25']}; {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'call', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '30', 'type': 'else_clause', 'children': ['31']}; {'id': '31', 'type': 'block', 'children': ['32', '38']}; {'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': 'resources'}; {'id': '37', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '38', 'type': 'for_statement', 'children': ['39', '44', '52']}; {'id': '39', 'type': 'pattern_list', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'ndx'}; {'id': '41', 'type': 'tuple_pattern', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'resource_name'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '44', 'type': 'call', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}; {'id': '47', 'type': 'call', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'resources'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '51', 'type': 'argument_list', 'children': []}; {'id': '52', 'type': 'block', 'children': ['53', '85']}; {'id': '53', 'type': 'if_statement', 'children': ['54', '56']}; {'id': '54', 'type': 'not_operator', 'children': ['55']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '56', 'type': 'block', 'children': ['57', '68']}; {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'call', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'print'}; {'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': "'({0:2d}) {1}'"}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '65', 'type': 'argument_list', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'ndx'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'resource_name'}; {'id': '68', 'type': 'if_statement', 'children': ['69', '72']}; {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'alias'}; {'id': '72', 'type': 'block', 'children': ['73']}; {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'call', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}; {'id': '77', 'type': 'call', 'children': ['78', '81']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}; {'id': '79', 'type': 'string', 'children': [], 'value': "' alias: {}'"}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'alias'}; {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'call', 'children': ['87', '92']}; {'id': '87', 'type': 'attribute', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'resources'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '92', 'type': 'argument_list', 'children': ['93']}; {'id': '93', 'type': 'tuple', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'resource_name'}; {'id': '95', 'type': 'boolean_operator', 'children': ['96', '99'], 'value': 'or'}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'alias'}; {'id': '99', 'type': 'None', 'children': []}
|
List all connected resources.
|
def functions(context):
config_file = "./lambder.json"
if os.path.isfile(config_file):
context.obj = FunctionConfig(config_file)
pass
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'functions'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'context'}; {'id': '5', 'type': 'block', 'children': ['6', '10', '29']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'config_file'}; {'id': '9', 'type': 'string', 'children': [], 'value': '"./lambder.json"'}; {'id': '10', 'type': 'if_statement', 'children': ['11', '19']}; {'id': '11', 'type': 'call', 'children': ['12', '17']}; {'id': '12', 'type': 'attribute', 'children': ['13', '16']}; {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'isfile'}; {'id': '17', 'type': 'argument_list', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'config_file'}; {'id': '19', 'type': 'block', 'children': ['20']}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}; {'id': '21', 'type': 'assignment', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'context'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'FunctionConfig'}; {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'config_file'}; {'id': '29', 'type': 'pass_statement', 'children': []}
|
Manage AWS Lambda functions
|
def _check_unique_together(cls):
if cls._meta.unique_together is None:
return
if not isinstance(cls._meta.unique_together, (tuple, list)):
raise ConfigurationError(
"'{}.unique_together' must be a list or tuple.".format(cls.__name__)
)
elif any(
not isinstance(unique_fields, (tuple, list))
for unique_fields in cls._meta.unique_together
):
raise ConfigurationError(
"All '{}.unique_together' elements must be lists or tuples.".format(cls.__name__)
)
else:
for fields_tuple in cls._meta.unique_together:
for field_name in fields_tuple:
field = cls._meta.fields_map.get(field_name)
if not field:
raise ConfigurationError(
"'{}.unique_together' has no '{}' "
"field.".format(cls.__name__, field_name)
)
if isinstance(field, ManyToManyField):
raise ConfigurationError(
"'{}.unique_together' '{}' field refers "
"to ManyToMany field.".format(cls.__name__, field_name)
)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_check_unique_together'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '5', 'type': 'block', 'children': ['6', '16']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '14']}; {'id': '7', 'type': 'comparison_operator', 'children': ['8', '13'], 'value': 'is'}; {'id': '8', 'type': 'attribute', 'children': ['9', '12']}; {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': '_meta'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'unique_together'}; {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15']}; {'id': '15', 'type': 'return_statement', 'children': []}; {'id': '16', 'type': 'if_statement', 'children': ['17', '29', '42', '74']}; {'id': '17', 'type': 'not_operator', 'children': ['18']}; {'id': '18', 'type': 'call', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '20', 'type': 'argument_list', 'children': ['21', '26']}; {'id': '21', 'type': 'attribute', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': '_meta'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'unique_together'}; {'id': '26', 'type': 'tuple', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '29', 'type': 'block', 'children': ['30']}; {'id': '30', 'type': 'raise_statement', 'children': ['31']}; {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'ConfigurationError'}; {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'call', 'children': ['35', '38']}; {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'string', 'children': [], 'value': '"\'{}.unique_together\' must be a list or tuple."'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}; {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': '__name__'}; {'id': '42', 'type': 'elif_clause', 'children': ['43', '61']}; {'id': '43', 'type': 'call', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'any'}; {'id': '45', 'type': 'generator_expression', 'children': ['46', '54']}; {'id': '46', 'type': 'not_operator', 'children': ['47']}; {'id': '47', 'type': 'call', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '49', 'type': 'argument_list', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'unique_fields'}; {'id': '51', 'type': 'tuple', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '54', 'type': 'for_in_clause', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'unique_fields'}; {'id': '56', 'type': 'attribute', 'children': ['57', '60']}; {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': '_meta'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'unique_together'}; {'id': '61', 'type': 'block', 'children': ['62']}; {'id': '62', 'type': 'raise_statement', 'children': ['63']}; {'id': '63', 'type': 'call', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'ConfigurationError'}; {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'call', 'children': ['67', '70']}; {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'string', 'children': [], 'value': '"All \'{}.unique_together\' elements must be lists or tuples."'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}; {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': '__name__'}; {'id': '74', 'type': 'else_clause', 'children': ['75']}; {'id': '75', 'type': 'block', 'children': ['76']}; {'id': '76', 'type': 'for_statement', 'children': ['77', '78', '83']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'fields_tuple'}; {'id': '78', 'type': 'attribute', 'children': ['79', '82']}; {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '81', 'type': 'identifier', 'children': [], 'value': '_meta'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'unique_together'}; {'id': '83', 'type': 'block', 'children': ['84']}; {'id': '84', 'type': 'for_statement', 'children': ['85', '86', '87']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'field_name'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'fields_tuple'}; {'id': '87', 'type': 'block', 'children': ['88', '101', '120']}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}; {'id': '89', 'type': 'assignment', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '91', 'type': 'call', 'children': ['92', '99']}; {'id': '92', 'type': 'attribute', 'children': ['93', '98']}; {'id': '93', 'type': 'attribute', 'children': ['94', '97']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': '_meta'}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'fields_map'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '99', 'type': 'argument_list', 'children': ['100']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'field_name'}; {'id': '101', 'type': 'if_statement', 'children': ['102', '104']}; {'id': '102', 'type': 'not_operator', 'children': ['103']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '104', 'type': 'block', 'children': ['105']}; {'id': '105', 'type': 'raise_statement', 'children': ['106']}; {'id': '106', 'type': 'call', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'ConfigurationError'}; {'id': '108', 'type': 'argument_list', 'children': ['109']}; {'id': '109', 'type': 'call', 'children': ['110', '115']}; {'id': '110', 'type': 'attribute', 'children': ['111', '114']}; {'id': '111', 'type': 'concatenated_string', 'children': ['112', '113']}; {'id': '112', 'type': 'string', 'children': [], 'value': '"\'{}.unique_together\' has no \'{}\' "'}; {'id': '113', 'type': 'string', 'children': [], 'value': '"field."'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '115', 'type': 'argument_list', 'children': ['116', '119']}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': '__name__'}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'field_name'}; {'id': '120', 'type': 'if_statement', 'children': ['121', '126']}; {'id': '121', 'type': 'call', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '123', 'type': 'argument_list', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'ManyToManyField'}; {'id': '126', 'type': 'block', 'children': ['127']}; {'id': '127', 'type': 'raise_statement', 'children': ['128']}; {'id': '128', 'type': 'call', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'ConfigurationError'}; {'id': '130', 'type': 'argument_list', 'children': ['131']}; {'id': '131', 'type': 'call', 'children': ['132', '137']}; {'id': '132', 'type': 'attribute', 'children': ['133', '136']}; {'id': '133', 'type': 'concatenated_string', 'children': ['134', '135']}; {'id': '134', 'type': 'string', 'children': [], 'value': '"\'{}.unique_together\' \'{}\' field refers "'}; {'id': '135', 'type': 'string', 'children': [], 'value': '"to ManyToMany field."'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '137', 'type': 'argument_list', 'children': ['138', '141']}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': '__name__'}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'field_name'}
|
Check the value of "unique_together" option.
|
def personastate(self):
if self._personastate == None:
return None
elif self._personastate in self.PersonaState:
return self.PersonaState[self._personastate]
else:
return None
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'personastate'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '12', '15', '32']}; {'id': '7', 'type': 'comparison_operator', 'children': ['8', '11'], 'value': '=='}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': '_personastate'}; {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'block', 'children': ['13']}; {'id': '13', 'type': 'return_statement', 'children': ['14']}; {'id': '14', 'type': 'None', 'children': []}; {'id': '15', 'type': 'elif_clause', 'children': ['16', '23']}; {'id': '16', 'type': 'comparison_operator', 'children': ['17', '20'], 'value': 'in'}; {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': '_personastate'}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'PersonaState'}; {'id': '23', 'type': 'block', 'children': ['24']}; {'id': '24', 'type': 'return_statement', 'children': ['25']}; {'id': '25', 'type': 'subscript', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'PersonaState'}; {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': '_personastate'}; {'id': '32', 'type': 'else_clause', 'children': ['33']}; {'id': '33', 'type': 'block', 'children': ['34']}; {'id': '34', 'type': 'return_statement', 'children': ['35']}; {'id': '35', 'type': 'None', 'children': []}
|
Return the Persona State of the Users Profile
|
def _run_default_moderator(comment, content_object, request):
if not default_moderator.allow(comment, content_object, request):
return False
if default_moderator.moderate(comment, content_object, request):
comment.is_public = False
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_run_default_moderator'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'comment'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'content_object'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '7', 'type': 'block', 'children': ['8', '21']}; {'id': '8', 'type': 'if_statement', 'children': ['9', '18']}; {'id': '9', 'type': 'not_operator', 'children': ['10']}; {'id': '10', 'type': 'call', 'children': ['11', '14']}; {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'default_moderator'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'allow'}; {'id': '14', 'type': 'argument_list', 'children': ['15', '16', '17']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'comment'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'content_object'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '18', 'type': 'block', 'children': ['19']}; {'id': '19', 'type': 'return_statement', 'children': ['20']}; {'id': '20', 'type': 'False', 'children': []}; {'id': '21', 'type': 'if_statement', 'children': ['22', '30']}; {'id': '22', 'type': 'call', 'children': ['23', '26']}; {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'default_moderator'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'moderate'}; {'id': '26', 'type': 'argument_list', 'children': ['27', '28', '29']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'comment'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'content_object'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '30', 'type': 'block', 'children': ['31']}; {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '36']}; {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'comment'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'is_public'}; {'id': '36', 'type': 'False', 'children': []}
|
Run the default moderator
|
def expire_file(filepath):
load_message.cache_clear()
orm.delete(pa for pa in model.PathAlias if pa.entry.file_path == filepath)
orm.delete(item for item in model.Entry if item.file_path == filepath)
orm.commit()
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'expire_file'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'filepath'}; {'id': '5', 'type': 'block', 'children': ['6', '12', '32', '50']}; {'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': 'load_message'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'cache_clear'}; {'id': '11', 'type': 'argument_list', 'children': []}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}; {'id': '13', 'type': 'call', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'orm'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'delete'}; {'id': '17', 'type': 'generator_expression', 'children': ['18', '19', '24']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'pa'}; {'id': '19', 'type': 'for_in_clause', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'pa'}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'PathAlias'}; {'id': '24', 'type': 'if_clause', 'children': ['25']}; {'id': '25', 'type': 'comparison_operator', 'children': ['26', '31'], 'value': '=='}; {'id': '26', 'type': 'attribute', 'children': ['27', '30']}; {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'pa'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'file_path'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'filepath'}; {'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': 'orm'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'delete'}; {'id': '37', 'type': 'generator_expression', 'children': ['38', '39', '44']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '39', 'type': 'for_in_clause', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'Entry'}; {'id': '44', 'type': 'if_clause', 'children': ['45']}; {'id': '45', 'type': 'comparison_operator', 'children': ['46', '49'], 'value': '=='}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'file_path'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'filepath'}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}; {'id': '51', 'type': 'call', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'orm'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'commit'}; {'id': '55', 'type': 'argument_list', 'children': []}
|
Expire a record for a missing file
|
def processed_file(self, new_text, filename, old_text=None, write=False,
encoding=None):
self.files.append(filename)
if old_text is None:
old_text = self._read_python_source(filename)[0]
if old_text is None:
return
equal = old_text == new_text
self.print_output(old_text, new_text, filename, equal)
if equal:
self.log_debug("No changes to %s", filename)
if not self.write_unchanged_files:
return
if write:
self.write_file(new_text, filename, old_text, encoding)
else:
self.log_debug("Not writing changes to %s", filename)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'processed_file'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'new_text'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'old_text'}; {'id': '9', 'type': 'None', 'children': []}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '12', 'type': 'False', 'children': []}; {'id': '13', 'type': 'default_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'encoding'}; {'id': '15', 'type': 'None', 'children': []}; {'id': '16', 'type': 'block', 'children': ['17', '26', '48', '54', '64', '82']}; {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'call', 'children': ['19', '24']}; {'id': '19', 'type': 'attribute', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'files'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '26', 'type': 'if_statement', 'children': ['27', '30']}; {'id': '27', 'type': 'comparison_operator', 'children': ['28', '29'], 'value': 'is'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'old_text'}; {'id': '29', 'type': 'None', 'children': []}; {'id': '30', 'type': 'block', 'children': ['31', '42']}; {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'old_text'}; {'id': '34', 'type': 'subscript', 'children': ['35', '41']}; {'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': '_read_python_source'}; {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '41', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '42', 'type': 'if_statement', 'children': ['43', '46']}; {'id': '43', 'type': 'comparison_operator', 'children': ['44', '45'], 'value': 'is'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'old_text'}; {'id': '45', 'type': 'None', 'children': []}; {'id': '46', 'type': 'block', 'children': ['47']}; {'id': '47', 'type': 'return_statement', 'children': []}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}; {'id': '49', 'type': 'assignment', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'equal'}; {'id': '51', 'type': 'comparison_operator', 'children': ['52', '53'], 'value': '=='}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'old_text'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'new_text'}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}; {'id': '55', 'type': 'call', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'print_output'}; {'id': '59', 'type': 'argument_list', 'children': ['60', '61', '62', '63']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'old_text'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'new_text'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'equal'}; {'id': '64', 'type': 'if_statement', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'equal'}; {'id': '66', 'type': 'block', 'children': ['67', '75']}; {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'call', 'children': ['69', '72']}; {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'log_debug'}; {'id': '72', 'type': 'argument_list', 'children': ['73', '74']}; {'id': '73', 'type': 'string', 'children': [], 'value': '"No changes to %s"'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '75', 'type': 'if_statement', 'children': ['76', '80']}; {'id': '76', 'type': 'not_operator', 'children': ['77']}; {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'write_unchanged_files'}; {'id': '80', 'type': 'block', 'children': ['81']}; {'id': '81', 'type': 'return_statement', 'children': []}; {'id': '82', 'type': 'if_statement', 'children': ['83', '84', '95']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '84', 'type': 'block', 'children': ['85']}; {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'call', 'children': ['87', '90']}; {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'write_file'}; {'id': '90', 'type': 'argument_list', 'children': ['91', '92', '93', '94']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'new_text'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'old_text'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'encoding'}; {'id': '95', 'type': 'else_clause', 'children': ['96']}; {'id': '96', 'type': 'block', 'children': ['97']}; {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'call', 'children': ['99', '102']}; {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'log_debug'}; {'id': '102', 'type': 'argument_list', 'children': ['103', '104']}; {'id': '103', 'type': 'string', 'children': [], 'value': '"Not writing changes to %s"'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'filename'}
|
Called when a file has been refactored and there may be changes.
|
def pycomplex(v_str):
assert isinstance(v_str, str)
if v_str[0] == '(' and v_str[-1] == ')' and len(v_str.split(',')) == 2:
v_re, v_im = v_str[1:-1].split(',', 1)
return complex(pyfloat(v_re), pyfloat(v_im))
else:
raise ValueError('{0} must be in complex number form (x, y).'
''.format(v_str))
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'pycomplex'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'v_str'}; {'id': '5', 'type': 'block', 'children': ['6', '12']}; {'id': '6', 'type': 'assert_statement', 'children': ['7']}; {'id': '7', 'type': 'call', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '9', 'type': 'argument_list', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'v_str'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '12', 'type': 'if_statement', 'children': ['13', '37', '68']}; {'id': '13', 'type': 'boolean_operator', 'children': ['14', '26'], 'value': 'and'}; {'id': '14', 'type': 'boolean_operator', 'children': ['15', '20'], 'value': 'and'}; {'id': '15', 'type': 'comparison_operator', 'children': ['16', '19'], 'value': '=='}; {'id': '16', 'type': 'subscript', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'v_str'}; {'id': '18', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '19', 'type': 'string', 'children': [], 'value': "'('"}; {'id': '20', 'type': 'comparison_operator', 'children': ['21', '25'], 'value': '=='}; {'id': '21', 'type': 'subscript', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'v_str'}; {'id': '23', 'type': 'unary_operator', 'children': ['24'], 'value': '-'}; {'id': '24', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '25', 'type': 'string', 'children': [], 'value': "')'"}; {'id': '26', 'type': 'comparison_operator', 'children': ['27', '36'], 'value': '=='}; {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'call', 'children': ['31', '34']}; {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'v_str'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}; {'id': '35', 'type': 'string', 'children': [], 'value': "','"}; {'id': '36', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '37', 'type': 'block', 'children': ['38', '56']}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}; {'id': '39', 'type': 'assignment', 'children': ['40', '43']}; {'id': '40', 'type': 'pattern_list', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'v_re'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'v_im'}; {'id': '43', 'type': 'call', 'children': ['44', '53']}; {'id': '44', 'type': 'attribute', 'children': ['45', '52']}; {'id': '45', 'type': 'subscript', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'v_str'}; {'id': '47', 'type': 'slice', 'children': ['48', '49', '50']}; {'id': '48', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '49', 'type': 'colon', 'children': []}; {'id': '50', 'type': 'unary_operator', 'children': ['51'], 'value': '-'}; {'id': '51', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '53', 'type': 'argument_list', 'children': ['54', '55']}; {'id': '54', 'type': 'string', 'children': [], 'value': "','"}; {'id': '55', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '56', 'type': 'return_statement', 'children': ['57']}; {'id': '57', 'type': 'call', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'complex'}; {'id': '59', 'type': 'argument_list', 'children': ['60', '64']}; {'id': '60', 'type': 'call', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'pyfloat'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'v_re'}; {'id': '64', 'type': 'call', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'pyfloat'}; {'id': '66', 'type': 'argument_list', 'children': ['67']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'v_im'}; {'id': '68', 'type': 'else_clause', 'children': ['69']}; {'id': '69', 'type': 'block', 'children': ['70']}; {'id': '70', 'type': 'raise_statement', 'children': ['71']}; {'id': '71', 'type': 'call', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'call', 'children': ['75', '80']}; {'id': '75', 'type': 'attribute', 'children': ['76', '79']}; {'id': '76', 'type': 'concatenated_string', 'children': ['77', '78']}; {'id': '77', 'type': 'string', 'children': [], 'value': "'{0} must be in complex number form (x, y).'"}; {'id': '78', 'type': 'string', 'children': [], 'value': "''"}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'v_str'}
|
Convert string repr of Fortran complex to Python complex.
|
def read_text(self, encoding='utf-8') -> str:
with self.open('r', encoding=encoding) as fp:
return fp.read()
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'read_text'}; {'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': 'encoding'}; {'id': '7', 'type': 'string', 'children': [], 'value': "'utf-8'"}; {'id': '8', 'type': 'type', 'children': ['9']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '10', 'type': 'block', 'children': ['11']}; {'id': '11', 'type': 'with_statement', 'children': ['12', '26']}; {'id': '12', 'type': 'with_clause', 'children': ['13']}; {'id': '13', 'type': 'with_item', 'children': ['14']}; {'id': '14', 'type': 'as_pattern', 'children': ['15', '24']}; {'id': '15', 'type': 'call', 'children': ['16', '19']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '19', 'type': 'argument_list', 'children': ['20', '21']}; {'id': '20', 'type': 'string', 'children': [], 'value': "'r'"}; {'id': '21', 'type': 'keyword_argument', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'encoding'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'encoding'}; {'id': '24', 'type': 'as_pattern_target', 'children': ['25']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'fp'}; {'id': '26', 'type': 'block', 'children': ['27']}; {'id': '27', 'type': 'return_statement', 'children': ['28']}; {'id': '28', 'type': 'call', 'children': ['29', '32']}; {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'fp'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'read'}; {'id': '32', 'type': 'argument_list', 'children': []}
|
read all text into memory.
|
def _encode_batched_write_command(
namespace, operation, command, docs, check_keys, opts, ctx):
buf = StringIO()
to_send, _ = _batched_write_command_impl(
namespace, operation, command, docs, check_keys, opts, ctx, buf)
return buf.getvalue(), to_send
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_encode_batched_write_command'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '10']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'namespace'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'operation'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'command'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'docs'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'check_keys'}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'opts'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'ctx'}; {'id': '11', 'type': 'block', 'children': ['12', '18', '34']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}; {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'buf'}; {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'StringIO'}; {'id': '17', 'type': 'argument_list', 'children': []}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}; {'id': '19', 'type': 'assignment', 'children': ['20', '23']}; {'id': '20', 'type': 'pattern_list', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'to_send'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '23', 'type': 'call', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': '_batched_write_command_impl'}; {'id': '25', 'type': 'argument_list', 'children': ['26', '27', '28', '29', '30', '31', '32', '33']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'namespace'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'operation'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'command'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'docs'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'check_keys'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'opts'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'ctx'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'buf'}; {'id': '34', 'type': 'return_statement', 'children': ['35']}; {'id': '35', 'type': 'expression_list', 'children': ['36', '41']}; {'id': '36', 'type': 'call', 'children': ['37', '40']}; {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'buf'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'getvalue'}; {'id': '40', 'type': 'argument_list', 'children': []}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'to_send'}
|
Encode the next batched insert, update, or delete command.
|
def Jobs(self):
url = self._url + "/jobs"
return Jobs(url=url,
securityHandler=self._securityHandler,
proxy_url=self._proxy_url,
proxy_port=self._proxy_port,
initialize=True)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'Jobs'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '14']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '9', 'type': 'binary_operator', 'children': ['10', '13'], 'value': '+'}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': '_url'}; {'id': '13', 'type': 'string', 'children': [], 'value': '"/jobs"'}; {'id': '14', 'type': 'return_statement', 'children': ['15']}; {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'Jobs'}; {'id': '17', 'type': 'argument_list', 'children': ['18', '21', '26', '31', '36']}; {'id': '18', 'type': 'keyword_argument', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '21', 'type': 'keyword_argument', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'securityHandler'}; {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': '_securityHandler'}; {'id': '26', 'type': 'keyword_argument', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'proxy_url'}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': '_proxy_url'}; {'id': '31', 'type': 'keyword_argument', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'proxy_port'}; {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': '_proxy_port'}; {'id': '36', 'type': 'keyword_argument', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'initialize'}; {'id': '38', 'type': 'True', 'children': []}
|
get the Jobs object
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.