Search is not available for this dataset
id
int64
0
10.8M
vector
listlengths
1.54k
1.54k
ast_depth
int64
3
164
ast_data
stringlengths
297
510k
full_path
stringlengths
0
319
code
stringlengths
60
56.5k
10,901
[ -0.024829931557178497, -0.02857142873108387, 0.02248542197048664, -0.0077259475365281105, 0.019302720203995705, -0.000548924901522696, 0.021902332082390785, 0.011339893564581871, 0.014686589129269123, 0.01123056374490261, 0.010495626367628574, 0.002033224096521735, 0.0259232260286808, -0.0...
13
{"_type": "Module", "_fields": {"body": [{"_type": "ClassDef", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "With", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "ListComp", "_fields": {"elt": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "float32", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "astype", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 16}}, {"_type": "Constant", "_fields": {"kind": null, "value": 16}}, {"_type": "Constant", "_fields": {"kind": null, "value": 16}}, {"_type": "Constant", "_fields": {"kind": null, "value": 16}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "rand", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "random", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}}}, "keywords": []}}, "generators": [{"_type": "comprehension", "_fields": {"ifs": [], "iter": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 20}}], "func": {"_type": "Name", "_fields": {"id": "range", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "target": {"_type": "Name", "_fields": {"id": "_", "ctx": {"_type": "Store", "_fields": {}}}}, "is_async": 0}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "random_arrays", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "ListComp", "_fields": {"elt": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "convert_to_tensor", "value": {"_type": "Name", "_fields": {"id": "ops", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "dtype", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "float32", "value": {"_type": "Name", "_fields": {"id": "dtypes_lib", "ctx": {"_type": "Load", "_fields": {}}}}}}}}]}}, "generators": [{"_type": "comprehension", "_fields": {"ifs": [], "iter": {"_type": "Name", "_fields": {"id": "random_arrays", "ctx": {"_type": "Load", "_fields": {}}}}, "target": {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Store", "_fields": {}}}}, "is_async": 0}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "random_tensors", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "random_tensors", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "accumulate_n", "value": {"_type": "Name", "_fields": {"id": "math_ops", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "tf_val", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "value": {"_type": "Name", "_fields": {"id": "random_arrays", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "np_val", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "For", "_fields": {"body": [{"_type": "AugAssign", "_fields": {"op": {"_type": "Add", "_fields": {}}, "value": {"_type": "Name", "_fields": {"id": "random_array", "ctx": {"_type": "Load", "_fields": {}}}}, "target": {"_type": "Name", "_fields": {"id": "np_val", "ctx": {"_type": "Store", "_fields": {}}}}}}], "iter": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Slice", "_fields": {"step": null, "lower": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, "upper": null}}, "value": {"_type": "Name", "_fields": {"id": "random_arrays", "ctx": {"_type": "Load", "_fields": {}}}}}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "random_array", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "np_val", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "eval", "value": {"_type": "Name", "_fields": {"id": "tf_val", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertAllClose", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "items": [{"_type": "withitem", "_fields": {"context_expr": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "cached_session", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "optional_vars": null}}], "type_comment": null}}], "name": "testSimple", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "With", "_fields": {"body": [{"_type": "With", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "accumulate_n", "value": {"_type": "Name", "_fields": {"id": "math_ops", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "tf_val", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "eval", "value": {"_type": "Name", "_fields": {"id": "tf_val", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "items": [{"_type": "withitem", "_fields": {"context_expr": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "ValueError", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertRaises", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "optional_vars": null}}], "type_comment": null}}], "items": [{"_type": "withitem", "_fields": {"context_expr": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "cached_session", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "optional_vars": null}}], "type_comment": null}}], "name": "testZeroArgs", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "With", "_fields": {"body": [{"_type": "With", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 0.2}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "Variable", "value": {"_type": "Name", "_fields": {"id": "variables", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "a", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 0.1}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "Variable", "value": {"_type": "Name", "_fields": {"id": "variables", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "b", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "a", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "b", "ctx": {"_type": "Load", "_fields": {}}}}]}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "accumulate_n", "value": {"_type": "Name", "_fields": {"id": "math_ops", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "shape", "value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 2}}, {"_type": "Constant", "_fields": {"kind": null, "value": 2}}]}}}}]}}}}], "items": [{"_type": "withitem", "_fields": {"context_expr": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "ValueError", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertRaises", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "optional_vars": null}}], "type_comment": null}}], "items": [{"_type": "withitem", "_fields": {"context_expr": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "cached_session", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "optional_vars": null}}], "type_comment": null}}], "name": "testWrongShape", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "With", "_fields": {"body": [{"_type": "With", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 0.2}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "Variable", "value": {"_type": "Name", "_fields": {"id": "variables", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "dtype", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "float32", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "a", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 0.1}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "Variable", "value": {"_type": "Name", "_fields": {"id": "variables", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "dtype", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "float32", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "b", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "a", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "b", "ctx": {"_type": "Load", "_fields": {}}}}]}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "accumulate_n", "value": {"_type": "Name", "_fields": {"id": "math_ops", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "tensor_dtype", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "int32", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}}}]}}}}], "items": [{"_type": "withitem", "_fields": {"context_expr": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "TypeError", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertRaises", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "optional_vars": null}}], "type_comment": null}}], "items": [{"_type": "withitem", "_fields": {"context_expr": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "cached_session", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "optional_vars": null}}], "type_comment": null}}], "name": "testWrongType", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "With", "_fields": {"body": [{"_type": "With", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 0.2}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "Variable", "value": {"_type": "Name", "_fields": {"id": "variables", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "dtype", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "float32", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "a", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "a", "ctx": {"_type": "Load", "_fields": {}}}}]}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "accumulate_n", "value": {"_type": "Name", "_fields": {"id": "math_ops", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "tensor_dtype", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "int32", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}}}]}}}}], "items": [{"_type": "withitem", "_fields": {"context_expr": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "TypeError", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertRaises", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "optional_vars": null}}], "type_comment": null}}], "items": [{"_type": "withitem", "_fields": {"context_expr": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "cached_session", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "optional_vars": null}}], "type_comment": null}}], "name": "testWrongTypeOneInput", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "name": "AccumulateTest", "bases": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "TestCase", "value": {"_type": "Name", "_fields": {"id": "test", "ctx": {"_type": "Load", "_fields": {}}}}}}], "keywords": [], "type_params": [], "decorator_list": []}}], "type_ignores": []}}
class AccumulateTest(test.TestCase): def testSimple(self): with self.cached_session(): random_arrays = [ np.random.rand(16, 16, 16, 16).astype(np.float32) for _ in range(20) ] random_tensors = [ ops.convert_to_tensor(x, dtype=dtypes_lib.float32) for x in random_arrays ] tf_val = math_ops.accumulate_n(random_tensors) np_val = random_arrays[0] for random_array in random_arrays[1:]: np_val += random_array self.assertAllClose(np_val, tf_val.eval()) def testZeroArgs(self): with self.cached_session(): with self.assertRaises(ValueError): tf_val = math_ops.accumulate_n([]) tf_val.eval() def testWrongShape(self): with self.cached_session(): with self.assertRaises(ValueError): a = variables.Variable(0.2) b = variables.Variable(0.1) math_ops.accumulate_n([a, b], shape=[2, 2]) # Should be shape=[] def testWrongType(self): with self.cached_session(): with self.assertRaises(TypeError): a = variables.Variable(0.2, dtype=np.float32) b = variables.Variable(0.1, dtype=np.float32) math_ops.accumulate_n([a, b], tensor_dtype=np.int32) def testWrongTypeOneInput(self): # Scenario that used to trigger a bug, even when testWrongType() worked with self.cached_session(): with self.assertRaises(TypeError): a = variables.Variable(0.2, dtype=np.float32) math_ops.accumulate_n([a], tensor_dtype=np.int32)
10,902
[ -0.00972236692905426, -0.003829766996204853, 0.0495079830288887, -0.05667717009782791, 0.020211249589920044, 0.016006678342819214, -0.00013843804481439292, -0.004621646832674742, 0.02003089338541031, 0.014879448339343071, -0.010201439261436462, -0.004655463621020317, -0.01792297139763832, ...
12
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "dtype", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "dtype", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "astype", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 3}}, {"_type": "Constant", "_fields": {"kind": null, "value": 2}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "reshape", "value": {"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [{"_type": "UnaryOp", "_fields": {"op": {"_type": "USub", "_fields": {}}, "operand": {"_type": "Constant", "_fields": {"kind": null, "value": 3}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": 3}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "arange", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 4.0}}}}}}, "keywords": []}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "data", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "data", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_compare", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Is", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "dtype", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "float16", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "orelse": []}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "data", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_compare_values", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 0.5}}, {"_type": "Constant", "_fields": {"kind": null, "value": 0.5000001}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 0.0}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1.0}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "y", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_compare_values", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "y", "value": {"_type": "Name", "_fields": {"id": "y", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "UnaryOp", "_fields": {"op": {"_type": "USub", "_fields": {}}, "operand": {"_type": "Constant", "_fields": {"kind": null, "value": 1.7}}}}, {"_type": "UnaryOp", "_fields": {"op": {"_type": "USub", "_fields": {}}, "operand": {"_type": "Constant", "_fields": {"kind": null, "value": 1.5}}}}, {"_type": "UnaryOp", "_fields": {"op": {"_type": "USub", "_fields": {}}, "operand": {"_type": "Constant", "_fields": {"kind": null, "value": 0.2}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": 0.2}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1.5}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1.7}}, {"_type": "Constant", "_fields": {"kind": null, "value": 2.0}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "UnaryOp", "_fields": {"op": {"_type": "USub", "_fields": {}}, "operand": {"_type": "Constant", "_fields": {"kind": null, "value": 2.0}}}}, {"_type": "UnaryOp", "_fields": {"op": {"_type": "USub", "_fields": {}}, "operand": {"_type": "Constant", "_fields": {"kind": null, "value": 2.0}}}}, {"_type": "UnaryOp", "_fields": {"op": {"_type": "USub", "_fields": {}}, "operand": {"_type": "Constant", "_fields": {"kind": null, "value": 0.0}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": 0.0}}, {"_type": "Constant", "_fields": {"kind": null, "value": 2.0}}, {"_type": "Constant", "_fields": {"kind": null, "value": 2.0}}, {"_type": "Constant", "_fields": {"kind": null, "value": 2.0}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "y", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_compare_values", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "y", "value": {"_type": "Name", "_fields": {"id": "y", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}], "name": "_testDtype", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def _testDtype(self, dtype): data = (np.arange(-3, 3) / 4.).reshape(1, 3, 2).astype(dtype) self._compare(data) # TODO: rint op is not supported for float16 if dtype is np.float16: return self._compare_values(data) x = [0.5, 0.5000001] y = [0.0, 1.0] self._compare_values(x, y=y) # numpy example x = [-1.7, -1.5, -0.2, 0.2, 1.5, 1.7, 2.0] y = [-2., -2., -0., 0., 2., 2., 2.] self._compare_values(x, y=y)
10,903
[ -0.013793661259114742, -0.03751278668642044, 0.04577157273888588, -0.033955540508031845, 0.05751297250390053, -0.016741449013352394, 0.01891808770596981, 0.026816170662641525, 0.03271174803376198, 0.00044310116209089756, 0.02075890079140663, 0.00007545352127635852, 0.030970437452197075, 0....
12
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "With", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "ListComp", "_fields": {"elt": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "float32", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "astype", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 16}}, {"_type": "Constant", "_fields": {"kind": null, "value": 16}}, {"_type": "Constant", "_fields": {"kind": null, "value": 16}}, {"_type": "Constant", "_fields": {"kind": null, "value": 16}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "rand", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "random", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}}}, "keywords": []}}, "generators": [{"_type": "comprehension", "_fields": {"ifs": [], "iter": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 20}}], "func": {"_type": "Name", "_fields": {"id": "range", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "target": {"_type": "Name", "_fields": {"id": "_", "ctx": {"_type": "Store", "_fields": {}}}}, "is_async": 0}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "random_arrays", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "ListComp", "_fields": {"elt": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "convert_to_tensor", "value": {"_type": "Name", "_fields": {"id": "ops", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "dtype", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "float32", "value": {"_type": "Name", "_fields": {"id": "dtypes_lib", "ctx": {"_type": "Load", "_fields": {}}}}}}}}]}}, "generators": [{"_type": "comprehension", "_fields": {"ifs": [], "iter": {"_type": "Name", "_fields": {"id": "random_arrays", "ctx": {"_type": "Load", "_fields": {}}}}, "target": {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Store", "_fields": {}}}}, "is_async": 0}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "random_tensors", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "random_tensors", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "accumulate_n", "value": {"_type": "Name", "_fields": {"id": "math_ops", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "tf_val", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "value": {"_type": "Name", "_fields": {"id": "random_arrays", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "np_val", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "For", "_fields": {"body": [{"_type": "AugAssign", "_fields": {"op": {"_type": "Add", "_fields": {}}, "value": {"_type": "Name", "_fields": {"id": "random_array", "ctx": {"_type": "Load", "_fields": {}}}}, "target": {"_type": "Name", "_fields": {"id": "np_val", "ctx": {"_type": "Store", "_fields": {}}}}}}], "iter": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Slice", "_fields": {"step": null, "lower": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, "upper": null}}, "value": {"_type": "Name", "_fields": {"id": "random_arrays", "ctx": {"_type": "Load", "_fields": {}}}}}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "random_array", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "np_val", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "eval", "value": {"_type": "Name", "_fields": {"id": "tf_val", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertAllClose", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "items": [{"_type": "withitem", "_fields": {"context_expr": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "cached_session", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "optional_vars": null}}], "type_comment": null}}], "name": "testSimple", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def testSimple(self): with self.cached_session(): random_arrays = [ np.random.rand(16, 16, 16, 16).astype(np.float32) for _ in range(20) ] random_tensors = [ ops.convert_to_tensor(x, dtype=dtypes_lib.float32) for x in random_arrays ] tf_val = math_ops.accumulate_n(random_tensors) np_val = random_arrays[0] for random_array in random_arrays[1:]: np_val += random_array self.assertAllClose(np_val, tf_val.eval())
10,904
[ -0.012791709043085575, 0.002606112975627184, 0.04522739350795746, -0.018317338079214096, 0.03410311043262482, -0.028893927112221718, -0.01175717543810606, 0.005388705059885979, 0.04495963081717491, 0.048732638359069824, 0.046493176370859146, -0.002943857805803418, 0.02848011441528797, 0.00...
14
{"_type": "Module", "_fields": {"body": [{"_type": "ClassDef", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "dtype", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "degree", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "dtype", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "astype", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 2}}, {"_type": "Constant", "_fields": {"kind": null, "value": 2}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "rand", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "random", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "ListComp", "_fields": {"elt": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "dtype", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "astype", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 2}}, {"_type": "Constant", "_fields": {"kind": null, "value": 2}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "rand", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "random", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}}}, "keywords": []}}, "generators": [{"_type": "comprehension", "_fields": {"ifs": [], "iter": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "degree", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}}}], "func": {"_type": "Name", "_fields": {"id": "range", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "target": {"_type": "Name", "_fields": {"id": "_", "ctx": {"_type": "Store", "_fields": {}}}}, "is_async": 0}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "coeffs", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "coeffs", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "polyval", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "np_val", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "With", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "coeffs", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "polyval", "value": {"_type": "Name", "_fields": {"id": "math_ops", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "tf_val", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "np_val", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "eval", "value": {"_type": "Name", "_fields": {"id": "tf_val", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertAllClose", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "items": [{"_type": "withitem", "_fields": {"context_expr": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "cached_session", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "optional_vars": null}}], "type_comment": null}}], "name": "_runtest", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "For", "_fields": {"body": [{"_type": "For", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "dtype", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "degree", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_runtest", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "iter": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 5}}], "func": {"_type": "Name", "_fields": {"id": "range", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "degree", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}], "iter": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "int32", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "float32", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "float64", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "complex64", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "complex128", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "dtype", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}], "name": "testSimple", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "float32", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "dtype", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": 3}}, "targets": [{"_type": "Name", "_fields": {"id": "degree", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}]}}, {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 2}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}]}}, {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 2}}]}}, {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 2}}, {"_type": "Constant", "_fields": {"kind": null, "value": 2}}]}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "shapes", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "For", "_fields": {"body": [{"_type": "For", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "dtype", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "astype", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Starred", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "value": {"_type": "Name", "_fields": {"id": "x_shape", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "rand", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "random", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "ListComp", "_fields": {"elt": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "dtype", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "astype", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Starred", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "value": {"_type": "Name", "_fields": {"id": "coeff_shape", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "rand", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "random", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}}}, "keywords": []}}, "generators": [{"_type": "comprehension", "_fields": {"ifs": [], "iter": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "degree", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}}}], "func": {"_type": "Name", "_fields": {"id": "range", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "target": {"_type": "Name", "_fields": {"id": "_", "ctx": {"_type": "Store", "_fields": {}}}}, "is_async": 0}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "coeffs", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "coeffs", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "polyval", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "np_val", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "With", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "coeffs", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "polyval", "value": {"_type": "Name", "_fields": {"id": "math_ops", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "tf_val", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "np_val", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "eval", "value": {"_type": "Name", "_fields": {"id": "tf_val", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertAllClose", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "items": [{"_type": "withitem", "_fields": {"context_expr": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "cached_session", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "optional_vars": null}}], "type_comment": null}}], "iter": {"_type": "Name", "_fields": {"id": "shapes", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "coeff_shape", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}], "iter": {"_type": "Name", "_fields": {"id": "shapes", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "x_shape", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}], "name": "testBroadcast", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "float32", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "astype", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 2}}, {"_type": "Constant", "_fields": {"kind": null, "value": 2}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "rand", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "random", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}, "targets": [{"_type": "Name", "_fields": {"id": "coeffs", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "coeffs", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "polyval", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "np_val", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "With", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "coeffs", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "polyval", "value": {"_type": "Name", "_fields": {"id": "math_ops", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "tf_val", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "np_val", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "eval", "value": {"_type": "Name", "_fields": {"id": "tf_val", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertAllClose", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "items": [{"_type": "withitem", "_fields": {"context_expr": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "cached_session", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "optional_vars": null}}], "type_comment": null}}], "name": "testEmpty", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "name": "PolyvalTest", "bases": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "TestCase", "value": {"_type": "Name", "_fields": {"id": "test", "ctx": {"_type": "Load", "_fields": {}}}}}}], "keywords": [], "type_params": [], "decorator_list": []}}], "type_ignores": []}}
class PolyvalTest(test.TestCase): def _runtest(self, dtype, degree): x = np.random.rand(2, 2).astype(dtype) coeffs = [np.random.rand(2, 2).astype(dtype) for _ in range(degree + 1)] np_val = np.polyval(coeffs, x) with self.cached_session(): tf_val = math_ops.polyval(coeffs, x) self.assertAllClose(np_val, tf_val.eval()) def testSimple(self): for dtype in [ np.int32, np.float32, np.float64, np.complex64, np.complex128 ]: for degree in range(5): self._runtest(dtype, degree) def testBroadcast(self): dtype = np.float32 degree = 3 shapes = [(1,), (2, 1), (1, 2), (2, 2)] for x_shape in shapes: for coeff_shape in shapes: x = np.random.rand(*x_shape).astype(dtype) coeffs = [ np.random.rand(*coeff_shape).astype(dtype) for _ in range(degree + 1) ] np_val = np.polyval(coeffs, x) with self.cached_session(): tf_val = math_ops.polyval(coeffs, x) self.assertAllClose(np_val, tf_val.eval()) def testEmpty(self): x = np.random.rand(2, 2).astype(np.float32) coeffs = [] np_val = np.polyval(coeffs, x) with self.cached_session(): tf_val = math_ops.polyval(coeffs, x) self.assertAllClose(np_val, tf_val.eval())
10,905
[ 0.022208627313375473, -0.005561253987252712, -0.0032688286155462265, -0.0029140484984964132, -0.0010597917716950178, -0.017077961936593056, 0.0015965104103088379, 0.01681111752986908, 0.0440291203558445, -0.013026797212660313, 0.008211491629481316, -0.04301026463508606, -0.025422874838113785...
13
{"_type": "Module", "_fields": {"body": [{"_type": "ClassDef", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "request", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Try", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "/mobile"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "info", "value": {"_type": "Name", "_fields": {"id": "logger", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Authenticating user..."}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "info", "value": {"_type": "Name", "_fields": {"id": "logger", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "HTTP_FACEBOOKID"}}, {"_type": "Constant", "_fields": {"kind": null, "value": null}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "META", "value": {"_type": "Name", "_fields": {"id": "request", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "facebook_id", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "HTTP_GOOGLEID"}}, {"_type": "Constant", "_fields": {"kind": null, "value": null}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "META", "value": {"_type": "Name", "_fields": {"id": "request", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "google_id", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "HTTP_TOKEN"}}, {"_type": "Constant", "_fields": {"kind": null, "value": null}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "META", "value": {"_type": "Name", "_fields": {"id": "request", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "token", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "HTTP_TOKENTYPE"}}, {"_type": "Constant", "_fields": {"kind": null, "value": null}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "META", "value": {"_type": "Name", "_fields": {"id": "request", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "token_type", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "access_token"}}, "targets": [{"_type": "Name", "_fields": {"id": "token_type", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Is", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "token_type", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}]}}, "orelse": []}}, {"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Facebook id was not provided."}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "warning", "value": {"_type": "Name", "_fields": {"id": "logger", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Is", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "facebook_id", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}]}}, "orelse": []}}, {"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Google id was not provided."}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "warning", "value": {"_type": "Name", "_fields": {"id": "logger", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Is", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "google_id", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}]}}, "orelse": []}}, {"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Token was not provided."}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "warning", "value": {"_type": "Name", "_fields": {"id": "logger", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Is", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "token", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}]}}, "orelse": []}}, {"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Authentication failed. A Facebook id or a Google id and a token was not provided."}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "warning", "value": {"_type": "Name", "_fields": {"id": "logger", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "You should provide a Facebook id or a Google id and a token."}}], "func": {"_type": "Name", "_fields": {"id": "HttpResponse", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "status", "value": {"_type": "Constant", "_fields": {"kind": null, "value": 400}}}}]}}}}], "test": {"_type": "BoolOp", "_fields": {"op": {"_type": "Or", "_fields": {}}, "values": [{"_type": "BoolOp", "_fields": {"op": {"_type": "And", "_fields": {}}, "values": [{"_type": "Compare", "_fields": {"ops": [{"_type": "Is", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "facebook_id", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}]}}, {"_type": "Compare", "_fields": {"ops": [{"_type": "Is", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "google_id", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}]}}]}}, {"_type": "Compare", "_fields": {"ops": [{"_type": "Is", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "token", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}]}}]}}, "orelse": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "IfExp", "_fields": {"body": {"_type": "Name", "_fields": {"id": "facebook_id", "ctx": {"_type": "Load", "_fields": {}}}}, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "IsNot", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "facebook_id", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}]}}, "orelse": {"_type": "Name", "_fields": {"id": "google_id", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "user_id", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "sha1", "value": {"_type": "Name", "_fields": {"id": "hashlib", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "hash", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "token", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "update", "value": {"_type": "Name", "_fields": {"id": "hash", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "user_id", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Slice", "_fields": {"step": null, "lower": null, "upper": {"_type": "Constant", "_fields": {"kind": null, "value": 100}}}}, "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "hexdigest", "value": {"_type": "Name", "_fields": {"id": "hash", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "token_hash", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "memcache_connection", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "mc", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "token_hash", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Name", "_fields": {"id": "mc", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Token was found in cache."}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "info", "value": {"_type": "Name", "_fields": {"id": "logger", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Authentication failed. The provided Facebook access token is related to another user."}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "warning", "value": {"_type": "Name", "_fields": {"id": "logger", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "This access token is related to another user."}}], "func": {"_type": "Name", "_fields": {"id": "HttpResponse", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "status", "value": {"_type": "Constant", "_fields": {"kind": null, "value": 401}}}}]}}}}], "test": {"_type": "BoolOp", "_fields": {"op": {"_type": "Or", "_fields": {}}, "values": [{"_type": "BoolOp", "_fields": {"op": {"_type": "And", "_fields": {}}, "values": [{"_type": "Compare", "_fields": {"ops": [{"_type": "IsNot", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "google_id", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}]}}, {"_type": "UnaryOp", "_fields": {"op": {"_type": "Not", "_fields": {}}, "operand": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Name", "_fields": {"id": "google_id", "ctx": {"_type": "Load", "_fields": {}}}}]}}}}]}}, {"_type": "BoolOp", "_fields": {"op": {"_type": "And", "_fields": {}}, "values": [{"_type": "Compare", "_fields": {"ops": [{"_type": "IsNot", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "facebook_id", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}]}}, {"_type": "UnaryOp", "_fields": {"op": {"_type": "Not", "_fields": {}}, "operand": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Name", "_fields": {"id": "facebook_id", "ctx": {"_type": "Load", "_fields": {}}}}]}}}}]}}]}}, "orelse": [{"_type": "Return", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}]}}], "test": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": []}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Token was not found in cache."}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "info", "value": {"_type": "Name", "_fields": {"id": "logger", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Validating Facebook token..."}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "info", "value": {"_type": "Name", "_fields": {"id": "logger", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "https://graph.facebook.com/me"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Name", "_fields": {"id": "requests", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "params", "value": {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "id"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "access_token"}}], "values": [{"_type": "Name", "_fields": {"id": "facebook_id", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "token", "ctx": {"_type": "Load", "_fields": {}}}}]}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "response", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "token_hash", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "delete", "value": {"_type": "Name", "_fields": {"id": "mc", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Authentication failed. An error occurred while validating Facebook token."}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "warning", "value": {"_type": "Name", "_fields": {"id": "logger", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Error validating Facebook token."}}], "func": {"_type": "Name", "_fields": {"id": "HttpResponse", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "status", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "status_code", "value": {"_type": "Name", "_fields": {"id": "response", "ctx": {"_type": "Load", "_fields": {}}}}}}}}]}}}}], "test": {"_type": "UnaryOp", "_fields": {"op": {"_type": "Not", "_fields": {}}, "operand": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "status_code", "value": {"_type": "Name", "_fields": {"id": "response", "ctx": {"_type": "Load", "_fields": {}}}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 200}}]}}}}, "orelse": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "token_hash", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "facebook_id", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": 7200}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "set", "value": {"_type": "Name", "_fields": {"id": "mc", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Authentication ok."}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "info", "value": {"_type": "Name", "_fields": {"id": "logger", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Return", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}]}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "IsNot", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "facebook_id", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}]}}, "orelse": []}}, {"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Validating Google token..."}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "info", "value": {"_type": "Name", "_fields": {"id": "logger", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "https://www.googleapis.com/oauth2/v1/tokeninfo"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Name", "_fields": {"id": "requests", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "params", "value": {"_type": "Dict", "_fields": {"keys": [{"_type": "Name", "_fields": {"id": "token_type", "ctx": {"_type": "Load", "_fields": {}}}}], "values": [{"_type": "Name", "_fields": {"id": "token", "ctx": {"_type": "Load", "_fields": {}}}}]}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "response", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "token_hash", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "delete", "value": {"_type": "Name", "_fields": {"id": "mc", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Authentication failed. An error occurred while validating Google token."}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "warning", "value": {"_type": "Name", "_fields": {"id": "logger", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Error validating Google token."}}], "func": {"_type": "Name", "_fields": {"id": "HttpResponse", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "status", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "status_code", "value": {"_type": "Name", "_fields": {"id": "response", "ctx": {"_type": "Load", "_fields": {}}}}}}}}]}}}}], "test": {"_type": "UnaryOp", "_fields": {"op": {"_type": "Not", "_fields": {}}, "operand": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "status_code", "value": {"_type": "Name", "_fields": {"id": "response", "ctx": {"_type": "Load", "_fields": {}}}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 200}}]}}}}, "orelse": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_content", "value": {"_type": "Name", "_fields": {"id": "response", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "loads", "value": {"_type": "Name", "_fields": {"id": "json", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "json_response", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Authentication failed. The provided Google access token is related to another user."}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "warning", "value": {"_type": "Name", "_fields": {"id": "logger", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "This access token is related to another user."}}], "func": {"_type": "Name", "_fields": {"id": "HttpResponse", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "status", "value": {"_type": "Constant", "_fields": {"kind": null, "value": 401}}}}]}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "NotEq", "_fields": {}}], "left": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "user_id"}}, "value": {"_type": "Name", "_fields": {"id": "json_response", "ctx": {"_type": "Load", "_fields": {}}}}}}, "comparators": [{"_type": "Name", "_fields": {"id": "google_id", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Authentication ok."}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "info", "value": {"_type": "Name", "_fields": {"id": "logger", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "token_hash", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "google_id", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "expires_in"}}, "value": {"_type": "Name", "_fields": {"id": "json_response", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "int", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "set", "value": {"_type": "Name", "_fields": {"id": "mc", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Return", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}]}}]}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "IsNot", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "google_id", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}]}}, "orelse": []}}], "orelse": [], "handlers": [{"_type": "ExceptHandler", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "format_exc", "value": {"_type": "Name", "_fields": {"id": "traceback", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "critical", "value": {"_type": "Name", "_fields": {"id": "logger", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Raise", "_fields": {"exc": null, "cause": null}}], "name": null, "type": null}}], "finalbody": []}}], "name": "process_request", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "name": "MobileMiddleware", "bases": [{"_type": "Name", "_fields": {"id": "object", "ctx": {"_type": "Load", "_fields": {}}}}], "keywords": [], "type_params": [], "decorator_list": []}}], "type_ignores": []}}
class MobileMiddleware(object): def process_request(self, request): try: logger.info('/mobile') logger.info('Authenticating user...') # region Getting data from meta. facebook_id = request.META.get('HTTP_FACEBOOKID', None) google_id = request.META.get('HTTP_GOOGLEID', None) token = request.META.get('HTTP_TOKEN', None) token_type = request.META.get('HTTP_TOKENTYPE', None) if token_type is None: token_type = "access_token" if facebook_id is None: logger.warning("Facebook id was not provided.") if google_id is None: logger.warning("Google id was not provided.") if token is None: logger.warning("Token was not provided.") if (facebook_id is None and google_id is None) or token is None: logger.warning('Authentication failed. A Facebook id or a Google id and a token was not provided.') return HttpResponse('You should provide a Facebook id or a Google id and a token.', status=400) # endregion # region Encoding token. user_id = facebook_id if facebook_id is not None else google_id hash = hashlib.sha1() hash.update(token) token_hash = user_id + hash.hexdigest()[:100] # endregion mc = memcache_connection() value = mc.get(token_hash) # region Validating token if it was found in cache. if value: logger.info('Token was found in cache.') if (google_id is not None and not value == google_id) or \ (facebook_id is not None and not value == facebook_id): logger.warning( 'Authentication failed. The provided Facebook access token is related to another user.') return HttpResponse('This access token is related to another user.', status=401) else: return None # endregion logger.info('Token was not found in cache.') # region Validating Facebook token. if facebook_id is not None: logger.info("Validating Facebook token...") response = requests.get("https://graph.facebook.com/me", params={'id': facebook_id, 'access_token': token}) if not response.status_code == 200: mc.delete(token_hash) logger.warning('Authentication failed. An error occurred while validating Facebook token.') return HttpResponse('Error validating Facebook token.', status=response.status_code) else: mc.set(token_hash, facebook_id, 7200) logger.info('Authentication ok.') return None # endregion # region Validating Google token. if google_id is not None: logger.info("Validating Google token...") response = requests.get('https://www.googleapis.com/oauth2/v1/tokeninfo', params={token_type: token}) if not response.status_code == 200: mc.delete(token_hash) logger.warning('Authentication failed. An error occurred while validating Google token.') return HttpResponse('Error validating Google token.', status=response.status_code) else: json_response = json.loads(response._content) if json_response['user_id'] != google_id: logger.warning( 'Authentication failed. The provided Google access token is related to another user.') return HttpResponse('This access token is related to another user.', status=401) else: logger.info('Authentication ok.') mc.set(token_hash, google_id, int(json_response['expires_in'])) return None # endregion except: logger.critical(traceback.format_exc()) raise
10,906
[ 0.0027337034698575735, -0.009602367877960205, 0.05665084347128868, -0.00955857802182436, 0.024384383112192154, -0.01917971298098564, 0.0005399376968853176, 0.013699795119464397, 0.04286346957087517, 0.014763249084353447, 0.038334403187036514, 0.011604164727032185, 0.011266360990703106, 0.0...
13
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "float32", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "dtype", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": 3}}, "targets": [{"_type": "Name", "_fields": {"id": "degree", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}]}}, {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 2}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}]}}, {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "Constant", "_fields": {"kind": null, "value": 2}}]}}, {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 2}}, {"_type": "Constant", "_fields": {"kind": null, "value": 2}}]}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "shapes", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "For", "_fields": {"body": [{"_type": "For", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "dtype", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "astype", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Starred", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "value": {"_type": "Name", "_fields": {"id": "x_shape", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "rand", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "random", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "ListComp", "_fields": {"elt": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "dtype", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "astype", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Starred", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "value": {"_type": "Name", "_fields": {"id": "coeff_shape", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "rand", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "random", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}}}, "keywords": []}}, "generators": [{"_type": "comprehension", "_fields": {"ifs": [], "iter": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "degree", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}}}], "func": {"_type": "Name", "_fields": {"id": "range", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "target": {"_type": "Name", "_fields": {"id": "_", "ctx": {"_type": "Store", "_fields": {}}}}, "is_async": 0}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "coeffs", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "coeffs", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "polyval", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "np_val", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "With", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "coeffs", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "polyval", "value": {"_type": "Name", "_fields": {"id": "math_ops", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "tf_val", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "np_val", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "eval", "value": {"_type": "Name", "_fields": {"id": "tf_val", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertAllClose", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "items": [{"_type": "withitem", "_fields": {"context_expr": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "cached_session", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "optional_vars": null}}], "type_comment": null}}], "iter": {"_type": "Name", "_fields": {"id": "shapes", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "coeff_shape", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}], "iter": {"_type": "Name", "_fields": {"id": "shapes", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "x_shape", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}], "name": "testBroadcast", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def testBroadcast(self): dtype = np.float32 degree = 3 shapes = [(1,), (2, 1), (1, 2), (2, 2)] for x_shape in shapes: for coeff_shape in shapes: x = np.random.rand(*x_shape).astype(dtype) coeffs = [ np.random.rand(*coeff_shape).astype(dtype) for _ in range(degree + 1) ] np_val = np.polyval(coeffs, x) with self.cached_session(): tf_val = math_ops.polyval(coeffs, x) self.assertAllClose(np_val, tf_val.eval())
10,907
[ 0.026497015729546547, -0.02206854522228241, -0.006624253932386637, 0.007466893643140793, 0.021096741780638695, -0.011649338528513908, 0.030679460614919662, 0.0220931489020586, 0.04792589321732521, 0.015844084322452545, 0.014884581789374352, -0.01931305229663849, -0.01029004342854023, 0.001...
12
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "request", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Try", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "/mobile"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "info", "value": {"_type": "Name", "_fields": {"id": "logger", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Authenticating user..."}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "info", "value": {"_type": "Name", "_fields": {"id": "logger", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "HTTP_FACEBOOKID"}}, {"_type": "Constant", "_fields": {"kind": null, "value": null}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "META", "value": {"_type": "Name", "_fields": {"id": "request", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "facebook_id", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "HTTP_GOOGLEID"}}, {"_type": "Constant", "_fields": {"kind": null, "value": null}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "META", "value": {"_type": "Name", "_fields": {"id": "request", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "google_id", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "HTTP_TOKEN"}}, {"_type": "Constant", "_fields": {"kind": null, "value": null}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "META", "value": {"_type": "Name", "_fields": {"id": "request", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "token", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "HTTP_TOKENTYPE"}}, {"_type": "Constant", "_fields": {"kind": null, "value": null}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "META", "value": {"_type": "Name", "_fields": {"id": "request", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "token_type", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "access_token"}}, "targets": [{"_type": "Name", "_fields": {"id": "token_type", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Is", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "token_type", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}]}}, "orelse": []}}, {"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Facebook id was not provided."}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "warning", "value": {"_type": "Name", "_fields": {"id": "logger", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Is", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "facebook_id", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}]}}, "orelse": []}}, {"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Google id was not provided."}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "warning", "value": {"_type": "Name", "_fields": {"id": "logger", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Is", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "google_id", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}]}}, "orelse": []}}, {"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Token was not provided."}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "warning", "value": {"_type": "Name", "_fields": {"id": "logger", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Is", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "token", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}]}}, "orelse": []}}, {"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Authentication failed. A Facebook id or a Google id and a token was not provided."}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "warning", "value": {"_type": "Name", "_fields": {"id": "logger", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "You should provide a Facebook id or a Google id and a token."}}], "func": {"_type": "Name", "_fields": {"id": "HttpResponse", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "status", "value": {"_type": "Constant", "_fields": {"kind": null, "value": 400}}}}]}}}}], "test": {"_type": "BoolOp", "_fields": {"op": {"_type": "Or", "_fields": {}}, "values": [{"_type": "BoolOp", "_fields": {"op": {"_type": "And", "_fields": {}}, "values": [{"_type": "Compare", "_fields": {"ops": [{"_type": "Is", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "facebook_id", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}]}}, {"_type": "Compare", "_fields": {"ops": [{"_type": "Is", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "google_id", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}]}}]}}, {"_type": "Compare", "_fields": {"ops": [{"_type": "Is", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "token", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}]}}]}}, "orelse": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "IfExp", "_fields": {"body": {"_type": "Name", "_fields": {"id": "facebook_id", "ctx": {"_type": "Load", "_fields": {}}}}, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "IsNot", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "facebook_id", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}]}}, "orelse": {"_type": "Name", "_fields": {"id": "google_id", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "user_id", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "sha1", "value": {"_type": "Name", "_fields": {"id": "hashlib", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "hash", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "token", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "update", "value": {"_type": "Name", "_fields": {"id": "hash", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "user_id", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Slice", "_fields": {"step": null, "lower": null, "upper": {"_type": "Constant", "_fields": {"kind": null, "value": 100}}}}, "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "hexdigest", "value": {"_type": "Name", "_fields": {"id": "hash", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "token_hash", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "memcache_connection", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "mc", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "token_hash", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Name", "_fields": {"id": "mc", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Token was found in cache."}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "info", "value": {"_type": "Name", "_fields": {"id": "logger", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Authentication failed. The provided Facebook access token is related to another user."}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "warning", "value": {"_type": "Name", "_fields": {"id": "logger", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "This access token is related to another user."}}], "func": {"_type": "Name", "_fields": {"id": "HttpResponse", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "status", "value": {"_type": "Constant", "_fields": {"kind": null, "value": 401}}}}]}}}}], "test": {"_type": "BoolOp", "_fields": {"op": {"_type": "Or", "_fields": {}}, "values": [{"_type": "BoolOp", "_fields": {"op": {"_type": "And", "_fields": {}}, "values": [{"_type": "Compare", "_fields": {"ops": [{"_type": "IsNot", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "google_id", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}]}}, {"_type": "UnaryOp", "_fields": {"op": {"_type": "Not", "_fields": {}}, "operand": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Name", "_fields": {"id": "google_id", "ctx": {"_type": "Load", "_fields": {}}}}]}}}}]}}, {"_type": "BoolOp", "_fields": {"op": {"_type": "And", "_fields": {}}, "values": [{"_type": "Compare", "_fields": {"ops": [{"_type": "IsNot", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "facebook_id", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}]}}, {"_type": "UnaryOp", "_fields": {"op": {"_type": "Not", "_fields": {}}, "operand": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Name", "_fields": {"id": "facebook_id", "ctx": {"_type": "Load", "_fields": {}}}}]}}}}]}}]}}, "orelse": [{"_type": "Return", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}]}}], "test": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": []}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Token was not found in cache."}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "info", "value": {"_type": "Name", "_fields": {"id": "logger", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Validating Facebook token..."}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "info", "value": {"_type": "Name", "_fields": {"id": "logger", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "https://graph.facebook.com/me"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Name", "_fields": {"id": "requests", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "params", "value": {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "id"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "access_token"}}], "values": [{"_type": "Name", "_fields": {"id": "facebook_id", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "token", "ctx": {"_type": "Load", "_fields": {}}}}]}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "response", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "token_hash", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "delete", "value": {"_type": "Name", "_fields": {"id": "mc", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Authentication failed. An error occurred while validating Facebook token."}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "warning", "value": {"_type": "Name", "_fields": {"id": "logger", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Error validating Facebook token."}}], "func": {"_type": "Name", "_fields": {"id": "HttpResponse", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "status", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "status_code", "value": {"_type": "Name", "_fields": {"id": "response", "ctx": {"_type": "Load", "_fields": {}}}}}}}}]}}}}], "test": {"_type": "UnaryOp", "_fields": {"op": {"_type": "Not", "_fields": {}}, "operand": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "status_code", "value": {"_type": "Name", "_fields": {"id": "response", "ctx": {"_type": "Load", "_fields": {}}}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 200}}]}}}}, "orelse": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "token_hash", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "facebook_id", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": 7200}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "set", "value": {"_type": "Name", "_fields": {"id": "mc", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Authentication ok."}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "info", "value": {"_type": "Name", "_fields": {"id": "logger", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Return", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}]}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "IsNot", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "facebook_id", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}]}}, "orelse": []}}, {"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Validating Google token..."}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "info", "value": {"_type": "Name", "_fields": {"id": "logger", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "https://www.googleapis.com/oauth2/v1/tokeninfo"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Name", "_fields": {"id": "requests", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "params", "value": {"_type": "Dict", "_fields": {"keys": [{"_type": "Name", "_fields": {"id": "token_type", "ctx": {"_type": "Load", "_fields": {}}}}], "values": [{"_type": "Name", "_fields": {"id": "token", "ctx": {"_type": "Load", "_fields": {}}}}]}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "response", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "token_hash", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "delete", "value": {"_type": "Name", "_fields": {"id": "mc", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Authentication failed. An error occurred while validating Google token."}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "warning", "value": {"_type": "Name", "_fields": {"id": "logger", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Error validating Google token."}}], "func": {"_type": "Name", "_fields": {"id": "HttpResponse", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "status", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "status_code", "value": {"_type": "Name", "_fields": {"id": "response", "ctx": {"_type": "Load", "_fields": {}}}}}}}}]}}}}], "test": {"_type": "UnaryOp", "_fields": {"op": {"_type": "Not", "_fields": {}}, "operand": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "status_code", "value": {"_type": "Name", "_fields": {"id": "response", "ctx": {"_type": "Load", "_fields": {}}}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 200}}]}}}}, "orelse": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_content", "value": {"_type": "Name", "_fields": {"id": "response", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "loads", "value": {"_type": "Name", "_fields": {"id": "json", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "json_response", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Authentication failed. The provided Google access token is related to another user."}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "warning", "value": {"_type": "Name", "_fields": {"id": "logger", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "This access token is related to another user."}}], "func": {"_type": "Name", "_fields": {"id": "HttpResponse", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "status", "value": {"_type": "Constant", "_fields": {"kind": null, "value": 401}}}}]}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "NotEq", "_fields": {}}], "left": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "user_id"}}, "value": {"_type": "Name", "_fields": {"id": "json_response", "ctx": {"_type": "Load", "_fields": {}}}}}}, "comparators": [{"_type": "Name", "_fields": {"id": "google_id", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Authentication ok."}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "info", "value": {"_type": "Name", "_fields": {"id": "logger", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "token_hash", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "google_id", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "expires_in"}}, "value": {"_type": "Name", "_fields": {"id": "json_response", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "int", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "set", "value": {"_type": "Name", "_fields": {"id": "mc", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Return", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}]}}]}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "IsNot", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "google_id", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}]}}, "orelse": []}}], "orelse": [], "handlers": [{"_type": "ExceptHandler", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "format_exc", "value": {"_type": "Name", "_fields": {"id": "traceback", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "critical", "value": {"_type": "Name", "_fields": {"id": "logger", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Raise", "_fields": {"exc": null, "cause": null}}], "name": null, "type": null}}], "finalbody": []}}], "name": "process_request", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def process_request(self, request): try: logger.info('/mobile') logger.info('Authenticating user...') # region Getting data from meta. facebook_id = request.META.get('HTTP_FACEBOOKID', None) google_id = request.META.get('HTTP_GOOGLEID', None) token = request.META.get('HTTP_TOKEN', None) token_type = request.META.get('HTTP_TOKENTYPE', None) if token_type is None: token_type = "access_token" if facebook_id is None: logger.warning("Facebook id was not provided.") if google_id is None: logger.warning("Google id was not provided.") if token is None: logger.warning("Token was not provided.") if (facebook_id is None and google_id is None) or token is None: logger.warning('Authentication failed. A Facebook id or a Google id and a token was not provided.') return HttpResponse('You should provide a Facebook id or a Google id and a token.', status=400) # endregion # region Encoding token. user_id = facebook_id if facebook_id is not None else google_id hash = hashlib.sha1() hash.update(token) token_hash = user_id + hash.hexdigest()[:100] # endregion mc = memcache_connection() value = mc.get(token_hash) # region Validating token if it was found in cache. if value: logger.info('Token was found in cache.') if (google_id is not None and not value == google_id) or \ (facebook_id is not None and not value == facebook_id): logger.warning( 'Authentication failed. The provided Facebook access token is related to another user.') return HttpResponse('This access token is related to another user.', status=401) else: return None # endregion logger.info('Token was not found in cache.') # region Validating Facebook token. if facebook_id is not None: logger.info("Validating Facebook token...") response = requests.get("https://graph.facebook.com/me", params={'id': facebook_id, 'access_token': token}) if not response.status_code == 200: mc.delete(token_hash) logger.warning('Authentication failed. An error occurred while validating Facebook token.') return HttpResponse('Error validating Facebook token.', status=response.status_code) else: mc.set(token_hash, facebook_id, 7200) logger.info('Authentication ok.') return None # endregion # region Validating Google token. if google_id is not None: logger.info("Validating Google token...") response = requests.get('https://www.googleapis.com/oauth2/v1/tokeninfo', params={token_type: token}) if not response.status_code == 200: mc.delete(token_hash) logger.warning('Authentication failed. An error occurred while validating Google token.') return HttpResponse('Error validating Google token.', status=response.status_code) else: json_response = json.loads(response._content) if json_response['user_id'] != google_id: logger.warning( 'Authentication failed. The provided Google access token is related to another user.') return HttpResponse('This access token is related to another user.', status=401) else: logger.info('Authentication ok.') mc.set(token_hash, google_id, int(json_response['expires_in'])) return None # endregion except: logger.critical(traceback.format_exc()) raise
10,908
[ 0.007501921616494656, 0.00713832164183259, 0.012084349989891052, -0.001431674580089748, 0.01926010102033615, -0.011517561972141266, -0.01914246566593647, 0.058518197387456894, 0.03193262591958046, 0.010047120973467827, 0.0018527554348111153, -0.04829462245106697, -0.047524645924568176, -0....
11
{"_type": "Module", "_fields": {"body": [{"_type": "ClassDef", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "request", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Try", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "HTTP_AUTHORIZATION"}}, {"_type": "Constant", "_fields": {"kind": null, "value": null}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "META", "value": {"_type": "Name", "_fields": {"id": "request", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "token", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "token", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "jwt_auth_validate_token", "value": {"_type": "Name", "_fields": {"id": "jwt_util", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "raise_exception", "value": {"_type": "Constant", "_fields": {"kind": null, "value": true}}}}]}}}}, {"_type": "Return", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}], "orelse": [], "handlers": [{"_type": "ExceptHandler", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "Exception while authenticating user. Exception: "}}, "right": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "message", "value": {"_type": "Name", "_fields": {"id": "ce", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "error", "value": {"_type": "Name", "_fields": {"id": "logger", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "message", "value": {"_type": "Name", "_fields": {"id": "ce", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "HttpResponse", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "status", "value": {"_type": "Constant", "_fields": {"kind": null, "value": 10}}}}]}}}}], "name": "ce", "type": {"_type": "Name", "_fields": {"id": "CustomException", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "ExceptHandler", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "Unexpected exception while authenticating user. Exception: "}}, "right": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "e", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "str", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "error", "value": {"_type": "Name", "_fields": {"id": "logger", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "UNEXPECTED_ERROR", "value": {"_type": "Name", "_fields": {"id": "CustomErrorMessages", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "HttpResponse", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "status", "value": {"_type": "Constant", "_fields": {"kind": null, "value": 500}}}}]}}}}], "name": "e", "type": {"_type": "Name", "_fields": {"id": "Exception", "ctx": {"_type": "Load", "_fields": {}}}}}}], "finalbody": []}}], "name": "process_request", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "name": "BackofficeAuthMiddleware", "bases": [{"_type": "Name", "_fields": {"id": "object", "ctx": {"_type": "Load", "_fields": {}}}}], "keywords": [], "type_params": [], "decorator_list": []}}], "type_ignores": []}}
class BackofficeAuthMiddleware(object): def process_request(self, request): try: token = request.META.get('HTTP_AUTHORIZATION', None) jwt_util.jwt_auth_validate_token(token, raise_exception=True) return None except CustomException as ce: logger.error('Exception while authenticating user. Exception: ' + ce.message) return HttpResponse(ce.message, status=10) except Exception as e: logger.error('Unexpected exception while authenticating user. Exception: ' + str(e)) return HttpResponse(CustomErrorMessages.UNEXPECTED_ERROR, status=500)
10,909
[ 0.00012397706450428814, -0.022716743871569633, -0.00610780343413353, -0.0030921711586415768, 0.03808575123548508, -0.026676354929804802, -0.0329219289124012, 0.06551729142665863, 0.04335162788629532, 0.01319530513137579, 0.00478112930431962, -0.01845097541809082, -0.02835000492632389, 0.00...
10
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "request", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Try", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "HTTP_AUTHORIZATION"}}, {"_type": "Constant", "_fields": {"kind": null, "value": null}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "META", "value": {"_type": "Name", "_fields": {"id": "request", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "token", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "token", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "jwt_auth_validate_token", "value": {"_type": "Name", "_fields": {"id": "jwt_util", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "raise_exception", "value": {"_type": "Constant", "_fields": {"kind": null, "value": true}}}}]}}}}, {"_type": "Return", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}], "orelse": [], "handlers": [{"_type": "ExceptHandler", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "Exception while authenticating user. Exception: "}}, "right": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "message", "value": {"_type": "Name", "_fields": {"id": "ce", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "error", "value": {"_type": "Name", "_fields": {"id": "logger", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "message", "value": {"_type": "Name", "_fields": {"id": "ce", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "HttpResponse", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "status", "value": {"_type": "Constant", "_fields": {"kind": null, "value": 10}}}}]}}}}], "name": "ce", "type": {"_type": "Name", "_fields": {"id": "CustomException", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "ExceptHandler", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "Unexpected exception while authenticating user. Exception: "}}, "right": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "e", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "str", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "error", "value": {"_type": "Name", "_fields": {"id": "logger", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "UNEXPECTED_ERROR", "value": {"_type": "Name", "_fields": {"id": "CustomErrorMessages", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "HttpResponse", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "status", "value": {"_type": "Constant", "_fields": {"kind": null, "value": 500}}}}]}}}}], "name": "e", "type": {"_type": "Name", "_fields": {"id": "Exception", "ctx": {"_type": "Load", "_fields": {}}}}}}], "finalbody": []}}], "name": "process_request", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def process_request(self, request): try: token = request.META.get('HTTP_AUTHORIZATION', None) jwt_util.jwt_auth_validate_token(token, raise_exception=True) return None except CustomException as ce: logger.error('Exception while authenticating user. Exception: ' + ce.message) return HttpResponse(ce.message, status=10) except Exception as e: logger.error('Unexpected exception while authenticating user. Exception: ' + str(e)) return HttpResponse(CustomErrorMessages.UNEXPECTED_ERROR, status=500)
10,910
[ -0.025952288880944252, 0.02620519883930683, 0.012149329297244549, 0.009260336868464947, 0.05100967362523079, -0.051476579159498215, -0.014513049274682999, 0.012373055331408978, 0.02486283890902996, 0.02791719324886799, -0.02243102714419365, -0.010019062086939812, 0.010077426210045815, -0.0...
9
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "v", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "vtype", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "If", "_fields": {"body": [{"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "ip", "value": {"_type": "Name", "_fields": {"id": "v", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "str", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "vtype", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": "address"}}]}}, "orelse": [{"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "v", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "str", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "vtype", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": "network"}}]}}, "orelse": []}}]}}], "test": {"_type": "Name", "_fields": {"id": "v", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": []}}], "name": "_empty_ipaddr_query", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def _empty_ipaddr_query(v, vtype): # We don't have any query to process, so just check what type the user # expects, and return the IP address in a correct format if v: if vtype == 'address': return str(v.ip) elif vtype == 'network': return str(v)
10,911
[ -0.0194848719984293, -0.027329744771122932, 0.017969246953725815, -0.011306560598313808, 0.005065217614173889, -0.03171899542212486, -0.012385684996843338, -0.009966747835278511, 0.008463248610496521, 0.022552495822310448, 0.015835247933864594, -0.02331637032330036, 0.03909099102020264, 0....
13
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "v", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "vtype", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "value", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "If", "_fields": {"body": [{"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "ip", "value": {"_type": "Name", "_fields": {"id": "v", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "str", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "ipconv", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "size", "value": {"_type": "Name", "_fields": {"id": "v", "ctx": {"_type": "Load", "_fields": {}}}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}]}}, "orelse": [{"_type": "If", "_fields": {"body": [{"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "ip", "value": {"_type": "Name", "_fields": {"id": "v", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "str", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "ipconv", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "NotEq", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "ip", "value": {"_type": "Name", "_fields": {"id": "v", "ctx": {"_type": "Load", "_fields": {}}}}}}, "comparators": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "network", "value": {"_type": "Name", "_fields": {"id": "v", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "orelse": [{"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": false}}, "targets": [{"_type": "Name", "_fields": {"id": "ipconv", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}]}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Gt", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "size", "value": {"_type": "Name", "_fields": {"id": "v", "ctx": {"_type": "Load", "_fields": {}}}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}]}}, "orelse": []}}]}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "int", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "."}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "split", "value": {"_type": "Name", "_fields": {"id": "ipconv", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "map", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "list", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "numbers", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "test": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "ipconv", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": "public"}}], "func": {"_type": "Name", "_fields": {"id": "ipaddr", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": []}}, {"_type": "Try", "_fields": {"body": [{"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Starred", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "value": {"_type": "Name", "_fields": {"id": "numbers", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "format", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "2002:{:02x}{:02x}:{:02x}{:02x}::1/48"}}}}, "keywords": []}}}}], "orelse": [], "handlers": [{"_type": "ExceptHandler", "_fields": {"body": [{"_type": "Return", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": false}}}}], "name": null, "type": null}}], "finalbody": []}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "version", "value": {"_type": "Name", "_fields": {"id": "v", "ctx": {"_type": "Load", "_fields": {}}}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 4}}]}}, "orelse": [{"_type": "If", "_fields": {"body": [{"_type": "If", "_fields": {"body": [{"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}}}], "test": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "v", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "str", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Constant", "_fields": {"kind": null, "value": "2002::/16"}}], "func": {"_type": "Name", "_fields": {"id": "ipaddr", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": []}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "vtype", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": "address"}}]}}, "orelse": [{"_type": "If", "_fields": {"body": [{"_type": "If", "_fields": {"body": [{"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}}}], "test": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "ip", "value": {"_type": "Name", "_fields": {"id": "v", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "str", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Constant", "_fields": {"kind": null, "value": "2002::/16"}}], "func": {"_type": "Name", "_fields": {"id": "ipaddr", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": []}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "NotEq", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "ip", "value": {"_type": "Name", "_fields": {"id": "v", "ctx": {"_type": "Load", "_fields": {}}}}}}, "comparators": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "network", "value": {"_type": "Name", "_fields": {"id": "v", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "orelse": [{"_type": "Return", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": false}}}}]}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "vtype", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": "network"}}]}}, "orelse": []}}]}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "version", "value": {"_type": "Name", "_fields": {"id": "v", "ctx": {"_type": "Load", "_fields": {}}}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 6}}]}}, "orelse": []}}]}}], "name": "_6to4_query", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def _6to4_query(v, vtype, value): if v.version == 4: if v.size == 1: ipconv = str(v.ip) elif v.size > 1: if v.ip != v.network: ipconv = str(v.ip) else: ipconv = False if ipaddr(ipconv, 'public'): numbers = list(map(int, ipconv.split('.'))) try: return '2002:{:02x}{:02x}:{:02x}{:02x}::1/48'.format(*numbers) except: return False elif v.version == 6: if vtype == 'address': if ipaddr(str(v), '2002::/16'): return value elif vtype == 'network': if v.ip != v.network: if ipaddr(str(v.ip), '2002::/16'): return value else: return False
10,912
[ 0.005854044109582901, -0.015987452119588852, -0.023248769342899323, 0.011425587348639965, 0.013015962205827236, -0.022160617634654045, -0.004752814304083586, -0.011802255176007748, 0.029484711587429047, 0.04532568156719208, 0.008888311684131622, 0.004391841124743223, 0.029296377673745155, ...
10
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "v", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "value", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "If", "_fields": {"body": [{"_type": "Try", "_fields": {"body": [{"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "ipv4", "value": {"_type": "Name", "_fields": {"id": "v", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "str", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "orelse": [], "handlers": [{"_type": "ExceptHandler", "_fields": {"body": [{"_type": "Return", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": false}}}}], "name": null, "type": null}}], "finalbody": []}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "version", "value": {"_type": "Name", "_fields": {"id": "v", "ctx": {"_type": "Load", "_fields": {}}}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 6}}]}}, "orelse": [{"_type": "Return", "_fields": {"value": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}], "name": "_ipv4_query", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def _ipv4_query(v, value): if v.version == 6: try: return str(v.ipv4()) except: return False else: return value
10,913
[ -0.018925147131085396, 0.0041582933627069, 0.016163865104317665, -0.032546013593673706, -0.013086073100566864, -0.014232059940695763, -0.04741109535098076, 0.001829485408961773, -0.0212062057107687, 0.0312363151460886, -0.012835047207772732, -0.036737050861120224, 0.03267698362469673, 0.01...
8
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "v", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "address"}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "size", "value": {"_type": "Name", "_fields": {"id": "v", "ctx": {"_type": "Load", "_fields": {}}}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}]}}, "orelse": []}}, {"_type": "If", "_fields": {"body": [{"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "address"}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "NotEq", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "ip", "value": {"_type": "Name", "_fields": {"id": "v", "ctx": {"_type": "Load", "_fields": {}}}}}}, "comparators": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "network", "value": {"_type": "Name", "_fields": {"id": "v", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "orelse": [{"_type": "Return", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "network"}}}}]}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Gt", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "size", "value": {"_type": "Name", "_fields": {"id": "v", "ctx": {"_type": "Load", "_fields": {}}}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}]}}, "orelse": []}}], "name": "_type_query", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def _type_query(v): if v.size == 1: return 'address' if v.size > 1: if v.ip != v.network: return 'address' else: return 'network'
10,914
[ -0.017639292404055595, -0.0027070462238043547, -0.0006718193180859089, 0.004523165989667177, 0.027223344892263412, -0.05596495419740677, -0.013959608040750027, -0.005830561276525259, -0.009030517190694809, 0.028889218345284462, -0.006500074174255133, 0.025494208559393883, 0.01095470786094665...
9
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "v", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "value", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "ip", "value": {"_type": "Name", "_fields": {"id": "v", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "str", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "IPAddress", "value": {"_type": "Name", "_fields": {"id": "netaddr", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "v_ip", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}}}], "test": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "v_ip", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "str", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Constant", "_fields": {"kind": null, "value": "169.254.0.0/24"}}], "func": {"_type": "Name", "_fields": {"id": "ipaddr", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": []}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "version", "value": {"_type": "Name", "_fields": {"id": "v", "ctx": {"_type": "Load", "_fields": {}}}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 4}}]}}, "orelse": [{"_type": "If", "_fields": {"body": [{"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}}}], "test": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "v_ip", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "str", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Constant", "_fields": {"kind": null, "value": "fe80::/10"}}], "func": {"_type": "Name", "_fields": {"id": "ipaddr", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": []}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "version", "value": {"_type": "Name", "_fields": {"id": "v", "ctx": {"_type": "Load", "_fields": {}}}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 6}}]}}, "orelse": []}}]}}], "name": "_link_local_query", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def _link_local_query(v, value): v_ip = netaddr.IPAddress(str(v.ip)) if v.version == 4: if ipaddr(str(v_ip), '169.254.0.0/24'): return value elif v.version == 6: if ipaddr(str(v_ip), 'fe80::/10'): return value
10,915
[ -0.0020095063373446465, 0.01725129410624504, -0.025575043633580208, 0.001923249801620841, 0.02277170866727829, -0.05071880668401718, -0.023138297721743584, -0.011989649385213852, 0.027386430650949478, 0.018146205693483353, 0.007682216819375753, -0.003345133736729622, 0.053565267473459244, ...
11
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "value", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "query", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [{"_type": "Constant", "_fields": {"kind": null, "value": ""}}], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Try", "_fields": {"body": [{"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}, "targets": [{"_type": "Name", "_fields": {"id": "_ret", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "For", "_fields": {"body": [{"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "element", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": "wrap"}}], "func": {"_type": "Name", "_fields": {"id": "ipaddr", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "append", "value": {"_type": "Name", "_fields": {"id": "_ret", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "test": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "element", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "query", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "ipaddr", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "version", "value": {"_type": "Constant", "_fields": {"kind": null, "value": false}}}}, {"_type": "keyword", "_fields": {"arg": "alias", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "ipwrap"}}}}]}}, "orelse": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "element", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "append", "value": {"_type": "Name", "_fields": {"id": "_ret", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}]}}], "iter": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "element", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}, {"_type": "Return", "_fields": {"value": {"_type": "Name", "_fields": {"id": "_ret", "ctx": {"_type": "Load", "_fields": {}}}}}}], "test": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "list", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "tuple", "ctx": {"_type": "Load", "_fields": {}}}}]}}], "func": {"_type": "Name", "_fields": {"id": "isinstance", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "query", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "ipaddr", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "version", "value": {"_type": "Constant", "_fields": {"kind": null, "value": false}}}}, {"_type": "keyword", "_fields": {"arg": "alias", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "ipwrap"}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "_ret", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "_ret", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": "wrap"}}], "func": {"_type": "Name", "_fields": {"id": "ipaddr", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "test": {"_type": "Name", "_fields": {"id": "_ret", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": [{"_type": "Return", "_fields": {"value": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}]}}], "orelse": [], "handlers": [{"_type": "ExceptHandler", "_fields": {"body": [{"_type": "Return", "_fields": {"value": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}}}], "name": null, "type": null}}], "finalbody": []}}], "name": "ipwrap", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def ipwrap(value, query = ''): try: if isinstance(value, (list, tuple)): _ret = [] for element in value: if ipaddr(element, query, version = False, alias = 'ipwrap'): _ret.append(ipaddr(element, 'wrap')) else: _ret.append(element) return _ret else: _ret = ipaddr(value, query, version = False, alias = 'ipwrap') if _ret: return ipaddr(_ret, 'wrap') else: return value except: return value
10,916
[ -0.010837015695869923, -0.007304127793759108, -0.01229890063405037, -0.012447208166122437, -0.007876169867813587, -0.014449354261159897, -0.006085890345275402, -0.011440837755799294, 0.024216439574956894, 0.030953822657465935, -0.03408946096897125, -0.009195043705403805, 0.0714840516448021, ...
13
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "v", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "vtype", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "value", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "If", "_fields": {"body": [{"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "["}}, "right": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "ip", "value": {"_type": "Name", "_fields": {"id": "v", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "str", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": "]"}}}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "vtype", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": "address"}}]}}, "orelse": [{"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "["}}, "right": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "ip", "value": {"_type": "Name", "_fields": {"id": "v", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "str", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": "]/"}}}}, "right": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "prefixlen", "value": {"_type": "Name", "_fields": {"id": "v", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "str", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "vtype", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": "network"}}]}}, "orelse": []}}]}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "version", "value": {"_type": "Name", "_fields": {"id": "v", "ctx": {"_type": "Load", "_fields": {}}}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 6}}]}}, "orelse": [{"_type": "Return", "_fields": {"value": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}], "name": "_wrap_query", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def _wrap_query(v, vtype, value): if v.version == 6: if vtype == 'address': return '[' + str(v.ip) + ']' elif vtype == 'network': return '[' + str(v.ip) + ']/' + str(v.prefixlen) else: return value
10,917
[ 0.027496686205267906, 0.017316527664661407, 0.053762175142765045, 0.019984116777777672, -0.0009184086811728776, 0.012425947934389114, 0.011143453419208527, -0.03253546357154846, -0.03404025733470917, 0.057546958327293396, -0.011377152986824512, -0.021648509427905083, 0.014078941196203232, ...
12
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": {"_type": "arg", "_fields": {"arg": "kwargs", "annotation": null, "type_comment": null}}, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "check", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "ArrayField", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "super", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": null, "value": {"_type": "Name", "_fields": {"id": "kwargs", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "errors", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Base field for array cannot be a related field."}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "Error", "value": {"_type": "Name", "_fields": {"id": "checks", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "hint", "value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}, {"_type": "keyword", "_fields": {"arg": "obj", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "keyword", "_fields": {"arg": "id", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "postgres.E002"}}}}]}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "append", "value": {"_type": "Name", "_fields": {"id": "errors", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "test": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "remote_field", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "base_field", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "orelse": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "check", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "base_field", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "base_errors", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "GeneratorExp", "_fields": {"elt": {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "%s (%s)"}}, "right": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "msg", "value": {"_type": "Name", "_fields": {"id": "error", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "id", "value": {"_type": "Name", "_fields": {"id": "error", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}, "generators": [{"_type": "comprehension", "_fields": {"ifs": [], "iter": {"_type": "Name", "_fields": {"id": "base_errors", "ctx": {"_type": "Load", "_fields": {}}}}, "target": {"_type": "Name", "_fields": {"id": "error", "ctx": {"_type": "Store", "_fields": {}}}}, "is_async": 0}}]}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "join", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "\n "}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "messages", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "Base field for array has errors:\n %s"}}, "right": {"_type": "Name", "_fields": {"id": "messages", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "Error", "value": {"_type": "Name", "_fields": {"id": "checks", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "hint", "value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}, {"_type": "keyword", "_fields": {"arg": "obj", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "keyword", "_fields": {"arg": "id", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "postgres.E001"}}}}]}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "append", "value": {"_type": "Name", "_fields": {"id": "errors", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "test": {"_type": "Name", "_fields": {"id": "base_errors", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": []}}]}}, {"_type": "Return", "_fields": {"value": {"_type": "Name", "_fields": {"id": "errors", "ctx": {"_type": "Load", "_fields": {}}}}}}], "name": "check", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def check(self, **kwargs): errors = super(ArrayField, self).check(**kwargs) if self.base_field.remote_field: errors.append( checks.Error( 'Base field for array cannot be a related field.', hint=None, obj=self, id='postgres.E002' ) ) else: # Remove the field name checks as they are not needed here. base_errors = self.base_field.check() if base_errors: messages = '\n '.join('%s (%s)' % (error.msg, error.id) for error in base_errors) errors.append( checks.Error( 'Base field for array has errors:\n %s' % messages, hint=None, obj=self, id='postgres.E001' ) ) return errors
10,918
[ 0.03583125025033951, -0.005935968365520239, 0.029708189889788628, 0.01171319093555212, 0.009768551215529442, 0.012404869310557842, 0.00620810454711318, -0.03195331245660782, -0.009133567102253437, 0.059280309826135635, -0.023517092689871788, -0.013323329389095306, 0.018766051158308983, -0....
13
{"_type": "Module", "_fields": {"body": [{"_type": "ClassDef", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": false}}, "targets": [{"_type": "Name", "_fields": {"id": "empty_strings_allowed", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "item_invalid"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "nested_array_mismatch"}}], "values": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Item %(nth)s in the array did not validate: "}}], "func": {"_type": "Name", "_fields": {"id": "_", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Nested arrays must have the same length."}}], "func": {"_type": "Name", "_fields": {"id": "_", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "default_error_messages", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "base_field", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "size", "annotation": null, "type_comment": null}}], "kwarg": {"_type": "arg", "_fields": {"arg": "kwargs", "annotation": null, "type_comment": null}}, "vararg": null, "defaults": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Name", "_fields": {"id": "base_field", "ctx": {"_type": "Load", "_fields": {}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "base_field", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Name", "_fields": {"id": "size", "ctx": {"_type": "Load", "_fields": {}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "size", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Slice", "_fields": {"step": null, "lower": null, "upper": null}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "default_validators", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "default_validators", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "size", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "ArrayMaxLengthValidator", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "append", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "default_validators", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}}}], "test": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "size", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "orelse": []}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "__init__", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "ArrayField", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "super", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": null, "value": {"_type": "Name", "_fields": {"id": "kwargs", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}], "name": "__init__", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": {"_type": "arg", "_fields": {"arg": "kwargs", "annotation": null, "type_comment": null}}, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "check", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "ArrayField", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "super", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": null, "value": {"_type": "Name", "_fields": {"id": "kwargs", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "errors", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Base field for array cannot be a related field."}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "Error", "value": {"_type": "Name", "_fields": {"id": "checks", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "hint", "value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}, {"_type": "keyword", "_fields": {"arg": "obj", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "keyword", "_fields": {"arg": "id", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "postgres.E002"}}}}]}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "append", "value": {"_type": "Name", "_fields": {"id": "errors", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "test": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "remote_field", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "base_field", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "orelse": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "check", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "base_field", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "base_errors", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "GeneratorExp", "_fields": {"elt": {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "%s (%s)"}}, "right": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "msg", "value": {"_type": "Name", "_fields": {"id": "error", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "id", "value": {"_type": "Name", "_fields": {"id": "error", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}, "generators": [{"_type": "comprehension", "_fields": {"ifs": [], "iter": {"_type": "Name", "_fields": {"id": "base_errors", "ctx": {"_type": "Load", "_fields": {}}}}, "target": {"_type": "Name", "_fields": {"id": "error", "ctx": {"_type": "Store", "_fields": {}}}}, "is_async": 0}}]}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "join", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "\n "}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "messages", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "Base field for array has errors:\n %s"}}, "right": {"_type": "Name", "_fields": {"id": "messages", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "Error", "value": {"_type": "Name", "_fields": {"id": "checks", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "hint", "value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}, {"_type": "keyword", "_fields": {"arg": "obj", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "keyword", "_fields": {"arg": "id", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "postgres.E001"}}}}]}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "append", "value": {"_type": "Name", "_fields": {"id": "errors", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "test": {"_type": "Name", "_fields": {"id": "base_errors", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": []}}]}}, {"_type": "Return", "_fields": {"value": {"_type": "Name", "_fields": {"id": "errors", "ctx": {"_type": "Load", "_fields": {}}}}}}], "name": "check", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "name", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "name", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "set_attributes_from_name", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "ArrayField", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "super", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "name", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "set_attributes_from_name", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "base_field", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}}}], "name": "set_attributes_from_name", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Return", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "Array of %s"}}, "right": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "description", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "base_field", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}}}], "name": "description", "returns": null, "type_params": [], "type_comment": null, "decorator_list": [{"_type": "Name", "_fields": {"id": "property", "ctx": {"_type": "Load", "_fields": {}}}}]}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "connection", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "BoolOp", "_fields": {"op": {"_type": "Or", "_fields": {}}, "values": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "size", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": ""}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "size", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Return", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "%s[%s]"}}, "right": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "connection", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "db_type", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "base_field", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, {"_type": "Name", "_fields": {"id": "size", "ctx": {"_type": "Load", "_fields": {}}}}]}}}}}}], "name": "db_type", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "value", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "connection", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "prepared", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [{"_type": "Constant", "_fields": {"kind": null, "value": false}}], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": {"_type": "ListComp", "_fields": {"elt": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "connection", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "prepared", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get_db_prep_value", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "base_field", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, "generators": [{"_type": "comprehension", "_fields": {"ifs": [], "iter": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}, "target": {"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Store", "_fields": {}}}}, "is_async": 0}}]}}}}], "test": {"_type": "BoolOp", "_fields": {"op": {"_type": "Or", "_fields": {}}, "values": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "list", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "isinstance", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "tuple", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "isinstance", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}]}}, "orelse": []}}, {"_type": "Return", "_fields": {"value": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}}}], "name": "get_db_prep_value", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "deconstruct", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "ArrayField", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "super", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "keywords": []}}, "targets": [{"_type": "Tuple", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "name", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "path", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "args", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "kwargs", "ctx": {"_type": "Store", "_fields": {}}}}]}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "django.contrib.postgres.fields.ArrayField"}}, "targets": [{"_type": "Name", "_fields": {"id": "path", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "path", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": "django.contrib.postgres.fields.array.ArrayField"}}]}}, "orelse": []}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "base_field"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "size"}}], "values": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "base_field", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "size", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "update", "value": {"_type": "Name", "_fields": {"id": "kwargs", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Return", "_fields": {"value": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "name", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "path", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "args", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "kwargs", "ctx": {"_type": "Load", "_fields": {}}}}]}}}}], "name": "deconstruct", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "value", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "loads", "value": {"_type": "Name", "_fields": {"id": "json", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "vals", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "ListComp", "_fields": {"elt": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "val", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "to_python", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "base_field", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, "generators": [{"_type": "comprehension", "_fields": {"ifs": [], "iter": {"_type": "Name", "_fields": {"id": "vals", "ctx": {"_type": "Load", "_fields": {}}}}, "target": {"_type": "Name", "_fields": {"id": "val", "ctx": {"_type": "Store", "_fields": {}}}}, "is_async": 0}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "test": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "string_types", "value": {"_type": "Name", "_fields": {"id": "six", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "isinstance", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": []}}, {"_type": "Return", "_fields": {"value": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}}}], "name": "to_python", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "obj", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}, "targets": [{"_type": "Name", "_fields": {"id": "values", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "obj", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_get_val_from_obj", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "vals", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "base_field", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "base_field", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "For", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "attname", "value": {"_type": "Name", "_fields": {"id": "base_field", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Name", "_fields": {"id": "val", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "AttributeSetter", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "obj", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "obj", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value_to_string", "value": {"_type": "Name", "_fields": {"id": "base_field", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "append", "value": {"_type": "Name", "_fields": {"id": "values", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "iter": {"_type": "Name", "_fields": {"id": "vals", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "val", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}, {"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "values", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "dumps", "value": {"_type": "Name", "_fields": {"id": "json", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "name": "value_to_string", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "name", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "name", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get_transform", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "ArrayField", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "super", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "transform", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": {"_type": "Name", "_fields": {"id": "transform", "ctx": {"_type": "Load", "_fields": {}}}}}}], "test": {"_type": "Name", "_fields": {"id": "transform", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": []}}, {"_type": "Try", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "name", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "int", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "index", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "orelse": [{"_type": "AugAssign", "_fields": {"op": {"_type": "Add", "_fields": {}}, "value": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, "target": {"_type": "Name", "_fields": {"id": "index", "ctx": {"_type": "Store", "_fields": {}}}}}}, {"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "index", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "base_field", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "IndexTransformFactory", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "handlers": [{"_type": "ExceptHandler", "_fields": {"body": [{"_type": "Pass", "_fields": {}}], "name": null, "type": {"_type": "Name", "_fields": {"id": "ValueError", "ctx": {"_type": "Load", "_fields": {}}}}}}], "finalbody": []}}, {"_type": "Try", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "_"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "split", "value": {"_type": "Name", "_fields": {"id": "name", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Tuple", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "start", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "end", "ctx": {"_type": "Store", "_fields": {}}}}]}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "start", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "int", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}}}, "targets": [{"_type": "Name", "_fields": {"id": "start", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "end", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "int", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "end", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "orelse": [{"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "start", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "end", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "SliceTransformFactory", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "handlers": [{"_type": "ExceptHandler", "_fields": {"body": [{"_type": "Pass", "_fields": {}}], "name": null, "type": {"_type": "Name", "_fields": {"id": "ValueError", "ctx": {"_type": "Load", "_fields": {}}}}}}], "finalbody": []}}], "name": "get_transform", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "value", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "model_instance", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "model_instance", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "validate", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "ArrayField", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "super", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "keywords": []}}}}, {"_type": "For", "_fields": {"body": [{"_type": "Try", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "part", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "model_instance", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "validate", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "base_field", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}}}], "orelse": [], "handlers": [{"_type": "ExceptHandler", "_fields": {"body": [{"_type": "Raise", "_fields": {"exc": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "item_invalid"}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "error_messages", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "message", "value": {"_type": "Name", "_fields": {"id": "e", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "string_concat", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "ValidationError", "value": {"_type": "Name", "_fields": {"id": "exceptions", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "code", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "item_invalid"}}}}, {"_type": "keyword", "_fields": {"arg": "params", "value": {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "nth"}}], "values": [{"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Load", "_fields": {}}}}]}}}}]}}, "cause": null}}], "name": "e", "type": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "ValidationError", "value": {"_type": "Name", "_fields": {"id": "exceptions", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "finalbody": []}}], "iter": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "enumerate", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [], "target": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "part", "ctx": {"_type": "Store", "_fields": {}}}}]}}, "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "If", "_fields": {"body": [{"_type": "Raise", "_fields": {"exc": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "nested_array_mismatch"}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "error_messages", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "ValidationError", "value": {"_type": "Name", "_fields": {"id": "exceptions", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "code", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "nested_array_mismatch"}}}}]}}, "cause": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Gt", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "SetComp", "_fields": {"elt": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "generators": [{"_type": "comprehension", "_fields": {"ifs": [], "iter": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}, "target": {"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Store", "_fields": {}}}}, "is_async": 0}}]}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}]}}, "orelse": []}}], "test": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "base_field", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Name", "_fields": {"id": "ArrayField", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "isinstance", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": []}}], "name": "validate", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "value", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "run_validators", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "ArrayField", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "super", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "keywords": []}}}}, {"_type": "For", "_fields": {"body": [{"_type": "Try", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "part", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "run_validators", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "base_field", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}}}], "orelse": [], "handlers": [{"_type": "ExceptHandler", "_fields": {"body": [{"_type": "Raise", "_fields": {"exc": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "item_invalid"}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "error_messages", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "messages", "value": {"_type": "Name", "_fields": {"id": "e", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "join", "value": {"_type": "Constant", "_fields": {"kind": null, "value": " "}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "string_concat", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "ValidationError", "value": {"_type": "Name", "_fields": {"id": "exceptions", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "code", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "item_invalid"}}}}, {"_type": "keyword", "_fields": {"arg": "params", "value": {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "nth"}}], "values": [{"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Load", "_fields": {}}}}]}}}}]}}, "cause": null}}], "name": "e", "type": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "ValidationError", "value": {"_type": "Name", "_fields": {"id": "exceptions", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "finalbody": []}}], "iter": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "enumerate", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [], "target": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "part", "ctx": {"_type": "Store", "_fields": {}}}}]}}, "type_comment": null}}], "name": "run_validators", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": {"_type": "arg", "_fields": {"arg": "kwargs", "annotation": null, "type_comment": null}}, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "form_class"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "base_field"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "max_length"}}], "values": [{"_type": "Name", "_fields": {"id": "SimpleArrayField", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "formfield", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "base_field", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "size", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "defaults", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "kwargs", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "update", "value": {"_type": "Name", "_fields": {"id": "defaults", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "formfield", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "ArrayField", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "super", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": null, "value": {"_type": "Name", "_fields": {"id": "defaults", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}], "name": "formfield", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "name": "ArrayField", "bases": [{"_type": "Name", "_fields": {"id": "Field", "ctx": {"_type": "Load", "_fields": {}}}}], "keywords": [], "type_params": [], "decorator_list": []}}], "type_ignores": []}}
class ArrayField(Field): empty_strings_allowed = False default_error_messages = { 'item_invalid': _('Item %(nth)s in the array did not validate: '), 'nested_array_mismatch': _('Nested arrays must have the same length.'), } def __init__(self, base_field, size=None, **kwargs): self.base_field = base_field self.size = size if self.size: self.default_validators = self.default_validators[:] self.default_validators.append(ArrayMaxLengthValidator(self.size)) super(ArrayField, self).__init__(**kwargs) def check(self, **kwargs): errors = super(ArrayField, self).check(**kwargs) if self.base_field.remote_field: errors.append( checks.Error( 'Base field for array cannot be a related field.', hint=None, obj=self, id='postgres.E002' ) ) else: # Remove the field name checks as they are not needed here. base_errors = self.base_field.check() if base_errors: messages = '\n '.join('%s (%s)' % (error.msg, error.id) for error in base_errors) errors.append( checks.Error( 'Base field for array has errors:\n %s' % messages, hint=None, obj=self, id='postgres.E001' ) ) return errors def set_attributes_from_name(self, name): super(ArrayField, self).set_attributes_from_name(name) self.base_field.set_attributes_from_name(name) @property def description(self): return 'Array of %s' % self.base_field.description def db_type(self, connection): size = self.size or '' return '%s[%s]' % (self.base_field.db_type(connection), size) def get_db_prep_value(self, value, connection, prepared=False): if isinstance(value, list) or isinstance(value, tuple): return [self.base_field.get_db_prep_value(i, connection, prepared) for i in value] return value def deconstruct(self): name, path, args, kwargs = super(ArrayField, self).deconstruct() if path == 'django.contrib.postgres.fields.array.ArrayField': path = 'django.contrib.postgres.fields.ArrayField' kwargs.update({ 'base_field': self.base_field, 'size': self.size, }) return name, path, args, kwargs def to_python(self, value): if isinstance(value, six.string_types): # Assume we're deserializing vals = json.loads(value) value = [self.base_field.to_python(val) for val in vals] return value def value_to_string(self, obj): values = [] vals = self._get_val_from_obj(obj) base_field = self.base_field for val in vals: obj = AttributeSetter(base_field.attname, val) values.append(base_field.value_to_string(obj)) return json.dumps(values) def get_transform(self, name): transform = super(ArrayField, self).get_transform(name) if transform: return transform try: index = int(name) except ValueError: pass else: index += 1 # postgres uses 1-indexing return IndexTransformFactory(index, self.base_field) try: start, end = name.split('_') start = int(start) + 1 end = int(end) # don't add one here because postgres slices are weird except ValueError: pass else: return SliceTransformFactory(start, end) def validate(self, value, model_instance): super(ArrayField, self).validate(value, model_instance) for i, part in enumerate(value): try: self.base_field.validate(part, model_instance) except exceptions.ValidationError as e: raise exceptions.ValidationError( string_concat(self.error_messages['item_invalid'], e.message), code='item_invalid', params={'nth': i}, ) if isinstance(self.base_field, ArrayField): if len({len(i) for i in value}) > 1: raise exceptions.ValidationError( self.error_messages['nested_array_mismatch'], code='nested_array_mismatch', ) def run_validators(self, value): super(ArrayField, self).run_validators(value) for i, part in enumerate(value): try: self.base_field.run_validators(part) except exceptions.ValidationError as e: raise exceptions.ValidationError( string_concat(self.error_messages['item_invalid'], ' '.join(e.messages)), code='item_invalid', params={'nth': i}, ) def formfield(self, **kwargs): defaults = { 'form_class': SimpleArrayField, 'base_field': self.base_field.formfield(), 'max_length': self.size, } defaults.update(kwargs) return super(ArrayField, self).formfield(**defaults)
10,919
[ 0.03418530523777008, -0.012213439680635929, -0.0118641909211874, 0.006758993491530418, -0.0024896825198084116, -0.0000967817468335852, 0.00002132649206032511, -0.011905279010534286, -0.010991068556904793, 0.03381551057100296, 0.006158079952001572, -0.03730800002813339, 0.038704995065927505, ...
8
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "deconstruct", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "ArrayField", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "super", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "keywords": []}}, "targets": [{"_type": "Tuple", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "name", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "path", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "args", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "kwargs", "ctx": {"_type": "Store", "_fields": {}}}}]}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "django.contrib.postgres.fields.ArrayField"}}, "targets": [{"_type": "Name", "_fields": {"id": "path", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "path", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": "django.contrib.postgres.fields.array.ArrayField"}}]}}, "orelse": []}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "base_field"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "size"}}], "values": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "base_field", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "size", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "update", "value": {"_type": "Name", "_fields": {"id": "kwargs", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Return", "_fields": {"value": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "name", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "path", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "args", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "kwargs", "ctx": {"_type": "Load", "_fields": {}}}}]}}}}], "name": "deconstruct", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def deconstruct(self): name, path, args, kwargs = super(ArrayField, self).deconstruct() if path == 'django.contrib.postgres.fields.array.ArrayField': path = 'django.contrib.postgres.fields.ArrayField' kwargs.update({ 'base_field': self.base_field, 'size': self.size, }) return name, path, args, kwargs
10,920
[ 0.03474612906575203, 0.00825122743844986, 0.0021300590597093105, -0.03277013823390007, -0.03476569429039955, -0.00012930754746776074, -0.03591998666524887, -0.05110185220837593, 0.036350399255752563, -0.019466441124677658, 0.029992014169692993, -0.005678527057170868, 0.008603384718298912, ...
9
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "obj", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}, "targets": [{"_type": "Name", "_fields": {"id": "values", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "obj", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_get_val_from_obj", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "vals", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "base_field", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "base_field", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "For", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "attname", "value": {"_type": "Name", "_fields": {"id": "base_field", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Name", "_fields": {"id": "val", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "AttributeSetter", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "obj", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "obj", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value_to_string", "value": {"_type": "Name", "_fields": {"id": "base_field", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "append", "value": {"_type": "Name", "_fields": {"id": "values", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "iter": {"_type": "Name", "_fields": {"id": "vals", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "val", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}, {"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "values", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "dumps", "value": {"_type": "Name", "_fields": {"id": "json", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "name": "value_to_string", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def value_to_string(self, obj): values = [] vals = self._get_val_from_obj(obj) base_field = self.base_field for val in vals: obj = AttributeSetter(base_field.attname, val) values.append(base_field.value_to_string(obj)) return json.dumps(values)
10,921
[ 0.0202522911131382, -0.03506430238485336, 0.00018910152721218765, -0.0024784088600426912, 0.02061356045305729, -0.02866772562265396, 0.027966439723968506, -0.026500113308429718, -0.052277687937021255, -0.009371732361614704, -0.0001271745131816715, -0.0022061290219426155, 0.037550680339336395...
8
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "name", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "name", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get_transform", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "ArrayField", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "super", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "transform", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": {"_type": "Name", "_fields": {"id": "transform", "ctx": {"_type": "Load", "_fields": {}}}}}}], "test": {"_type": "Name", "_fields": {"id": "transform", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": []}}, {"_type": "Try", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "name", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "int", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "index", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "orelse": [{"_type": "AugAssign", "_fields": {"op": {"_type": "Add", "_fields": {}}, "value": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, "target": {"_type": "Name", "_fields": {"id": "index", "ctx": {"_type": "Store", "_fields": {}}}}}}, {"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "index", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "base_field", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "IndexTransformFactory", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "handlers": [{"_type": "ExceptHandler", "_fields": {"body": [{"_type": "Pass", "_fields": {}}], "name": null, "type": {"_type": "Name", "_fields": {"id": "ValueError", "ctx": {"_type": "Load", "_fields": {}}}}}}], "finalbody": []}}, {"_type": "Try", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "_"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "split", "value": {"_type": "Name", "_fields": {"id": "name", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Tuple", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "start", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "end", "ctx": {"_type": "Store", "_fields": {}}}}]}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "start", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "int", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}}}, "targets": [{"_type": "Name", "_fields": {"id": "start", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "end", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "int", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "end", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "orelse": [{"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "start", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "end", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "SliceTransformFactory", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "handlers": [{"_type": "ExceptHandler", "_fields": {"body": [{"_type": "Pass", "_fields": {}}], "name": null, "type": {"_type": "Name", "_fields": {"id": "ValueError", "ctx": {"_type": "Load", "_fields": {}}}}}}], "finalbody": []}}], "name": "get_transform", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def get_transform(self, name): transform = super(ArrayField, self).get_transform(name) if transform: return transform try: index = int(name) except ValueError: pass else: index += 1 # postgres uses 1-indexing return IndexTransformFactory(index, self.base_field) try: start, end = name.split('_') start = int(start) + 1 end = int(end) # don't add one here because postgres slices are weird except ValueError: pass else: return SliceTransformFactory(start, end)
10,922
[ 0.04139215871691704, 0.007314533926546574, -0.015354122966527939, 0.0016420382307842374, 0.015642013400793076, 0.005469906609505415, 0.027744047343730927, -0.025142377242445946, 0.0020512149203568697, 0.04286359250545502, 0.008274166844785213, -0.013114980421960354, -0.01041734591126442, -...
12
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "value", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "model_instance", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "model_instance", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "validate", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "ArrayField", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "super", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "keywords": []}}}}, {"_type": "For", "_fields": {"body": [{"_type": "Try", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "part", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "model_instance", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "validate", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "base_field", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}}}], "orelse": [], "handlers": [{"_type": "ExceptHandler", "_fields": {"body": [{"_type": "Raise", "_fields": {"exc": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "item_invalid"}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "error_messages", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "message", "value": {"_type": "Name", "_fields": {"id": "e", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "string_concat", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "ValidationError", "value": {"_type": "Name", "_fields": {"id": "exceptions", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "code", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "item_invalid"}}}}, {"_type": "keyword", "_fields": {"arg": "params", "value": {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "nth"}}], "values": [{"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Load", "_fields": {}}}}]}}}}]}}, "cause": null}}], "name": "e", "type": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "ValidationError", "value": {"_type": "Name", "_fields": {"id": "exceptions", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "finalbody": []}}], "iter": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "enumerate", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [], "target": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "part", "ctx": {"_type": "Store", "_fields": {}}}}]}}, "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "If", "_fields": {"body": [{"_type": "Raise", "_fields": {"exc": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "nested_array_mismatch"}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "error_messages", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "ValidationError", "value": {"_type": "Name", "_fields": {"id": "exceptions", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "code", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "nested_array_mismatch"}}}}]}}, "cause": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Gt", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "SetComp", "_fields": {"elt": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "generators": [{"_type": "comprehension", "_fields": {"ifs": [], "iter": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}, "target": {"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Store", "_fields": {}}}}, "is_async": 0}}]}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}]}}, "orelse": []}}], "test": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "base_field", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Name", "_fields": {"id": "ArrayField", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "isinstance", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": []}}], "name": "validate", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def validate(self, value, model_instance): super(ArrayField, self).validate(value, model_instance) for i, part in enumerate(value): try: self.base_field.validate(part, model_instance) except exceptions.ValidationError as e: raise exceptions.ValidationError( string_concat(self.error_messages['item_invalid'], e.message), code='item_invalid', params={'nth': i}, ) if isinstance(self.base_field, ArrayField): if len({len(i) for i in value}) > 1: raise exceptions.ValidationError( self.error_messages['nested_array_mismatch'], code='nested_array_mismatch', )
10,923
[ 0.0542110912501812, -0.007655764929950237, 0.027891812846064568, 0.010831872932612896, 0.009424867108464241, -0.004715019837021828, 0.018963536247611046, -0.03176107630133629, -0.02280176430940628, 0.03722357004880905, -0.05553533136844635, -0.02936089225113392, 0.024726051837205887, -0.00...
9
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": {"_type": "arg", "_fields": {"arg": "kwargs", "annotation": null, "type_comment": null}}, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "form_class"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "base_field"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "max_length"}}], "values": [{"_type": "Name", "_fields": {"id": "SimpleArrayField", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "formfield", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "base_field", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "size", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "defaults", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "kwargs", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "update", "value": {"_type": "Name", "_fields": {"id": "defaults", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "formfield", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "ArrayField", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "super", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": null, "value": {"_type": "Name", "_fields": {"id": "defaults", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}], "name": "formfield", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def formfield(self, **kwargs): defaults = { 'form_class': SimpleArrayField, 'base_field': self.base_field.formfield(), 'max_length': self.size, } defaults.update(kwargs) return super(ArrayField, self).formfield(**defaults)
10,924
[ 0.054592616856098175, 0.037320759147405624, 0.0031665072310715914, 0.007157096639275551, 0.003496704623103142, -0.023661315441131592, 0.01536405086517334, -0.014607702381908894, 0.016052667051553726, 0.04122668132185936, 0.015251163393259048, 0.0156124047935009, -0.0036293480079621077, -0....
12
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "value", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "run_validators", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "ArrayField", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "super", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "keywords": []}}}}, {"_type": "For", "_fields": {"body": [{"_type": "Try", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "part", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "run_validators", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "base_field", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}}}], "orelse": [], "handlers": [{"_type": "ExceptHandler", "_fields": {"body": [{"_type": "Raise", "_fields": {"exc": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "item_invalid"}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "error_messages", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "messages", "value": {"_type": "Name", "_fields": {"id": "e", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "join", "value": {"_type": "Constant", "_fields": {"kind": null, "value": " "}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "string_concat", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "ValidationError", "value": {"_type": "Name", "_fields": {"id": "exceptions", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "code", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "item_invalid"}}}}, {"_type": "keyword", "_fields": {"arg": "params", "value": {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "nth"}}], "values": [{"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Load", "_fields": {}}}}]}}}}]}}, "cause": null}}], "name": "e", "type": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "ValidationError", "value": {"_type": "Name", "_fields": {"id": "exceptions", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "finalbody": []}}], "iter": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "enumerate", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [], "target": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "part", "ctx": {"_type": "Store", "_fields": {}}}}]}}, "type_comment": null}}], "name": "run_validators", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def run_validators(self, value): super(ArrayField, self).run_validators(value) for i, part in enumerate(value): try: self.base_field.run_validators(part) except exceptions.ValidationError as e: raise exceptions.ValidationError( string_concat(self.error_messages['item_invalid'], ' '.join(e.messages)), code='item_invalid', params={'nth': i}, )
10,925
[ 0.022779343649744987, -0.010094300843775272, 0.002248908393085003, -0.023815641179680824, -0.004008454270660877, -0.03584820032119751, -0.01692618429660797, -0.03172220289707184, -0.0726175531744957, 0.014009200036525726, 0.008251994848251343, -0.07016114890575409, 0.05350362882018089, -0....
10
{"_type": "Module", "_fields": {"body": [{"_type": "ClassDef", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "start", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "end", "annotation": null, "type_comment": null}}], "kwarg": {"_type": "arg", "_fields": {"arg": "kwargs", "annotation": null, "type_comment": null}}, "vararg": {"_type": "arg", "_fields": {"arg": "args", "annotation": null, "type_comment": null}}, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Starred", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "value": {"_type": "Name", "_fields": {"id": "args", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "__init__", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "SliceTransform", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "super", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": null, "value": {"_type": "Name", "_fields": {"id": "kwargs", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Name", "_fields": {"id": "start", "ctx": {"_type": "Load", "_fields": {}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "start", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Name", "_fields": {"id": "end", "ctx": {"_type": "Load", "_fields": {}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "end", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "name": "__init__", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "compiler", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "connection", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "lhs", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "compile", "value": {"_type": "Name", "_fields": {"id": "compiler", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Tuple", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "lhs", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "params", "ctx": {"_type": "Store", "_fields": {}}}}]}}], "type_comment": null}}, {"_type": "Return", "_fields": {"value": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "%s[%s:%s]"}}, "right": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "lhs", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "start", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "end", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}, {"_type": "Name", "_fields": {"id": "params", "ctx": {"_type": "Load", "_fields": {}}}}]}}}}], "name": "as_sql", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "name": "SliceTransform", "bases": [{"_type": "Name", "_fields": {"id": "Transform", "ctx": {"_type": "Load", "_fields": {}}}}], "keywords": [], "type_params": [], "decorator_list": []}}], "type_ignores": []}}
class SliceTransform(Transform): def __init__(self, start, end, *args, **kwargs): super(SliceTransform, self).__init__(*args, **kwargs) self.start = start self.end = end def as_sql(self, compiler, connection): lhs, params = compiler.compile(self.lhs) return '%s[%s:%s]' % (lhs, self.start, self.end), params
10,926
[ 0.010185524821281433, -0.016407320275902748, 0.03674929589033127, -0.02690296620130539, 0.006202412769198418, -0.04120728000998497, -0.012792476452887058, 0.00020836231124121696, -0.07167663425207138, 0.007195767946541309, 0.0009757897933013737, -0.016872501000761986, 0.051596321165561676, ...
10
{"_type": "Module", "_fields": {"body": [{"_type": "ClassDef", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "index", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "base_field", "annotation": null, "type_comment": null}}], "kwarg": {"_type": "arg", "_fields": {"arg": "kwargs", "annotation": null, "type_comment": null}}, "vararg": {"_type": "arg", "_fields": {"arg": "args", "annotation": null, "type_comment": null}}, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Starred", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "value": {"_type": "Name", "_fields": {"id": "args", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "__init__", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "IndexTransform", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "super", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": null, "value": {"_type": "Name", "_fields": {"id": "kwargs", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Name", "_fields": {"id": "index", "ctx": {"_type": "Load", "_fields": {}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "index", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Name", "_fields": {"id": "base_field", "ctx": {"_type": "Load", "_fields": {}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "base_field", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "name": "__init__", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "compiler", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "connection", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "lhs", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "compile", "value": {"_type": "Name", "_fields": {"id": "compiler", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Tuple", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "lhs", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "params", "ctx": {"_type": "Store", "_fields": {}}}}]}}], "type_comment": null}}, {"_type": "Return", "_fields": {"value": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "%s[%s]"}}, "right": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "lhs", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "index", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}, {"_type": "Name", "_fields": {"id": "params", "ctx": {"_type": "Load", "_fields": {}}}}]}}}}], "name": "as_sql", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Return", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "base_field", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "name": "output_field", "returns": null, "type_params": [], "type_comment": null, "decorator_list": [{"_type": "Name", "_fields": {"id": "property", "ctx": {"_type": "Load", "_fields": {}}}}]}}], "name": "IndexTransform", "bases": [{"_type": "Name", "_fields": {"id": "Transform", "ctx": {"_type": "Load", "_fields": {}}}}], "keywords": [], "type_params": [], "decorator_list": []}}], "type_ignores": []}}
class IndexTransform(Transform): def __init__(self, index, base_field, *args, **kwargs): super(IndexTransform, self).__init__(*args, **kwargs) self.index = index self.base_field = base_field def as_sql(self, compiler, connection): lhs, params = compiler.compile(self.lhs) return '%s[%s]' % (lhs, self.index), params @property def output_field(self): return self.base_field
10,927
[ 0.001112222671508789, -0.031775884330272675, 0.02639986388385296, -0.05210604891180992, -0.0057195257395505905, -0.009958311915397644, 0.032923124730587006, 0.007490410935133696, -0.011205601505935192, -0.013093211688101292, 0.05039852857589722, -0.020917123183608055, -0.026493243873119354, ...
11
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": ""}}, "targets": [{"_type": "Name", "_fields": {"id": "default_topic_name", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": ""}}, "targets": [{"_type": "Name", "_fields": {"id": "default_share_level", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Basket migration kit (for CDSware prior to v0.7.1 -> v0.90)"}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "==============================="}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Checking your installation..."}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Tables are OK, please answer the next two questions in order to migrate your existing baskets"}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "test": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "__check_update_possibility", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "exit", "value": {"_type": "Name", "_fields": {"id": "sys", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}]}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "There are %i baskets to migrate"}}, "right": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "__count_current_baskets", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "==============================="}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "In new WebBasket module, baskets are stored in topics."}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Name of default topic [Default topic]: "}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "end", "value": {"_type": "Constant", "_fields": {"kind": null, "value": " "}}}}]}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "BoolOp", "_fields": {"op": {"_type": "Or", "_fields": {}}, "values": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "raw_input", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Constant", "_fields": {"kind": null, "value": "Default topic"}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "default_topic_name", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "==============================="}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Public baskets now have share levels. Please choose between:"}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": " 0: current public baskets should not be public anymore"}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": " 1: people can view content [default]"}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": " 2: people can view content and comments"}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": " 3: people can add comments"}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": " 4: people can add records to baskets"}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Share level for current public baskets [1]: "}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "end", "value": {"_type": "Constant", "_fields": {"kind": null, "value": " "}}}}]}}}}, {"_type": "Return", "_fields": {"value": {"_type": "BoolOp", "_fields": {"op": {"_type": "Or", "_fields": {}}, "values": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "raw_input", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Constant", "_fields": {"kind": null, "value": "1"}}]}}}}], "name": "choose_share_level", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "targets": [{"_type": "Name", "_fields": {"id": "choosed", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "While", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "choose_share_level", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "default_share_level", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Try", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "default_share_level", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "int", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "default_share_level", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, "targets": [{"_type": "Name", "_fields": {"id": "choosed", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "default_share_level", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 0}}, {"_type": "Constant", "_fields": {"kind": null, "value": 5}}], "func": {"_type": "Name", "_fields": {"id": "range", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}]}}, "orelse": [{"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "targets": [{"_type": "Name", "_fields": {"id": "choosed", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}]}}], "orelse": [], "handlers": [{"_type": "ExceptHandler", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "targets": [{"_type": "Name", "_fields": {"id": "choosed", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "name": null, "type": null}}], "finalbody": []}}], "test": {"_type": "UnaryOp", "_fields": {"op": {"_type": "Not", "_fields": {}}, "operand": {"_type": "Name", "_fields": {"id": "choosed", "ctx": {"_type": "Load", "_fields": {}}}}}}, "orelse": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}, {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "READITM"}}, "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "CFG_WEBBASKET_SHARE_LEVELS"}}, "value": {"_type": "Name", "_fields": {"id": "cfg", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "READCMT"}}, "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "CFG_WEBBASKET_SHARE_LEVELS"}}, "value": {"_type": "Name", "_fields": {"id": "cfg", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "ADDCMT"}}, "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "CFG_WEBBASKET_SHARE_LEVELS"}}, "value": {"_type": "Name", "_fields": {"id": "cfg", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "ADDITM"}}, "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "CFG_WEBBASKET_SHARE_LEVELS"}}, "value": {"_type": "Name", "_fields": {"id": "cfg", "ctx": {"_type": "Load", "_fields": {}}}}}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "share_levels", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Name", "_fields": {"id": "default_share_level", "ctx": {"_type": "Load", "_fields": {}}}}, "value": {"_type": "Name", "_fields": {"id": "share_levels", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "default_share_level", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "==============================="}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Checking database consistency..."}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "targets": [{"_type": "Name", "_fields": {"id": "problem", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "__check_every_basket_has_one_owner", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "owners_list", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": " -----------------------------"}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": " Warning! There are baskets without owners."}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": " The following basket ids exist in table 'basket' but not in 'user_basket'"}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "For", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": " "}}, "right": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "bskid", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "str", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "iter": {"_type": "Name", "_fields": {"id": "owners_list", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": [], "target": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "bskid", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "junk", "ctx": {"_type": "Store", "_fields": {}}}}]}}, "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": " -----------------------------"}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, "targets": [{"_type": "Name", "_fields": {"id": "problem", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "test": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "owners_list", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": " Baskets' ownership: OK"}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}]}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "__check_baskets_exist", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "baskets_list", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": " -----------------------------"}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": " Warning! Users own unexisting baskets"}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": " The following basket ids exist in table 'user_basket' but not in 'basket'"}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "For", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": " "}}, "right": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "bskid", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "str", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "iter": {"_type": "Name", "_fields": {"id": "baskets_list", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": [], "target": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "bskid", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "junk", "ctx": {"_type": "Store", "_fields": {}}}}]}}, "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, "targets": [{"_type": "Name", "_fields": {"id": "problem", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": " -----------------------------"}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "test": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "baskets_list", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": " Baskets' existence: OK"}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}]}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "__check_basket_is_owned_by_only_one_user", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "baskets_list", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": " -----------------------------"}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": " Warning! Some baskets are owned by more than one user"}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": " The following basket ids are mentioned several times in table 'user_basket'"}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "For", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": " "}}, "right": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "bskid", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "str", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": " (%i records)"}}, "right": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "bskid", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "__count_records", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "iter": {"_type": "Name", "_fields": {"id": "baskets_list", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": [], "target": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "bskid", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "junk", "ctx": {"_type": "Store", "_fields": {}}}}]}}, "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, "targets": [{"_type": "Name", "_fields": {"id": "problem", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": " -----------------------------"}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "test": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "baskets_list", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": " Multiple owners: OK"}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}]}}, {"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Problems have been detected. Please fix them before continuing."}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Tables you should look at: basket, user_basket, basket_record, user_query_basket"}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "exit", "value": {"_type": "Name", "_fields": {"id": "sys", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "test": {"_type": "Name", "_fields": {"id": "problem", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": []}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "==============================="}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Copying baskets..."}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "N/A"}}, "targets": [{"_type": "Name", "_fields": {"id": "nb_baskets", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Try", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "default_topic_name", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "default_share_level", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "__import_baskets", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "nb_baskets", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "orelse": [], "handlers": [{"_type": "ExceptHandler", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "There was an error while importing baskets."}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Table bskBASKET was perhaps not empty?"}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Migration cancelled"}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "exit", "value": {"_type": "Name", "_fields": {"id": "sys", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "name": null, "type": null}}], "finalbody": []}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "%s baskets haven been imported."}}, "right": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "nb_baskets", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "str", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "==============================="}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Copying records... (time for a coffee break!)"}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "N/A"}}, "targets": [{"_type": "Name", "_fields": {"id": "nb_records", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Try", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "__import_records", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "nb_records", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "orelse": [], "handlers": [{"_type": "ExceptHandler", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "There was an error while importing records."}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Table bskREC was perhaps not empty?"}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Migration cancelled"}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "exit", "value": {"_type": "Name", "_fields": {"id": "sys", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "name": null, "type": null}}], "finalbody": []}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "%s records haven been imported."}}, "right": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "nb_records", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "str", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "==============================="}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Updating auto-increment values."}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Try", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "__set_auto_increment_value", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "orelse": [], "handlers": [{"_type": "ExceptHandler", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "There was an error:"}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Could not set new auto-increment value to table 'bskBASKET'"}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "exit", "value": {"_type": "Name", "_fields": {"id": "sys", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "name": null, "type": null}}], "finalbody": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "==============================="}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Would you like to remove old tables (type y or n)? [n]"}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Return", "_fields": {"value": {"_type": "BoolOp", "_fields": {"op": {"_type": "Or", "_fields": {}}, "values": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "raw_input", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Constant", "_fields": {"kind": null, "value": "n"}}]}}}}], "name": "choose_delete", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "targets": [{"_type": "Name", "_fields": {"id": "choosed", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "While", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "choose_delete", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "delete", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Try", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "delete", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "str", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "targets": [{"_type": "Name", "_fields": {"id": "delete", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, "targets": [{"_type": "Name", "_fields": {"id": "choosed", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "delete", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "y"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "n"}}]}}]}}, "orelse": [{"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "targets": [{"_type": "Name", "_fields": {"id": "choosed", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}]}}], "orelse": [], "handlers": [{"_type": "ExceptHandler", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "targets": [{"_type": "Name", "_fields": {"id": "choosed", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "name": null, "type": null}}], "finalbody": []}}], "test": {"_type": "UnaryOp", "_fields": {"op": {"_type": "Not", "_fields": {}}, "operand": {"_type": "Name", "_fields": {"id": "choosed", "ctx": {"_type": "Load", "_fields": {}}}}}}, "orelse": []}}, {"_type": "If", "_fields": {"body": [{"_type": "Try", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "__drop_baskets", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "orelse": [], "handlers": [{"_type": "ExceptHandler", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "There was an error while deleting old tables"}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "exit", "value": {"_type": "Name", "_fields": {"id": "sys", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "name": null, "type": null}}], "finalbody": []}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Old baskets have been erased"}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "delete", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": "y"}}]}}, "orelse": []}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "==============================="}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Migration to new basket system has been successful."}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "name": "migrate_v071_baskets", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def migrate_v071_baskets(): default_topic_name = '' default_share_level = '' print("Basket migration kit (for CDSware prior to v0.7.1 -> v0.90)") print("===============================") print("Checking your installation...") if __check_update_possibility(): print("Tables are OK, please answer the next two questions in order to migrate your existing baskets") else: sys.exit(1) print("There are %i baskets to migrate" % __count_current_baskets()) print("===============================") print("In new WebBasket module, baskets are stored in topics.") print('Name of default topic [Default topic]: ', end=' ') default_topic_name = raw_input() or "Default topic" def choose_share_level(): print("===============================") print("Public baskets now have share levels. Please choose between:") print(" 0: current public baskets should not be public anymore") print(" 1: people can view content [default]") print(" 2: people can view content and comments") print(" 3: people can add comments") print(" 4: people can add records to baskets") print('Share level for current public baskets [1]: ', end=' ') return raw_input() or '1' choosed = 0 while not(choosed): default_share_level = choose_share_level() try: default_share_level = int(default_share_level) if default_share_level in range(0, 5): choosed = 1 else: choosed = 0 except: choosed = 0 share_levels = [None, cfg['CFG_WEBBASKET_SHARE_LEVELS']['READITM'], cfg['CFG_WEBBASKET_SHARE_LEVELS']['READCMT'], cfg['CFG_WEBBASKET_SHARE_LEVELS']['ADDCMT'], cfg['CFG_WEBBASKET_SHARE_LEVELS']['ADDITM']] default_share_level = share_levels[default_share_level] print("===============================") print("Checking database consistency...") problem = 0 owners_list = __check_every_basket_has_one_owner() if len(owners_list): print(" -----------------------------") print(" Warning! There are baskets without owners.") print(" The following basket ids exist in table 'basket' but not in 'user_basket'") for (bskid, junk) in owners_list: print(" " + str(bskid)) print(" -----------------------------") problem = 1 else: print(" Baskets' ownership: OK") baskets_list = __check_baskets_exist() if len(baskets_list): print(" -----------------------------") print(" Warning! Users own unexisting baskets") print(" The following basket ids exist in table 'user_basket' but not in 'basket'") for (bskid, junk) in baskets_list: print(" " + str(bskid)) problem = 1 print(" -----------------------------") else: print(" Baskets' existence: OK") baskets_list = __check_basket_is_owned_by_only_one_user() if len(baskets_list): print(" -----------------------------") print(" Warning! Some baskets are owned by more than one user") print(" The following basket ids are mentioned several times in table 'user_basket'") for (bskid, junk) in baskets_list: print(" " + str(bskid) + " (%i records)" % __count_records(bskid)) problem = 1 print(" -----------------------------") else: print(" Multiple owners: OK") if problem: print("Problems have been detected. Please fix them before continuing.") print("Tables you should look at: basket, user_basket, basket_record, user_query_basket") sys.exit(1) print("===============================") print("Copying baskets...") nb_baskets = "N/A" try: nb_baskets = __import_baskets(default_topic_name, default_share_level) except: print("There was an error while importing baskets.") print("Table bskBASKET was perhaps not empty?") print("Migration cancelled") sys.exit(1) print("%s baskets haven been imported." % str(nb_baskets)) print("===============================") print("Copying records... (time for a coffee break!)") nb_records = "N/A" try: nb_records = __import_records() except: print("There was an error while importing records.") print("Table bskREC was perhaps not empty?") print("Migration cancelled") sys.exit(1) print("%s records haven been imported." % str(nb_records)) print("===============================") print("Updating auto-increment values.") try: __set_auto_increment_value() except: print("There was an error:") print("Could not set new auto-increment value to table 'bskBASKET'") sys.exit(1) def choose_delete(): print("===============================") print("Would you like to remove old tables (type y or n)? [n]") return raw_input() or 'n' choosed = 0 while not(choosed): delete = choose_delete() try: delete = str(delete)[0] if delete in ('y','n'): choosed = 1 else: choosed = 0 except: choosed = 0 if delete == 'y': try: __drop_baskets() except: print("There was an error while deleting old tables") sys.exit(1) print("Old baskets have been erased") print("===============================") print("Migration to new basket system has been successful.")
10,928
[ 0.031064944341778755, -0.03177500143647194, 0.023507921025156975, -0.008805961348116398, 0.0406760573387146, -0.01013097632676363, 0.011830038391053677, 0.004200107418000698, 0.00648876978084445, 0.013858769088983536, 0.055029332637786865, -0.018854519352316856, -0.02677925117313862, 0.037...
7
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "==============================="}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Public baskets now have share levels. Please choose between:"}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": " 0: current public baskets should not be public anymore"}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": " 1: people can view content [default]"}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": " 2: people can view content and comments"}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": " 3: people can add comments"}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": " 4: people can add records to baskets"}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Share level for current public baskets [1]: "}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "end", "value": {"_type": "Constant", "_fields": {"kind": null, "value": " "}}}}]}}}}, {"_type": "Return", "_fields": {"value": {"_type": "BoolOp", "_fields": {"op": {"_type": "Or", "_fields": {}}, "values": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "raw_input", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Constant", "_fields": {"kind": null, "value": "1"}}]}}}}], "name": "choose_share_level", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def choose_share_level(): print("===============================") print("Public baskets now have share levels. Please choose between:") print(" 0: current public baskets should not be public anymore") print(" 1: people can view content [default]") print(" 2: people can view content and comments") print(" 3: people can add comments") print(" 4: people can add records to baskets") print('Share level for current public baskets [1]: ', end=' ') return raw_input() or '1'
10,929
[ 0.010859185829758644, -0.007930731400847435, 0.009096136316657066, -0.038273099809885025, 0.0010817350121214986, -0.009556322358548641, -0.006000342313200235, -0.010793444700539112, 0.009096136316657066, 0.0031944054644554853, 0.011158007197082043, -0.023379821330308914, 0.017391430214047432...
8
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "r", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "If", "_fields": {"body": [{"_type": "Raise", "_fields": {"exc": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "You manually constructed a FunctionGraph, but you passed it a graph that has a cached constant. This should not happen. Clone the graph before building the FunctionGraph."}}], "func": {"_type": "Name", "_fields": {"id": "CachedConstantError", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "cause": null}}], "test": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "r", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": "cached"}}, {"_type": "Constant", "_fields": {"kind": null, "value": false}}], "func": {"_type": "Name", "_fields": {"id": "getattr", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": []}}, {"_type": "If", "_fields": {"body": [{"_type": "Raise", "_fields": {"exc": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "%s is already owned by another fgraph"}}, "right": {"_type": "Name", "_fields": {"id": "r", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "Exception", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "cause": null}}], "test": {"_type": "BoolOp", "_fields": {"op": {"_type": "And", "_fields": {}}, "values": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "r", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": "fgraph"}}], "func": {"_type": "Name", "_fields": {"id": "hasattr", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Compare", "_fields": {"ops": [{"_type": "IsNot", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fgraph", "value": {"_type": "Name", "_fields": {"id": "r", "ctx": {"_type": "Load", "_fields": {}}}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}]}}, {"_type": "Compare", "_fields": {"ops": [{"_type": "IsNot", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fgraph", "value": {"_type": "Name", "_fields": {"id": "r", "ctx": {"_type": "Load", "_fields": {}}}}}}, "comparators": [{"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}]}}]}}, "orelse": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "fgraph", "value": {"_type": "Name", "_fields": {"id": "r", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "clients", "value": {"_type": "Name", "_fields": {"id": "r", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "name": "__setup_r__", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def __setup_r__(self, r): # sets up r so it belongs to this fgraph if getattr(r, 'cached', False): raise CachedConstantError( "You manually constructed a FunctionGraph, but you passed it a" " graph that has a cached constant. This should not happen." " Clone the graph before building the FunctionGraph.") if (hasattr(r, 'fgraph') and r.fgraph is not None and r.fgraph is not self): raise Exception("%s is already owned by another fgraph" % r) r.fgraph = self r.clients = []
10,930
[ 0.0014174544485285878, -0.010423184372484684, -0.009953358210623264, -0.051599692553281784, -0.005278295837342739, 0.00773183349519968, 0.01493003685027361, -0.02247045934200287, -0.018131816759705544, 0.03271383419632912, 0.049001146107912064, 0.004080528859049082, -0.008503276854753494, ...
13
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "node", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "If", "_fields": {"body": [{"_type": "Raise", "_fields": {"exc": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "%s is already owned by another fgraph"}}, "right": {"_type": "Name", "_fields": {"id": "node", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "Exception", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "cause": null}}], "test": {"_type": "BoolOp", "_fields": {"op": {"_type": "And", "_fields": {}}, "values": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "node", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": "fgraph"}}], "func": {"_type": "Name", "_fields": {"id": "hasattr", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Compare", "_fields": {"ops": [{"_type": "IsNot", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fgraph", "value": {"_type": "Name", "_fields": {"id": "node", "ctx": {"_type": "Load", "_fields": {}}}}}}, "comparators": [{"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}]}}]}}, "orelse": []}}, {"_type": "If", "_fields": {"body": [{"_type": "Raise", "_fields": {"exc": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "Op '%s' have a bad view map '%s', the values must be tuples or lists."}}, "right": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "op", "value": {"_type": "Name", "_fields": {"id": "node", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "str", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "view_map", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "op", "value": {"_type": "Name", "_fields": {"id": "node", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "func": {"_type": "Name", "_fields": {"id": "str", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}]}}}}], "func": {"_type": "Name", "_fields": {"id": "Exception", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "cause": null}}], "test": {"_type": "BoolOp", "_fields": {"op": {"_type": "And", "_fields": {}}, "values": [{"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "op", "value": {"_type": "Name", "_fields": {"id": "node", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": "view_map"}}], "func": {"_type": "Name", "_fields": {"id": "hasattr", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "UnaryOp", "_fields": {"op": {"_type": "Not", "_fields": {}}, "operand": {"_type": "Call", "_fields": {"args": [{"_type": "GeneratorExp", "_fields": {"elt": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "view", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "list", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "tuple", "ctx": {"_type": "Load", "_fields": {}}}}]}}], "func": {"_type": "Name", "_fields": {"id": "isinstance", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "generators": [{"_type": "comprehension", "_fields": {"ifs": [], "iter": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "view_map", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "op", "value": {"_type": "Name", "_fields": {"id": "node", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "func": {"_type": "Name", "_fields": {"id": "itervalues", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "target": {"_type": "Name", "_fields": {"id": "view", "ctx": {"_type": "Store", "_fields": {}}}}, "is_async": 0}}]}}], "func": {"_type": "Name", "_fields": {"id": "all", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}]}}, "orelse": []}}, {"_type": "If", "_fields": {"body": [{"_type": "Raise", "_fields": {"exc": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "Op '%s' have a bad destroy map '%s', the values must be tuples or lists."}}, "right": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "op", "value": {"_type": "Name", "_fields": {"id": "node", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "str", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "destroy_map", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "op", "value": {"_type": "Name", "_fields": {"id": "node", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "func": {"_type": "Name", "_fields": {"id": "str", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}]}}}}], "func": {"_type": "Name", "_fields": {"id": "Exception", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "cause": null}}], "test": {"_type": "BoolOp", "_fields": {"op": {"_type": "And", "_fields": {}}, "values": [{"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "op", "value": {"_type": "Name", "_fields": {"id": "node", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": "destroy_map"}}], "func": {"_type": "Name", "_fields": {"id": "hasattr", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "UnaryOp", "_fields": {"op": {"_type": "Not", "_fields": {}}, "operand": {"_type": "Call", "_fields": {"args": [{"_type": "GeneratorExp", "_fields": {"elt": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "destroy", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "list", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "tuple", "ctx": {"_type": "Load", "_fields": {}}}}]}}], "func": {"_type": "Name", "_fields": {"id": "isinstance", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "generators": [{"_type": "comprehension", "_fields": {"ifs": [], "iter": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "destroy_map", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "op", "value": {"_type": "Name", "_fields": {"id": "node", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "func": {"_type": "Name", "_fields": {"id": "itervalues", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "target": {"_type": "Name", "_fields": {"id": "destroy", "ctx": {"_type": "Store", "_fields": {}}}}, "is_async": 0}}]}}], "func": {"_type": "Name", "_fields": {"id": "all", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}]}}, "orelse": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "fgraph", "value": {"_type": "Name", "_fields": {"id": "node", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Dict", "_fields": {"keys": [], "values": []}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "deps", "value": {"_type": "Name", "_fields": {"id": "node", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "name": "__setup_node__", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def __setup_node__(self, node): # sets up node so it belongs to this fgraph if hasattr(node, 'fgraph') and node.fgraph is not self: raise Exception("%s is already owned by another fgraph" % node) if (hasattr(node.op, 'view_map') and not all(isinstance(view, (list, tuple)) for view in itervalues(node.op.view_map))): raise Exception("Op '%s' have a bad view map '%s'," " the values must be tuples or lists." % ( str(node.op), str(node.op.view_map))) if (hasattr(node.op, 'destroy_map') and not all(isinstance(destroy, (list, tuple)) for destroy in itervalues(node.op.destroy_map))): raise Exception("Op '%s' have a bad destroy map '%s'," " the values must be tuples or lists." % ( str(node.op), str(node.op.destroy_map))) node.fgraph = self node.deps = {}
10,931
[ 0.0006525154458358884, 0.019671747460961342, -0.006245187483727932, -0.03446111083030701, -0.009118922054767609, 0.00687326118350029, -0.023914208635687828, -0.010659480467438698, -0.013568766415119171, 0.08423300087451935, -0.0093500055372715, -0.018024535849690437, 0.024648936465382576, ...
11
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "op1", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "operator_list", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "tier", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "For", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "UnaryOp", "_fields": {"op": {"_type": "USub", "_fields": {}}, "operand": {"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Load", "_fields": {}}}}}}, "value": {"_type": "Name", "_fields": {"id": "operator_list", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "op2", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "For", "_fields": {"body": [{"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Call", "_fields": {"args": [{"_type": "UnaryOp", "_fields": {"op": {"_type": "USub", "_fields": {}}, "operand": {"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "pop", "value": {"_type": "Name", "_fields": {"id": "operator_list", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, {"_type": "Name", "_fields": {"id": "adder", "ctx": {"_type": "Load", "_fields": {}}}}]}}}}], "test": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "op1", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "op2", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "can_add", "value": {"_type": "Name", "_fields": {"id": "adder", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "orelse": []}}], "iter": {"_type": "Name", "_fields": {"id": "tier", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "adder", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}], "iter": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}, {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "operator_list", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}}}], "func": {"_type": "Name", "_fields": {"id": "range", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "i", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}, {"_type": "Return", "_fields": {"value": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}, {"_type": "Constant", "_fields": {"kind": null, "value": null}}]}}}}], "name": "_pop_a_match_at_tier", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def _pop_a_match_at_tier(op1, operator_list, tier): # Search from the back of list to the front in order to create nice default # order of operations. for i in range(1, len(operator_list) + 1): op2 = operator_list[-i] for adder in tier: if adder.can_add(op1, op2): return operator_list.pop(-i), adder return None, None
10,932
[ 0.02373291179537773, 0.006982867605984211, -0.029102647677063942, -0.0009640114149078727, -0.020097842440009117, 0.004027302842587233, -0.0009943956974893808, -0.04295789450407028, -0.0075960783287882805, 0.020583990961313248, -0.048791684210300446, -0.011711771599948406, 0.01961169391870498...
9
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "op1", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "op2", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "operator_name", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "hints", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "multiplier", "value": {"_type": "Name", "_fields": {"id": "op1", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "multiplier_1", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "op1", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "_type", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "Name", "_fields": {"id": "_SCALED_IDENTITY", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "batch_shape_tensor", "value": {"_type": "Name", "_fields": {"id": "op1", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "ones", "value": {"_type": "Name", "_fields": {"id": "array_ops", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "dtype", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "dtype", "value": {"_type": "Name", "_fields": {"id": "op1", "ctx": {"_type": "Load", "_fields": {}}}}}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "multiplier_1", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}]}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "multiplier", "value": {"_type": "Name", "_fields": {"id": "op2", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "multiplier_2", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "op2", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "_type", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "Name", "_fields": {"id": "_SCALED_IDENTITY", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "batch_shape_tensor", "value": {"_type": "Name", "_fields": {"id": "op2", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "ones", "value": {"_type": "Name", "_fields": {"id": "array_ops", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "dtype", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "dtype", "value": {"_type": "Name", "_fields": {"id": "op2", "ctx": {"_type": "Load", "_fields": {}}}}}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "multiplier_2", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}]}}, {"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "LinearOperatorScaledIdentity", "value": {"_type": "Name", "_fields": {"id": "linear_operator_identity", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "num_rows", "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "range_dimension_tensor", "value": {"_type": "Name", "_fields": {"id": "op1", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "keyword", "_fields": {"arg": "multiplier", "value": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "multiplier_1", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Name", "_fields": {"id": "multiplier_2", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "keyword", "_fields": {"arg": "is_non_singular", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "is_non_singular", "value": {"_type": "Name", "_fields": {"id": "hints", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "keyword", "_fields": {"arg": "is_self_adjoint", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "is_self_adjoint", "value": {"_type": "Name", "_fields": {"id": "hints", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "keyword", "_fields": {"arg": "is_positive_definite", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "is_positive_definite", "value": {"_type": "Name", "_fields": {"id": "hints", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "keyword", "_fields": {"arg": "name", "value": {"_type": "Name", "_fields": {"id": "operator_name", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}], "name": "_add", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def _add(self, op1, op2, operator_name, hints): # Will build a LinearOperatorScaledIdentity. if _type(op1) == _SCALED_IDENTITY: multiplier_1 = op1.multiplier else: multiplier_1 = array_ops.ones(op1.batch_shape_tensor(), dtype=op1.dtype) if _type(op2) == _SCALED_IDENTITY: multiplier_2 = op2.multiplier else: multiplier_2 = array_ops.ones(op2.batch_shape_tensor(), dtype=op2.dtype) return linear_operator_identity.LinearOperatorScaledIdentity( num_rows=op1.range_dimension_tensor(), multiplier=multiplier_1 + multiplier_2, is_non_singular=hints.is_non_singular, is_self_adjoint=hints.is_self_adjoint, is_positive_definite=hints.is_positive_definite, name=operator_name)
10,933
[ -0.004781000316143036, -0.015506247989833355, -0.024823354557156563, -0.013658410869538784, 0.018678739666938782, 0.0476430281996727, 0.004989716690033674, -0.004483231343328953, 0.0017671333625912666, 0.041765570640563965, -0.03299391269683838, 0.025825193151831627, 0.014671381562948227, ...
10
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "op1", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "op2", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "operator_name", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "hints", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "op1", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "op2", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "targets": [{"_type": "Tuple", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "op_add_to_tensor", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "op_other", "ctx": {"_type": "Store", "_fields": {}}}}]}}], "type_comment": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "op1", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "_type", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "Name", "_fields": {"id": "_EFFICIENT_ADD_TO_TENSOR", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": [{"_type": "Assign", "_fields": {"value": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "op2", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "op1", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "targets": [{"_type": "Tuple", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "op_add_to_tensor", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "op_other", "ctx": {"_type": "Store", "_fields": {}}}}]}}], "type_comment": null}}]}}, {"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "LinearOperatorLowerTriangular", "value": {"_type": "Name", "_fields": {"id": "linear_operator_lower_triangular", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "tril", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "to_dense", "value": {"_type": "Name", "_fields": {"id": "op_other", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "add_to_tensor", "value": {"_type": "Name", "_fields": {"id": "op_add_to_tensor", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "keyword", "_fields": {"arg": "is_non_singular", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "is_non_singular", "value": {"_type": "Name", "_fields": {"id": "hints", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "keyword", "_fields": {"arg": "is_self_adjoint", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "is_self_adjoint", "value": {"_type": "Name", "_fields": {"id": "hints", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "keyword", "_fields": {"arg": "is_positive_definite", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "is_positive_definite", "value": {"_type": "Name", "_fields": {"id": "hints", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "keyword", "_fields": {"arg": "name", "value": {"_type": "Name", "_fields": {"id": "operator_name", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}], "name": "_add", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def _add(self, op1, op2, operator_name, hints): if _type(op1) in _EFFICIENT_ADD_TO_TENSOR: op_add_to_tensor, op_other = op1, op2 else: op_add_to_tensor, op_other = op2, op1 return linear_operator_lower_triangular.LinearOperatorLowerTriangular( tril=op_add_to_tensor.add_to_tensor(op_other.to_dense()), is_non_singular=hints.is_non_singular, is_self_adjoint=hints.is_self_adjoint, is_positive_definite=hints.is_positive_definite, name=operator_name)
10,934
[ -0.007470869924873114, -0.01077309250831604, -0.051484156399965286, -0.011911978013813496, 0.002299567451700568, 0.03688026964664459, 0.00641372287645936, -0.014767364598810673, 0.0029316761065274477, 0.04267822951078415, -0.02524075098335743, 0.026548562571406364, 0.009797683916985989, -0...
10
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "op1", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "op2", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "operator_name", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "hints", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "op1", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "op2", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "targets": [{"_type": "Tuple", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "op_add_to_tensor", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "op_other", "ctx": {"_type": "Store", "_fields": {}}}}]}}], "type_comment": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "op1", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "_type", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "Name", "_fields": {"id": "_EFFICIENT_ADD_TO_TENSOR", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": [{"_type": "Assign", "_fields": {"value": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "op2", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "op1", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "targets": [{"_type": "Tuple", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "op_add_to_tensor", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "op_other", "ctx": {"_type": "Store", "_fields": {}}}}]}}], "type_comment": null}}]}}, {"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "LinearOperatorFullMatrix", "value": {"_type": "Name", "_fields": {"id": "linear_operator_full_matrix", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "matrix", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "to_dense", "value": {"_type": "Name", "_fields": {"id": "op_other", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "add_to_tensor", "value": {"_type": "Name", "_fields": {"id": "op_add_to_tensor", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "keyword", "_fields": {"arg": "is_non_singular", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "is_non_singular", "value": {"_type": "Name", "_fields": {"id": "hints", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "keyword", "_fields": {"arg": "is_self_adjoint", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "is_self_adjoint", "value": {"_type": "Name", "_fields": {"id": "hints", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "keyword", "_fields": {"arg": "is_positive_definite", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "is_positive_definite", "value": {"_type": "Name", "_fields": {"id": "hints", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "keyword", "_fields": {"arg": "name", "value": {"_type": "Name", "_fields": {"id": "operator_name", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}], "name": "_add", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def _add(self, op1, op2, operator_name, hints): if _type(op1) in _EFFICIENT_ADD_TO_TENSOR: op_add_to_tensor, op_other = op1, op2 else: op_add_to_tensor, op_other = op2, op1 return linear_operator_full_matrix.LinearOperatorFullMatrix( matrix=op_add_to_tensor.add_to_tensor(op_other.to_dense()), is_non_singular=hints.is_non_singular, is_self_adjoint=hints.is_self_adjoint, is_positive_definite=hints.is_positive_definite, name=operator_name)
10,935
[ 0.02956845425069332, -0.020068082958459854, 0.01590440422296524, -0.05516345053911209, -0.03202016279101372, -0.0030857715755701065, 0.03191448748111725, -0.00341601250693202, -0.00813713762909174, 0.006499141920357943, -0.007027527783066034, -0.007598184049129486, -0.00715962378308177, -0...
11
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "meta", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "size", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": null}}], "test": {"_type": "BoolOp", "_fields": {"op": {"_type": "Or", "_fields": {}}, "values": [{"_type": "UnaryOp", "_fields": {"op": {"_type": "Not", "_fields": {}}, "operand": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "duration"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "has", "value": {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "UnaryOp", "_fields": {"op": {"_type": "Not", "_fields": {}}, "operand": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "sample_rate"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "has", "value": {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "UnaryOp", "_fields": {"op": {"_type": "Not", "_fields": {}}, "operand": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "bits_per_sample"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "has", "value": {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "UnaryOp", "_fields": {"op": {"_type": "Not", "_fields": {}}, "operand": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "nb_channel"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "has", "value": {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "UnaryOp", "_fields": {"op": {"_type": "Not", "_fields": {}}, "operand": {"_type": "Name", "_fields": {"id": "size", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "orelse": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Mult", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Mult", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Mult", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "duration"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "timedelta2seconds", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "right": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "sample_rate"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, "right": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "bits_per_sample"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, "right": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "nb_channel"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, "targets": [{"_type": "Name", "_fields": {"id": "orig_size", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "orig_size", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "float", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "right": {"_type": "Name", "_fields": {"id": "size", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "compr_rate", "value": {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "name": "computeComprRate", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def computeComprRate(meta, size): if not meta.has("duration") \ or not meta.has("sample_rate") \ or not meta.has("bits_per_sample") \ or not meta.has("nb_channel") \ or not size: return orig_size = timedelta2seconds(meta.get("duration")) * meta.get('sample_rate') * meta.get('bits_per_sample') * meta.get('nb_channel') meta.compr_rate = float(orig_size) / size
10,936
[ 0.03171386197209358, 0.026621971279382706, -0.020088544115424156, -0.023239005357027054, -0.0018382529960945249, 0.03548046201467514, 0.016542823985219002, 0.006992627400904894, 0.019867664203047752, -0.029946811497211456, -0.0017437973292544484, 0.0008275771397165954, 0.00558596383780241, ...
12
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "metadata", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "comment", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "comment", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": "vendor"}}], "func": {"_type": "Name", "_fields": {"id": "getValue", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "producer", "value": {"_type": "Name", "_fields": {"id": "metadata", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "For", "_fields": {"body": [{"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "="}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "split", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Name", "_fields": {"id": "item", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, "targets": [{"_type": "Tuple", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "key", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Store", "_fields": {}}}}]}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "upper", "value": {"_type": "Name", "_fields": {"id": "key", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "key", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Name", "_fields": {"id": "key", "ctx": {"_type": "Load", "_fields": {}}}}, "value": {"_type": "Name", "_fields": {"id": "VORBIS_KEY_TO_ATTR", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "key", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "metadata", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "key", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "setattr", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "key", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Name", "_fields": {"id": "VORBIS_KEY_TO_ATTR", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": [{"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "Skip Vorbis comment %s: %s"}}, "right": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "key", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}]}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "warning", "value": {"_type": "Name", "_fields": {"id": "metadata", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "test": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": []}}]}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "="}}, "comparators": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Name", "_fields": {"id": "item", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "orelse": []}}], "iter": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "metadata"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "array", "value": {"_type": "Name", "_fields": {"id": "comment", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "item", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}], "name": "readVorbisComment", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def readVorbisComment(metadata, comment): metadata.producer = getValue(comment, "vendor") for item in comment.array("metadata"): if "=" in item.value: key, value = item.value.split("=", 1) key = key.upper() if key in VORBIS_KEY_TO_ATTR: key = VORBIS_KEY_TO_ATTR[key] setattr(metadata, key, value) elif value: metadata.warning("Skip Vorbis comment %s: %s" % (key, value))
10,937
[ 0.019478866830468178, 0.0285587590187788, -0.006031917408108711, -0.03567923977971077, -0.03352772817015648, 0.0027406164444983006, 0.017519453540444374, -0.01629001833498478, -0.030710270628333092, -0.01113535463809967, 0.10066001862287521, -0.026893898844718933, -0.036447636783123016, 0....
14
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "ogg", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}, "targets": [{"_type": "Name", "_fields": {"id": "granule_quotient", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "For", "_fields": {"body": [{"_type": "If", "_fields": {"body": [{"_type": "Continue", "_fields": {}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "NotIn", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "segments"}}, "comparators": [{"_type": "Name", "_fields": {"id": "page", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "segments"}}, "value": {"_type": "Name", "_fields": {"id": "page", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "page", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "Metadata", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "vorbis_hdr"}}, "value": {"_type": "Name", "_fields": {"id": "page", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "vorbisHeader", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "audio[]"}}, {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": "Audio"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "addGroup", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "sample_rate"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "granule_quotient", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "test": {"_type": "BoolOp", "_fields": {"op": {"_type": "And", "_fields": {}}, "values": [{"_type": "UnaryOp", "_fields": {"op": {"_type": "Not", "_fields": {}}, "operand": {"_type": "Name", "_fields": {"id": "granule_quotient", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "sample_rate"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "has", "value": {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}]}}, "orelse": []}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "vorbis_hdr"}}, "comparators": [{"_type": "Name", "_fields": {"id": "page", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": []}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "Metadata", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "theora_hdr"}}, "value": {"_type": "Name", "_fields": {"id": "page", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "theoraHeader", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "video[]"}}, {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": "Video"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "addGroup", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "theora_hdr"}}, "comparators": [{"_type": "Name", "_fields": {"id": "page", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": []}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "Metadata", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "video_hdr"}}, "value": {"_type": "Name", "_fields": {"id": "page", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "videoHeader", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "video[]"}}, {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": "Video"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "addGroup", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "frame_rate"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "granule_quotient", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "test": {"_type": "BoolOp", "_fields": {"op": {"_type": "And", "_fields": {}}, "values": [{"_type": "UnaryOp", "_fields": {"op": {"_type": "Not", "_fields": {}}, "operand": {"_type": "Name", "_fields": {"id": "granule_quotient", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "frame_rate"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "has", "value": {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}]}}, "orelse": []}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "video_hdr"}}, "comparators": [{"_type": "Name", "_fields": {"id": "page", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": []}}, {"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "comment"}}, "value": {"_type": "Name", "_fields": {"id": "page", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "readVorbisComment", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "comment"}}, "comparators": [{"_type": "Name", "_fields": {"id": "page", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": []}}, {"_type": "If", "_fields": {"body": [{"_type": "Break", "_fields": {}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "LtE", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": 3}}, "comparators": [{"_type": "Name", "_fields": {"id": "index", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": []}}], "iter": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "page"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "array", "value": {"_type": "Name", "_fields": {"id": "ogg", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "enumerate", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [], "target": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "index", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "page", "ctx": {"_type": "Store", "_fields": {}}}}]}}, "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "createLastPage", "value": {"_type": "Name", "_fields": {"id": "ogg", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "page", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Try", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "timedelta", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "seconds", "value": {"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "abs_granule_pos"}}, "value": {"_type": "Name", "_fields": {"id": "page", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "func": {"_type": "Name", "_fields": {"id": "float", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "right": {"_type": "Name", "_fields": {"id": "granule_quotient", "ctx": {"_type": "Load", "_fields": {}}}}}}}}]}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "duration", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "orelse": [], "handlers": [{"_type": "ExceptHandler", "_fields": {"body": [{"_type": "Pass", "_fields": {}}], "name": null, "type": {"_type": "Name", "_fields": {"id": "OverflowError", "ctx": {"_type": "Load", "_fields": {}}}}}}], "finalbody": []}}], "test": {"_type": "BoolOp", "_fields": {"op": {"_type": "And", "_fields": {}}, "values": [{"_type": "Name", "_fields": {"id": "page", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "abs_granule_pos"}}, "comparators": [{"_type": "Name", "_fields": {"id": "page", "ctx": {"_type": "Load", "_fields": {}}}}]}}]}}, "orelse": []}}], "test": {"_type": "BoolOp", "_fields": {"op": {"_type": "And", "_fields": {}}, "values": [{"_type": "Name", "_fields": {"id": "granule_quotient", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Compare", "_fields": {"ops": [{"_type": "LtE", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "QUALITY_NORMAL", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "quality", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}]}}, "orelse": []}}], "name": "extract", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def extract(self, ogg): granule_quotient = None for index, page in enumerate(ogg.array("page")): if "segments" not in page: continue page = page["segments"] if "vorbis_hdr" in page: meta = Metadata(self) self.vorbisHeader(page["vorbis_hdr"], meta) self.addGroup("audio[]", meta, "Audio") if not granule_quotient and meta.has("sample_rate"): granule_quotient = meta.get('sample_rate') if "theora_hdr" in page: meta = Metadata(self) self.theoraHeader(page["theora_hdr"], meta) self.addGroup("video[]", meta, "Video") if "video_hdr" in page: meta = Metadata(self) self.videoHeader(page["video_hdr"], meta) self.addGroup("video[]", meta, "Video") if not granule_quotient and meta.has("frame_rate"): granule_quotient = meta.get('frame_rate') if "comment" in page: readVorbisComment(self, page["comment"]) if 3 <= index: # Only process pages 0..3 break # Compute duration if granule_quotient and QUALITY_NORMAL <= self.quality: page = ogg.createLastPage() if page and "abs_granule_pos" in page: try: self.duration = timedelta(seconds=float(page["abs_granule_pos"].value) / granule_quotient) except OverflowError: pass
10,938
[ 0.017222989350557327, 0.05923860892653465, 0.01628119871020317, -0.06451263278722763, -0.011566361412405968, 0.008511429652571678, 0.03599993512034416, -0.035717397928237915, -0.038966573774814606, -0.020589889958500862, 0.08589127659797668, -0.019695188850164413, -0.05151592940092087, 0.0...
15
{"_type": "Module", "_fields": {"body": [{"_type": "ClassDef", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "ogg", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}, "targets": [{"_type": "Name", "_fields": {"id": "granule_quotient", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "For", "_fields": {"body": [{"_type": "If", "_fields": {"body": [{"_type": "Continue", "_fields": {}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "NotIn", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "segments"}}, "comparators": [{"_type": "Name", "_fields": {"id": "page", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "segments"}}, "value": {"_type": "Name", "_fields": {"id": "page", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "page", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "Metadata", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "vorbis_hdr"}}, "value": {"_type": "Name", "_fields": {"id": "page", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "vorbisHeader", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "audio[]"}}, {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": "Audio"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "addGroup", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "sample_rate"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "granule_quotient", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "test": {"_type": "BoolOp", "_fields": {"op": {"_type": "And", "_fields": {}}, "values": [{"_type": "UnaryOp", "_fields": {"op": {"_type": "Not", "_fields": {}}, "operand": {"_type": "Name", "_fields": {"id": "granule_quotient", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "sample_rate"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "has", "value": {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}]}}, "orelse": []}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "vorbis_hdr"}}, "comparators": [{"_type": "Name", "_fields": {"id": "page", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": []}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "Metadata", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "theora_hdr"}}, "value": {"_type": "Name", "_fields": {"id": "page", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "theoraHeader", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "video[]"}}, {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": "Video"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "addGroup", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "theora_hdr"}}, "comparators": [{"_type": "Name", "_fields": {"id": "page", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": []}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "Metadata", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "video_hdr"}}, "value": {"_type": "Name", "_fields": {"id": "page", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "videoHeader", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "video[]"}}, {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": "Video"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "addGroup", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "frame_rate"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "granule_quotient", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "test": {"_type": "BoolOp", "_fields": {"op": {"_type": "And", "_fields": {}}, "values": [{"_type": "UnaryOp", "_fields": {"op": {"_type": "Not", "_fields": {}}, "operand": {"_type": "Name", "_fields": {"id": "granule_quotient", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "frame_rate"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "has", "value": {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}]}}, "orelse": []}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "video_hdr"}}, "comparators": [{"_type": "Name", "_fields": {"id": "page", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": []}}, {"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "comment"}}, "value": {"_type": "Name", "_fields": {"id": "page", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "readVorbisComment", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "comment"}}, "comparators": [{"_type": "Name", "_fields": {"id": "page", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": []}}, {"_type": "If", "_fields": {"body": [{"_type": "Break", "_fields": {}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "LtE", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": 3}}, "comparators": [{"_type": "Name", "_fields": {"id": "index", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": []}}], "iter": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "page"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "array", "value": {"_type": "Name", "_fields": {"id": "ogg", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "enumerate", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [], "target": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "index", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "page", "ctx": {"_type": "Store", "_fields": {}}}}]}}, "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "createLastPage", "value": {"_type": "Name", "_fields": {"id": "ogg", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "page", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Try", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "timedelta", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "seconds", "value": {"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "abs_granule_pos"}}, "value": {"_type": "Name", "_fields": {"id": "page", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "func": {"_type": "Name", "_fields": {"id": "float", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "right": {"_type": "Name", "_fields": {"id": "granule_quotient", "ctx": {"_type": "Load", "_fields": {}}}}}}}}]}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "duration", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "orelse": [], "handlers": [{"_type": "ExceptHandler", "_fields": {"body": [{"_type": "Pass", "_fields": {}}], "name": null, "type": {"_type": "Name", "_fields": {"id": "OverflowError", "ctx": {"_type": "Load", "_fields": {}}}}}}], "finalbody": []}}], "test": {"_type": "BoolOp", "_fields": {"op": {"_type": "And", "_fields": {}}, "values": [{"_type": "Name", "_fields": {"id": "page", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "abs_granule_pos"}}, "comparators": [{"_type": "Name", "_fields": {"id": "page", "ctx": {"_type": "Load", "_fields": {}}}}]}}]}}, "orelse": []}}], "test": {"_type": "BoolOp", "_fields": {"op": {"_type": "And", "_fields": {}}, "values": [{"_type": "Name", "_fields": {"id": "granule_quotient", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Compare", "_fields": {"ops": [{"_type": "LtE", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "QUALITY_NORMAL", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "quality", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}]}}, "orelse": []}}], "name": "extract", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "header", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "meta", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "display", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "fourcc"}}, "value": {"_type": "Name", "_fields": {"id": "header", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "compression", "value": {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "width"}}, "value": {"_type": "Name", "_fields": {"id": "header", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "width", "value": {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "height"}}, "value": {"_type": "Name", "_fields": {"id": "header", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "height", "value": {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "bits_per_sample"}}, "value": {"_type": "Name", "_fields": {"id": "header", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "bits_per_pixel", "value": {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": 10000000.0}}, "right": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "time_unit"}}, "value": {"_type": "Name", "_fields": {"id": "header", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "frame_rate", "value": {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "test": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "time_unit"}}, "value": {"_type": "Name", "_fields": {"id": "header", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "orelse": []}}], "name": "videoHeader", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "header", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "meta", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "Theora"}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "compression", "value": {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "Theora version %u.%u (revision %u)"}}, "right": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "version_major"}}, "value": {"_type": "Name", "_fields": {"id": "header", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "version_minor"}}, "value": {"_type": "Name", "_fields": {"id": "header", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "version_revision"}}, "value": {"_type": "Name", "_fields": {"id": "header", "ctx": {"_type": "Load", "_fields": {}}}}}}}}]}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "format_version", "value": {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "frame_width"}}, "value": {"_type": "Name", "_fields": {"id": "header", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "width", "value": {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "frame_height"}}, "value": {"_type": "Name", "_fields": {"id": "header", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "height", "value": {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "fps_num"}}, "value": {"_type": "Name", "_fields": {"id": "header", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "func": {"_type": "Name", "_fields": {"id": "float", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "right": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "fps_den"}}, "value": {"_type": "Name", "_fields": {"id": "header", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "frame_rate", "value": {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "test": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "fps_den"}}, "value": {"_type": "Name", "_fields": {"id": "header", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "orelse": []}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "aspect_ratio_num"}}, "value": {"_type": "Name", "_fields": {"id": "header", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "func": {"_type": "Name", "_fields": {"id": "float", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "right": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "aspect_ratio_den"}}, "value": {"_type": "Name", "_fields": {"id": "header", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "aspect_ratio", "value": {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "test": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "aspect_ratio_den"}}, "value": {"_type": "Name", "_fields": {"id": "header", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "orelse": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "display", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "pixel_format"}}, "value": {"_type": "Name", "_fields": {"id": "header", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "pixel_format", "value": {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "Quality: %s"}}, "right": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "quality"}}, "value": {"_type": "Name", "_fields": {"id": "header", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "comment", "value": {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "name": "theoraHeader", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "header", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "meta", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": "u", "value": "Vorbis"}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "compression", "value": {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "audio_sample_rate"}}, "value": {"_type": "Name", "_fields": {"id": "header", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "sample_rate", "value": {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "audio_channels"}}, "value": {"_type": "Name", "_fields": {"id": "header", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "nb_channel", "value": {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": "u", "value": "Vorbis version %s"}}, "right": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "vorbis_version"}}, "value": {"_type": "Name", "_fields": {"id": "header", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "format_version", "value": {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "bitrate_nominal"}}, "value": {"_type": "Name", "_fields": {"id": "header", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "bit_rate", "value": {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "name": "vorbisHeader", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "name": "OggMetadata", "bases": [{"_type": "Name", "_fields": {"id": "MultipleMetadata", "ctx": {"_type": "Load", "_fields": {}}}}], "keywords": [], "type_params": [], "decorator_list": []}}], "type_ignores": []}}
class OggMetadata(MultipleMetadata): def extract(self, ogg): granule_quotient = None for index, page in enumerate(ogg.array("page")): if "segments" not in page: continue page = page["segments"] if "vorbis_hdr" in page: meta = Metadata(self) self.vorbisHeader(page["vorbis_hdr"], meta) self.addGroup("audio[]", meta, "Audio") if not granule_quotient and meta.has("sample_rate"): granule_quotient = meta.get('sample_rate') if "theora_hdr" in page: meta = Metadata(self) self.theoraHeader(page["theora_hdr"], meta) self.addGroup("video[]", meta, "Video") if "video_hdr" in page: meta = Metadata(self) self.videoHeader(page["video_hdr"], meta) self.addGroup("video[]", meta, "Video") if not granule_quotient and meta.has("frame_rate"): granule_quotient = meta.get('frame_rate') if "comment" in page: readVorbisComment(self, page["comment"]) if 3 <= index: # Only process pages 0..3 break # Compute duration if granule_quotient and QUALITY_NORMAL <= self.quality: page = ogg.createLastPage() if page and "abs_granule_pos" in page: try: self.duration = timedelta(seconds=float(page["abs_granule_pos"].value) / granule_quotient) except OverflowError: pass def videoHeader(self, header, meta): meta.compression = header["fourcc"].display meta.width = header["width"].value meta.height = header["height"].value meta.bits_per_pixel = header["bits_per_sample"].value if header["time_unit"].value: meta.frame_rate = 10000000.0 / header["time_unit"].value def theoraHeader(self, header, meta): meta.compression = "Theora" meta.format_version = "Theora version %u.%u (revision %u)" % (\ header["version_major"].value, header["version_minor"].value, header["version_revision"].value) meta.width = header["frame_width"].value meta.height = header["frame_height"].value if header["fps_den"].value: meta.frame_rate = float(header["fps_num"].value) / header["fps_den"].value if header["aspect_ratio_den"].value: meta.aspect_ratio = float(header["aspect_ratio_num"].value) / header["aspect_ratio_den"].value meta.pixel_format = header["pixel_format"].display meta.comment = "Quality: %s" % header["quality"].value def vorbisHeader(self, header, meta): meta.compression = u"Vorbis" meta.sample_rate = header["audio_sample_rate"].value meta.nb_channel = header["audio_channels"].value meta.format_version = u"Vorbis version %s" % header["vorbis_version"].value meta.bit_rate = header["bitrate_nominal"].value
10,939
[ -0.007276621181517839, 0.03389446809887886, -0.011313002556562424, -0.06097441166639328, 0.0011190519435331225, 0.013951960951089859, -0.020488115027546883, -0.018840158358216286, -0.023026859387755394, -0.030019542202353477, 0.03456255793571472, -0.038482025265693665, -0.02828250639140606, ...
14
{"_type": "Module", "_fields": {"body": [{"_type": "ClassDef", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "audio", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "sample_rate"}}, "value": {"_type": "Name", "_fields": {"id": "audio", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "sample_rate", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "channels"}}, "value": {"_type": "Name", "_fields": {"id": "audio", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "nb_channel", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "display", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "codec"}}, "value": {"_type": "Name", "_fields": {"id": "audio", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "compression", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "info"}}, "value": {"_type": "Name", "_fields": {"id": "audio", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "comment", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "info"}}, "comparators": [{"_type": "Name", "_fields": {"id": "audio", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "getBitsPerSample", "value": {"_type": "Name", "_fields": {"id": "audio", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "bits_per_sample", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "computeBitRate", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "If", "_fields": {"body": [{"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "timedelta", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "seconds", "value": {"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "size", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "audio_data"}}, "value": {"_type": "Name", "_fields": {"id": "audio", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "func": {"_type": "Name", "_fields": {"id": "float", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "right": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "bit_rate"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}}}]}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "duration", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "test": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "bit_rate"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "has", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "orelse": []}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "size", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "audio_data"}}, "value": {"_type": "Name", "_fields": {"id": "audio", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "func": {"_type": "Name", "_fields": {"id": "computeComprRate", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "audio_data"}}, "comparators": [{"_type": "Name", "_fields": {"id": "audio", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": []}}], "name": "extract", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "name": "AuMetadata", "bases": [{"_type": "Name", "_fields": {"id": "RootMetadata", "ctx": {"_type": "Load", "_fields": {}}}}], "keywords": [], "type_params": [], "decorator_list": []}}], "type_ignores": []}}
class AuMetadata(RootMetadata): def extract(self, audio): self.sample_rate = audio["sample_rate"].value self.nb_channel = audio["channels"].value self.compression = audio["codec"].display if "info" in audio: self.comment = audio["info"].value self.bits_per_sample = audio.getBitsPerSample() computeBitRate(self) if "audio_data" in audio: if self.has("bit_rate"): self.duration = timedelta(seconds=float(audio["audio_data"].size) / self.get('bit_rate')) computeComprRate(self, audio["audio_data"].size)
10,940
[ 0.013966202735900879, 0.009045644663274288, -0.0005103090079501271, -0.06654685735702515, -0.007306972052901983, -0.024205055087804794, 0.04084176942706108, 0.010363854467868805, 0.0024020392447710037, -0.022068645805120468, 0.013261642307043076, 0.013307098299264908, -0.06000126153230667, ...
10
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "header", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "meta", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "Theora"}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "compression", "value": {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "Theora version %u.%u (revision %u)"}}, "right": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "version_major"}}, "value": {"_type": "Name", "_fields": {"id": "header", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "version_minor"}}, "value": {"_type": "Name", "_fields": {"id": "header", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "version_revision"}}, "value": {"_type": "Name", "_fields": {"id": "header", "ctx": {"_type": "Load", "_fields": {}}}}}}}}]}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "format_version", "value": {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "frame_width"}}, "value": {"_type": "Name", "_fields": {"id": "header", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "width", "value": {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "frame_height"}}, "value": {"_type": "Name", "_fields": {"id": "header", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "height", "value": {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "fps_num"}}, "value": {"_type": "Name", "_fields": {"id": "header", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "func": {"_type": "Name", "_fields": {"id": "float", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "right": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "fps_den"}}, "value": {"_type": "Name", "_fields": {"id": "header", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "frame_rate", "value": {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "test": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "fps_den"}}, "value": {"_type": "Name", "_fields": {"id": "header", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "orelse": []}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "aspect_ratio_num"}}, "value": {"_type": "Name", "_fields": {"id": "header", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "func": {"_type": "Name", "_fields": {"id": "float", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "right": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "aspect_ratio_den"}}, "value": {"_type": "Name", "_fields": {"id": "header", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "aspect_ratio", "value": {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "test": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "aspect_ratio_den"}}, "value": {"_type": "Name", "_fields": {"id": "header", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "orelse": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "display", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "pixel_format"}}, "value": {"_type": "Name", "_fields": {"id": "header", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "pixel_format", "value": {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "Quality: %s"}}, "right": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "quality"}}, "value": {"_type": "Name", "_fields": {"id": "header", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "comment", "value": {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "name": "theoraHeader", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def theoraHeader(self, header, meta): meta.compression = "Theora" meta.format_version = "Theora version %u.%u (revision %u)" % (\ header["version_major"].value, header["version_minor"].value, header["version_revision"].value) meta.width = header["frame_width"].value meta.height = header["frame_height"].value if header["fps_den"].value: meta.frame_rate = float(header["fps_num"].value) / header["fps_den"].value if header["aspect_ratio_den"].value: meta.aspect_ratio = float(header["aspect_ratio_num"].value) / header["aspect_ratio_den"].value meta.pixel_format = header["pixel_format"].display meta.comment = "Quality: %s" % header["quality"].value
10,941
[ -0.01785123161971569, -0.022754712030291557, -0.007697075139731169, -0.059525471180677414, -0.006666169036179781, 0.010309060104191303, -0.01687908172607422, -0.007819929160177708, 0.010971403680741787, -0.0037684154231101274, 0.04315917193889618, 0.0006720251985825598, -0.04670591652393341,...
13
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "audio", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "sample_rate"}}, "value": {"_type": "Name", "_fields": {"id": "audio", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "sample_rate", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "channels"}}, "value": {"_type": "Name", "_fields": {"id": "audio", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "nb_channel", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "display", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "codec"}}, "value": {"_type": "Name", "_fields": {"id": "audio", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "compression", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "info"}}, "value": {"_type": "Name", "_fields": {"id": "audio", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "comment", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "info"}}, "comparators": [{"_type": "Name", "_fields": {"id": "audio", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "getBitsPerSample", "value": {"_type": "Name", "_fields": {"id": "audio", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "bits_per_sample", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "computeBitRate", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "If", "_fields": {"body": [{"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "timedelta", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "seconds", "value": {"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "size", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "audio_data"}}, "value": {"_type": "Name", "_fields": {"id": "audio", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "func": {"_type": "Name", "_fields": {"id": "float", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "right": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "bit_rate"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}}}]}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "duration", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "test": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "bit_rate"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "has", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "orelse": []}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "size", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "audio_data"}}, "value": {"_type": "Name", "_fields": {"id": "audio", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "func": {"_type": "Name", "_fields": {"id": "computeComprRate", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "audio_data"}}, "comparators": [{"_type": "Name", "_fields": {"id": "audio", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": []}}], "name": "extract", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def extract(self, audio): self.sample_rate = audio["sample_rate"].value self.nb_channel = audio["channels"].value self.compression = audio["codec"].display if "info" in audio: self.comment = audio["info"].value self.bits_per_sample = audio.getBitsPerSample() computeBitRate(self) if "audio_data" in audio: if self.has("bit_rate"): self.duration = timedelta(seconds=float(audio["audio_data"].size) / self.get('bit_rate')) computeComprRate(self, audio["audio_data"].size)
10,942
[ -0.016844239085912704, 0.017910923808813095, 0.029421741142868996, -0.04344102367758751, 0.012636110186576843, 0.006552491337060928, -0.03619694709777832, -0.006757623050361872, -0.03643138334155083, -0.017864037305116653, 0.013773125596344471, 0.0015238352352753282, -0.010367940180003643, ...
12
{"_type": "Module", "_fields": {"body": [{"_type": "ClassDef", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": "u", "value": "28_8"}}, {"_type": "Constant", "_fields": {"kind": "u", "value": "14_4"}}, {"_type": "Constant", "_fields": {"kind": "u", "value": "lpcJ"}}], "values": [{"_type": "Constant", "_fields": {"kind": null, "value": 15200}}, {"_type": "Constant", "_fields": {"kind": null, "value": 8000}}, {"_type": "Constant", "_fields": {"kind": null, "value": 8000}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "FOURCC_TO_BITRATE", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "real", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "version"}}, "value": {"_type": "Name", "_fields": {"id": "real", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "version", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "metadata"}}, "value": {"_type": "Name", "_fields": {"id": "real", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "useMetadata", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "metadata"}}, "comparators": [{"_type": "Name", "_fields": {"id": "real", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": []}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "real", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "useRoot", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "Real audio version %s"}}, "right": {"_type": "Name", "_fields": {"id": "version", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "format_version", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "real", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": "data_size"}}], "func": {"_type": "Name", "_fields": {"id": "getValue", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "size", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "version", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 3}}]}}, "orelse": [{"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Sub", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "filesize"}}, "value": {"_type": "Name", "_fields": {"id": "real", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 40}}}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "headersize"}}, "value": {"_type": "Name", "_fields": {"id": "real", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 16}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "size", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "test": {"_type": "BoolOp", "_fields": {"op": {"_type": "And", "_fields": {}}, "values": [{"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "filesize"}}, "comparators": [{"_type": "Name", "_fields": {"id": "real", "ctx": {"_type": "Load", "_fields": {}}}}]}}, {"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "headersize"}}, "comparators": [{"_type": "Name", "_fields": {"id": "real", "ctx": {"_type": "Load", "_fields": {}}}}]}}]}}, "orelse": [{"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}, "targets": [{"_type": "Name", "_fields": {"id": "size", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}]}}]}}, {"_type": "If", "_fields": {"body": [{"_type": "AugAssign", "_fields": {"op": {"_type": "Mult", "_fields": {}}, "value": {"_type": "Constant", "_fields": {"kind": null, "value": 8}}, "target": {"_type": "Name", "_fields": {"id": "size", "ctx": {"_type": "Store", "_fields": {}}}}}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "size", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "float", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "right": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "bit_rate"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, "targets": [{"_type": "Name", "_fields": {"id": "sec", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "timedelta", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "seconds", "value": {"_type": "Name", "_fields": {"id": "sec", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "duration", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "test": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "bit_rate"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "has", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "orelse": []}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "size", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "computeComprRate", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "test": {"_type": "Name", "_fields": {"id": "size", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": []}}], "name": "extract", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "info", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "title"}}, "value": {"_type": "Name", "_fields": {"id": "info", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "title", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "author"}}, "value": {"_type": "Name", "_fields": {"id": "info", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "author", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "copyright"}}, "value": {"_type": "Name", "_fields": {"id": "info", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "copyright", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "comment"}}, "value": {"_type": "Name", "_fields": {"id": "info", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "comment", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "name": "useMetadata", "returns": null, "type_params": [], "type_comment": null, "decorator_list": [{"_type": "Name", "_fields": {"id": "fault_tolerant", "ctx": {"_type": "Load", "_fields": {}}}}]}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "real", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": 16}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "bits_per_sample", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "sample_rate"}}, "value": {"_type": "Name", "_fields": {"id": "real", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "sample_rate", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "channels"}}, "value": {"_type": "Name", "_fields": {"id": "real", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "nb_channel", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "NotEq", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "version"}}, "value": {"_type": "Name", "_fields": {"id": "real", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 3}}]}}, "orelse": [{"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": 8000}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "sample_rate", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "nb_channel", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}]}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "real", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": "FourCC"}}], "func": {"_type": "Name", "_fields": {"id": "getValue", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "fourcc", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Name", "_fields": {"id": "fourcc", "ctx": {"_type": "Load", "_fields": {}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "compression", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Try", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Name", "_fields": {"id": "fourcc", "ctx": {"_type": "Load", "_fields": {}}}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "FOURCC_TO_BITRATE", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "bit_rate", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "orelse": [], "handlers": [{"_type": "ExceptHandler", "_fields": {"body": [{"_type": "Pass", "_fields": {}}], "name": null, "type": {"_type": "Name", "_fields": {"id": "LookupError", "ctx": {"_type": "Load", "_fields": {}}}}}}], "finalbody": []}}], "test": {"_type": "Name", "_fields": {"id": "fourcc", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": []}}], "name": "useRoot", "returns": null, "type_params": [], "type_comment": null, "decorator_list": [{"_type": "Name", "_fields": {"id": "fault_tolerant", "ctx": {"_type": "Load", "_fields": {}}}}]}}], "name": "RealAudioMetadata", "bases": [{"_type": "Name", "_fields": {"id": "RootMetadata", "ctx": {"_type": "Load", "_fields": {}}}}], "keywords": [], "type_params": [], "decorator_list": []}}], "type_ignores": []}}
class RealAudioMetadata(RootMetadata): FOURCC_TO_BITRATE = { u"28_8": 15200, # 28.8 kbit/sec (audio bit rate: 15.2 kbit/s) u"14_4": 8000, # 14.4 kbit/sec u"lpcJ": 8000, # 14.4 kbit/sec } def extract(self, real): version = real["version"].value if "metadata" in real: self.useMetadata(real["metadata"]) self.useRoot(real) self.format_version = "Real audio version %s" % version if version == 3: size = getValue(real, "data_size") elif "filesize" in real and "headersize" in real: size = (real["filesize"].value + 40) - (real["headersize"].value + 16) else: size = None if size: size *= 8 if self.has("bit_rate"): sec = float(size) / self.get('bit_rate') self.duration = timedelta(seconds=sec) computeComprRate(self, size) @fault_tolerant def useMetadata(self, info): self.title = info["title"].value self.author = info["author"].value self.copyright = info["copyright"].value self.comment = info["comment"].value @fault_tolerant def useRoot(self, real): self.bits_per_sample = 16 # FIXME: Is that correct? if real["version"].value != 3: self.sample_rate = real["sample_rate"].value self.nb_channel = real["channels"].value else: self.sample_rate = 8000 self.nb_channel = 1 fourcc = getValue(real, "FourCC") if fourcc: self.compression = fourcc try: self.bit_rate = self.FOURCC_TO_BITRATE[fourcc] except LookupError: pass
10,943
[ 0.026354840025305748, 0.0060020009987056255, -0.006689109373837709, -0.06018943339586258, 0.0073354304768145084, 0.015436406247317791, -0.030446115881204605, -0.012964071705937386, -0.007806052919477224, 0.01356646791100502, 0.04455222934484482, 0.0032253304962068796, -0.039783257991075516, ...
11
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "real", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "version"}}, "value": {"_type": "Name", "_fields": {"id": "real", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "version", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "metadata"}}, "value": {"_type": "Name", "_fields": {"id": "real", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "useMetadata", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "metadata"}}, "comparators": [{"_type": "Name", "_fields": {"id": "real", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": []}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "real", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "useRoot", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "Real audio version %s"}}, "right": {"_type": "Name", "_fields": {"id": "version", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "format_version", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "real", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": "data_size"}}], "func": {"_type": "Name", "_fields": {"id": "getValue", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "size", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "version", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 3}}]}}, "orelse": [{"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Sub", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "filesize"}}, "value": {"_type": "Name", "_fields": {"id": "real", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 40}}}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "headersize"}}, "value": {"_type": "Name", "_fields": {"id": "real", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 16}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "size", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "test": {"_type": "BoolOp", "_fields": {"op": {"_type": "And", "_fields": {}}, "values": [{"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "filesize"}}, "comparators": [{"_type": "Name", "_fields": {"id": "real", "ctx": {"_type": "Load", "_fields": {}}}}]}}, {"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "headersize"}}, "comparators": [{"_type": "Name", "_fields": {"id": "real", "ctx": {"_type": "Load", "_fields": {}}}}]}}]}}, "orelse": [{"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}, "targets": [{"_type": "Name", "_fields": {"id": "size", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}]}}]}}, {"_type": "If", "_fields": {"body": [{"_type": "AugAssign", "_fields": {"op": {"_type": "Mult", "_fields": {}}, "value": {"_type": "Constant", "_fields": {"kind": null, "value": 8}}, "target": {"_type": "Name", "_fields": {"id": "size", "ctx": {"_type": "Store", "_fields": {}}}}}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "size", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "float", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "right": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "bit_rate"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, "targets": [{"_type": "Name", "_fields": {"id": "sec", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "timedelta", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "seconds", "value": {"_type": "Name", "_fields": {"id": "sec", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "duration", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "test": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "bit_rate"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "has", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "orelse": []}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "size", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "computeComprRate", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "test": {"_type": "Name", "_fields": {"id": "size", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": []}}], "name": "extract", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def extract(self, real): version = real["version"].value if "metadata" in real: self.useMetadata(real["metadata"]) self.useRoot(real) self.format_version = "Real audio version %s" % version if version == 3: size = getValue(real, "data_size") elif "filesize" in real and "headersize" in real: size = (real["filesize"].value + 40) - (real["headersize"].value + 16) else: size = None if size: size *= 8 if self.has("bit_rate"): sec = float(size) / self.get('bit_rate') self.duration = timedelta(seconds=sec) computeComprRate(self, size)
10,944
[ 0.0027614987920969725, -0.024568451568484306, -0.0003177945618517697, 0.0060685547068715096, 0.0044104293920099735, -0.017090030014514923, -0.03802960738539696, 0.01830374076962471, -0.026603562757372856, 0.01690613478422165, 0.0009018546552397311, 0.017126809805631638, -0.000525251787621527...
9
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "real", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": 16}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "bits_per_sample", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "sample_rate"}}, "value": {"_type": "Name", "_fields": {"id": "real", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "sample_rate", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "channels"}}, "value": {"_type": "Name", "_fields": {"id": "real", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "nb_channel", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "NotEq", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "version"}}, "value": {"_type": "Name", "_fields": {"id": "real", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 3}}]}}, "orelse": [{"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": 8000}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "sample_rate", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "nb_channel", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}]}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "real", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": "FourCC"}}], "func": {"_type": "Name", "_fields": {"id": "getValue", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "fourcc", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Name", "_fields": {"id": "fourcc", "ctx": {"_type": "Load", "_fields": {}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "compression", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Try", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Name", "_fields": {"id": "fourcc", "ctx": {"_type": "Load", "_fields": {}}}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "FOURCC_TO_BITRATE", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "bit_rate", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "orelse": [], "handlers": [{"_type": "ExceptHandler", "_fields": {"body": [{"_type": "Pass", "_fields": {}}], "name": null, "type": {"_type": "Name", "_fields": {"id": "LookupError", "ctx": {"_type": "Load", "_fields": {}}}}}}], "finalbody": []}}], "test": {"_type": "Name", "_fields": {"id": "fourcc", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": []}}], "name": "useRoot", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def useRoot(self, real): self.bits_per_sample = 16 # FIXME: Is that correct? if real["version"].value != 3: self.sample_rate = real["sample_rate"].value self.nb_channel = real["channels"].value else: self.sample_rate = 8000 self.nb_channel = 1 fourcc = getValue(real, "FourCC") if fourcc: self.compression = fourcc try: self.bit_rate = self.FOURCC_TO_BITRATE[fourcc] except LookupError: pass
10,945
[ 0.05261903256177902, 0.04319300130009651, -0.0018310705199837685, -0.049237702041864395, 0.03344273194670677, 0.005963644944131374, -0.0023883527610450983, -0.04108545929193497, -0.018284650519490242, -0.021828098222613335, 0.01572549343109131, -0.012529443949460983, 0.016177110373973846, ...
13
{"_type": "Module", "_fields": {"body": [{"_type": "ClassDef", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "generated by"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "creation date"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "modification date"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "description"}}], "values": [{"_type": "Constant", "_fields": {"kind": null, "value": "producer"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "creation_date"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "last_modification"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "comment"}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "KEY_TO_ATTR", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "media", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "file_prop"}}, "value": {"_type": "Name", "_fields": {"id": "media", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "useFileProp", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "file_prop"}}, "comparators": [{"_type": "Name", "_fields": {"id": "media", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": []}}, {"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "content_desc"}}, "value": {"_type": "Name", "_fields": {"id": "media", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "useContentDesc", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "content_desc"}}, "comparators": [{"_type": "Name", "_fields": {"id": "media", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": []}}, {"_type": "For", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "stream", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "index", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "useStreamProp", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "iter": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "stream_prop"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "array", "value": {"_type": "Name", "_fields": {"id": "media", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "enumerate", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [], "target": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "index", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "stream", "ctx": {"_type": "Store", "_fields": {}}}}]}}, "type_comment": null}}], "name": "extract", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "prop", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "lower", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "name"}}, "value": {"_type": "Name", "_fields": {"id": "prop", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "key", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "value"}}, "value": {"_type": "Name", "_fields": {"id": "prop", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Name", "_fields": {"id": "key", "ctx": {"_type": "Load", "_fields": {}}}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "KEY_TO_ATTR", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "setattr", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "key", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "KEY_TO_ATTR", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "orelse": [{"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "Skip %s: %s"}}, "right": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "name"}}, "value": {"_type": "Name", "_fields": {"id": "prop", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}]}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "warning", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "test": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": []}}]}}], "name": "useFileInfoProp", "returns": null, "type_params": [], "type_comment": null, "decorator_list": [{"_type": "Name", "_fields": {"id": "fault_tolerant", "ctx": {"_type": "Load", "_fields": {}}}}]}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "prop", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "avg_bit_rate"}}, "value": {"_type": "Name", "_fields": {"id": "prop", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "bit_rate", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "timedelta", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "milliseconds", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "duration"}}, "value": {"_type": "Name", "_fields": {"id": "prop", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}]}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "duration", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "name": "useFileProp", "returns": null, "type_params": [], "type_comment": null, "decorator_list": [{"_type": "Name", "_fields": {"id": "fault_tolerant", "ctx": {"_type": "Load", "_fields": {}}}}]}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "content", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "title"}}, "value": {"_type": "Name", "_fields": {"id": "content", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "title", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "author"}}, "value": {"_type": "Name", "_fields": {"id": "content", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "author", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "copyright"}}, "value": {"_type": "Name", "_fields": {"id": "content", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "copyright", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "comment"}}, "value": {"_type": "Name", "_fields": {"id": "content", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "comment", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "name": "useContentDesc", "returns": null, "type_params": [], "type_comment": null, "decorator_list": [{"_type": "Name", "_fields": {"id": "fault_tolerant", "ctx": {"_type": "Load", "_fields": {}}}}]}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "stream", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "index", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "Metadata", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "Start: %s"}}, "right": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "stream_start"}}, "value": {"_type": "Name", "_fields": {"id": "stream", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "comment", "value": {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "For", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "prop", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "useFileInfoProp", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "iter": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "file_info/prop"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "array", "value": {"_type": "Name", "_fields": {"id": "stream", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "prop", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "stream", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": "mime_type"}}], "func": {"_type": "Name", "_fields": {"id": "getValue", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": "logical-fileinfo"}}]}}, "orelse": [{"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "avg_bit_rate"}}, "value": {"_type": "Name", "_fields": {"id": "stream", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "bit_rate", "value": {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "timedelta", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "milliseconds", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "duration"}}, "value": {"_type": "Name", "_fields": {"id": "stream", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}]}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "duration", "value": {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "stream", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": "mime_type"}}], "func": {"_type": "Name", "_fields": {"id": "getValue", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "mime_type", "value": {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}]}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "stream", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": "desc"}}], "func": {"_type": "Name", "_fields": {"id": "getValue", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "title", "value": {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "stream[%u]"}}, "right": {"_type": "Name", "_fields": {"id": "index", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "Stream #%u"}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, "right": {"_type": "Name", "_fields": {"id": "index", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "addGroup", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "name": "useStreamProp", "returns": null, "type_params": [], "type_comment": null, "decorator_list": [{"_type": "Name", "_fields": {"id": "fault_tolerant", "ctx": {"_type": "Load", "_fields": {}}}}]}}], "name": "RealMediaMetadata", "bases": [{"_type": "Name", "_fields": {"id": "MultipleMetadata", "ctx": {"_type": "Load", "_fields": {}}}}], "keywords": [], "type_params": [], "decorator_list": []}}], "type_ignores": []}}
class RealMediaMetadata(MultipleMetadata): KEY_TO_ATTR = { "generated by": "producer", "creation date": "creation_date", "modification date": "last_modification", "description": "comment", } def extract(self, media): if "file_prop" in media: self.useFileProp(media["file_prop"]) if "content_desc" in media: self.useContentDesc(media["content_desc"]) for index, stream in enumerate(media.array("stream_prop")): self.useStreamProp(stream, index) @fault_tolerant def useFileInfoProp(self, prop): key = prop["name"].value.lower() value = prop["value"].value if key in self.KEY_TO_ATTR: setattr(self, self.KEY_TO_ATTR[key], value) elif value: self.warning("Skip %s: %s" % (prop["name"].value, value)) @fault_tolerant def useFileProp(self, prop): self.bit_rate = prop["avg_bit_rate"].value self.duration = timedelta(milliseconds=prop["duration"].value) @fault_tolerant def useContentDesc(self, content): self.title = content["title"].value self.author = content["author"].value self.copyright = content["copyright"].value self.comment = content["comment"].value @fault_tolerant def useStreamProp(self, stream, index): meta = Metadata(self) meta.comment = "Start: %s" % stream["stream_start"].value if getValue(stream, "mime_type") == "logical-fileinfo": for prop in stream.array("file_info/prop"): self.useFileInfoProp(prop) else: meta.bit_rate = stream["avg_bit_rate"].value meta.duration = timedelta(milliseconds=stream["duration"].value) meta.mime_type = getValue(stream, "mime_type") meta.title = getValue(stream, "desc") self.addGroup("stream[%u]" % index, meta, "Stream #%u" % (1+index))
10,946
[ 0.06343255937099457, 0.017514102160930634, -0.017111610621213913, -0.045009974390268326, -0.010562509298324585, 0.03173927962779999, 0.00798081886023283, -0.03100329451262951, -0.0028260606341063976, -0.010976499877870083, 0.026334401220083237, 0.0005749869160354137, 0.028358355164527893, ...
10
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "stream", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "index", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "Metadata", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "Start: %s"}}, "right": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "stream_start"}}, "value": {"_type": "Name", "_fields": {"id": "stream", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "comment", "value": {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "For", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "prop", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "useFileInfoProp", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "iter": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "file_info/prop"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "array", "value": {"_type": "Name", "_fields": {"id": "stream", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "prop", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "stream", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": "mime_type"}}], "func": {"_type": "Name", "_fields": {"id": "getValue", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": "logical-fileinfo"}}]}}, "orelse": [{"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "avg_bit_rate"}}, "value": {"_type": "Name", "_fields": {"id": "stream", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "bit_rate", "value": {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "timedelta", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "milliseconds", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "duration"}}, "value": {"_type": "Name", "_fields": {"id": "stream", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}]}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "duration", "value": {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "stream", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": "mime_type"}}], "func": {"_type": "Name", "_fields": {"id": "getValue", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "mime_type", "value": {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}]}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "stream", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": "desc"}}], "func": {"_type": "Name", "_fields": {"id": "getValue", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "title", "value": {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "stream[%u]"}}, "right": {"_type": "Name", "_fields": {"id": "index", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Name", "_fields": {"id": "meta", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "Stream #%u"}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, "right": {"_type": "Name", "_fields": {"id": "index", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "addGroup", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "name": "useStreamProp", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def useStreamProp(self, stream, index): meta = Metadata(self) meta.comment = "Start: %s" % stream["stream_start"].value if getValue(stream, "mime_type") == "logical-fileinfo": for prop in stream.array("file_info/prop"): self.useFileInfoProp(prop) else: meta.bit_rate = stream["avg_bit_rate"].value meta.duration = timedelta(milliseconds=stream["duration"].value) meta.mime_type = getValue(stream, "mime_type") meta.title = getValue(stream, "desc") self.addGroup("stream[%u]" % index, meta, "Stream #%u" % (1+index))
10,947
[ 0.020205970853567123, 0.026827482506632805, 0.0005197824793867767, -0.07301952689886093, 0.005566702224314213, -0.016096489503979683, 0.04528966546058655, 0.024766642600297928, -0.0333392433822155, 0.005609382409602404, 0.06623949110507965, 0.006008746102452278, -0.02504711225628853, 0.006...
12
{"_type": "Module", "_fields": {"body": [{"_type": "ClassDef", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "TP1"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "COM"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "TEN"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "TRK"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "TAL"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "TT2"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "TYE"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "TCO"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "TPE1"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "COMM"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "TENC"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "TRCK"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "TALB"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "TIT2"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "TYER"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "WXXX"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "TCON"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "TLAN"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "TCOP"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "TDAT"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "TRDA"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "TORY"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "TIT1"}}], "values": [{"_type": "Constant", "_fields": {"kind": null, "value": "author"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "comment"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "producer"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "track_number"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "album"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "title"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "creation_date"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "music_genre"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "author"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "comment"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "producer"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "track_number"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "album"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "title"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "creation_date"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "url"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "music_genre"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "language"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "copyright"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "creation_date"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "creation_date"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "creation_date"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "title"}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "TAG_TO_KEY", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "field", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "NotIn", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "content"}}, "comparators": [{"_type": "Name", "_fields": {"id": "field", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "content"}}, "value": {"_type": "Name", "_fields": {"id": "field", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "content", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "NotIn", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "text"}}, "comparators": [{"_type": "Name", "_fields": {"id": "content", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": []}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "%s: %s"}}, "right": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "title"}}, "value": {"_type": "Name", "_fields": {"id": "content", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "text"}}, "value": {"_type": "Name", "_fields": {"id": "content", "ctx": {"_type": "Load", "_fields": {}}}}}}}}]}}}}, "targets": [{"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "test": {"_type": "BoolOp", "_fields": {"op": {"_type": "And", "_fields": {}}, "values": [{"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "title"}}, "comparators": [{"_type": "Name", "_fields": {"id": "content", "ctx": {"_type": "Load", "_fields": {}}}}]}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "title"}}, "value": {"_type": "Name", "_fields": {"id": "content", "ctx": {"_type": "Load", "_fields": {}}}}}}}}]}}, "orelse": [{"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "text"}}, "value": {"_type": "Name", "_fields": {"id": "content", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}]}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "tag"}}, "value": {"_type": "Name", "_fields": {"id": "field", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "tag", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "If", "_fields": {"body": [{"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "tag", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": "ISO-8859-1"}}], "func": {"_type": "Name", "_fields": {"id": "makePrintable", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "to_unicode", "value": {"_type": "Constant", "_fields": {"kind": null, "value": true}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "tag", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "test": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "tag", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "str", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "isinstance", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": []}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "Skip ID3v2 tag %s: %s"}}, "right": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "tag", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}]}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "warning", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "test": {"_type": "Name", "_fields": {"id": "tag", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": []}}, {"_type": "Return", "_fields": {"value": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "NotIn", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "tag", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "TAG_TO_KEY", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "orelse": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Name", "_fields": {"id": "tag", "ctx": {"_type": "Load", "_fields": {}}}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "TAG_TO_KEY", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "key", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "key", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "setattr", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "name": "processID3v2", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "id3", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "For", "_fields": {"body": [{"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "field", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "processID3v2", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "test": {"_type": "BoolOp", "_fields": {"op": {"_type": "And", "_fields": {}}, "values": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "is_field_set", "value": {"_type": "Name", "_fields": {"id": "field", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "tag"}}, "comparators": [{"_type": "Name", "_fields": {"id": "field", "ctx": {"_type": "Load", "_fields": {}}}}]}}]}}, "orelse": []}}], "iter": {"_type": "Name", "_fields": {"id": "id3", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "field", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}], "name": "readID3v2", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "mp3", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "/frames/frame[0]"}}, "value": {"_type": "Name", "_fields": {"id": "mp3", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "frame", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "getNbChannel", "value": {"_type": "Name", "_fields": {"id": "frame", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "display", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "channel_mode"}}, "value": {"_type": "Name", "_fields": {"id": "frame", "ctx": {"_type": "Load", "_fields": {}}}}}}}}]}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "nb_channel", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": "u", "value": "MPEG version %s layer %s"}}, "right": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "display", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "version"}}, "value": {"_type": "Name", "_fields": {"id": "frame", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "display", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "layer"}}, "value": {"_type": "Name", "_fields": {"id": "frame", "ctx": {"_type": "Load", "_fields": {}}}}}}}}]}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "format_version", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "getSampleRate", "value": {"_type": "Name", "_fields": {"id": "frame", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "sample_rate", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": 16}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "bits_per_sample", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "frame", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "computeBitrate", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "test": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "looksConstantBitRate", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "frames"}}, "value": {"_type": "Name", "_fields": {"id": "mp3", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, "orelse": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "mp3", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "computeVariableBitrate", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}]}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "/frames/frame[0]"}}, "comparators": [{"_type": "Name", "_fields": {"id": "mp3", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": []}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "id3v1"}}, "value": {"_type": "Name", "_fields": {"id": "mp3", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "id3", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "comment"}}, "value": {"_type": "Name", "_fields": {"id": "id3", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "comment", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "author"}}, "value": {"_type": "Name", "_fields": {"id": "id3", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "author", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "song"}}, "value": {"_type": "Name", "_fields": {"id": "id3", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "title", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "album"}}, "value": {"_type": "Name", "_fields": {"id": "id3", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "album", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "year"}}, "value": {"_type": "Name", "_fields": {"id": "id3", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "creation_date", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "NotEq", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "year"}}, "value": {"_type": "Name", "_fields": {"id": "id3", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": "0"}}]}}, "orelse": []}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "track_nb"}}, "value": {"_type": "Name", "_fields": {"id": "id3", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "track_number", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "track_nb"}}, "comparators": [{"_type": "Name", "_fields": {"id": "id3", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": []}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "id3v1"}}, "comparators": [{"_type": "Name", "_fields": {"id": "mp3", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": []}}, {"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "id3v2"}}, "value": {"_type": "Name", "_fields": {"id": "mp3", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "readID3v2", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "id3v2"}}, "comparators": [{"_type": "Name", "_fields": {"id": "mp3", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": []}}, {"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "size", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "frames"}}, "value": {"_type": "Name", "_fields": {"id": "mp3", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "func": {"_type": "Name", "_fields": {"id": "computeComprRate", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "frames"}}, "comparators": [{"_type": "Name", "_fields": {"id": "mp3", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": []}}], "name": "extract", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "frame", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "getBitRate", "value": {"_type": "Name", "_fields": {"id": "frame", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "bit_rate", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": null}}], "test": {"_type": "UnaryOp", "_fields": {"op": {"_type": "Not", "_fields": {}}, "operand": {"_type": "Name", "_fields": {"id": "bit_rate", "ctx": {"_type": "Load", "_fields": {}}}}}}, "orelse": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "bit_rate", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "%s (constant)"}}], "func": {"_type": "Name", "_fields": {"id": "_", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "right": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "bit_rate", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "humanBitRate", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}]}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "bit_rate", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "timedelta", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "seconds", "value": {"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "size", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "/frames"}}, "value": {"_type": "Name", "_fields": {"id": "frame", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "func": {"_type": "Name", "_fields": {"id": "float", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "right": {"_type": "Name", "_fields": {"id": "bit_rate", "ctx": {"_type": "Load", "_fields": {}}}}}}}}]}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "duration", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "name": "computeBitrate", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "mp3", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "LtE", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "quality", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "comparators": [{"_type": "Name", "_fields": {"id": "QUALITY_FAST", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "targets": [{"_type": "Name", "_fields": {"id": "count", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Process all MPEG audio frames to compute exact duration"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "warning", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}, "targets": [{"_type": "Name", "_fields": {"id": "max_count", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "LtE", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "QUALITY_BEST", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "quality", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "orelse": [{"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Mult", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": 500}}, "right": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "quality", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "max_count", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}]}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": 0.0}}, "targets": [{"_type": "Name", "_fields": {"id": "total_bit_rate", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "For", "_fields": {"body": [{"_type": "If", "_fields": {"body": [{"_type": "Continue", "_fields": {}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Lt", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "index", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 3}}]}}, "orelse": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "getBitRate", "value": {"_type": "Name", "_fields": {"id": "frame", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "bit_rate", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "AugAssign", "_fields": {"op": {"_type": "Add", "_fields": {}}, "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "bit_rate", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "float", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "target": {"_type": "Name", "_fields": {"id": "total_bit_rate", "ctx": {"_type": "Store", "_fields": {}}}}}}, {"_type": "AugAssign", "_fields": {"op": {"_type": "Add", "_fields": {}}, "value": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, "target": {"_type": "Name", "_fields": {"id": "count", "ctx": {"_type": "Store", "_fields": {}}}}}}, {"_type": "If", "_fields": {"body": [{"_type": "Break", "_fields": {}}], "test": {"_type": "BoolOp", "_fields": {"op": {"_type": "And", "_fields": {}}, "values": [{"_type": "Name", "_fields": {"id": "max_count", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Compare", "_fields": {"ops": [{"_type": "LtE", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "max_count", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Name", "_fields": {"id": "count", "ctx": {"_type": "Load", "_fields": {}}}}]}}]}}, "orelse": []}}], "test": {"_type": "Name", "_fields": {"id": "bit_rate", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": []}}], "iter": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "frames/frame"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "array", "value": {"_type": "Name", "_fields": {"id": "mp3", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "enumerate", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [], "target": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "index", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "frame", "ctx": {"_type": "Store", "_fields": {}}}}]}}, "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": null}}], "test": {"_type": "UnaryOp", "_fields": {"op": {"_type": "Not", "_fields": {}}, "operand": {"_type": "Name", "_fields": {"id": "count", "ctx": {"_type": "Load", "_fields": {}}}}}}, "orelse": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "total_bit_rate", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Name", "_fields": {"id": "count", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "bit_rate", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "bit_rate", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "%s (Variable bit rate)"}}], "func": {"_type": "Name", "_fields": {"id": "_", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "right": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "bit_rate", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "humanBitRate", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}]}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "bit_rate", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "timedelta", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "seconds", "value": {"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "size", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "frames"}}, "value": {"_type": "Name", "_fields": {"id": "mp3", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "func": {"_type": "Name", "_fields": {"id": "float", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "right": {"_type": "Name", "_fields": {"id": "bit_rate", "ctx": {"_type": "Load", "_fields": {}}}}}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "duration", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Name", "_fields": {"id": "duration", "ctx": {"_type": "Load", "_fields": {}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "duration", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "name": "computeVariableBitrate", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "name": "MpegAudioMetadata", "bases": [{"_type": "Name", "_fields": {"id": "RootMetadata", "ctx": {"_type": "Load", "_fields": {}}}}], "keywords": [], "type_params": [], "decorator_list": []}}], "type_ignores": []}}
class MpegAudioMetadata(RootMetadata): TAG_TO_KEY = { # ID3 version 2.2 "TP1": "author", "COM": "comment", "TEN": "producer", "TRK": "track_number", "TAL": "album", "TT2": "title", "TYE": "creation_date", "TCO": "music_genre", # ID3 version 2.3+ "TPE1": "author", "COMM": "comment", "TENC": "producer", "TRCK": "track_number", "TALB": "album", "TIT2": "title", "TYER": "creation_date", "WXXX": "url", "TCON": "music_genre", "TLAN": "language", "TCOP": "copyright", "TDAT": "creation_date", "TRDA": "creation_date", "TORY": "creation_date", "TIT1": "title", } def processID3v2(self, field): # Read value if "content" not in field: return content = field["content"] if "text" not in content: return if "title" in content and content["title"].value: value = "%s: %s" % (content["title"].value, content["text"].value) else: value = content["text"].value # Known tag? tag = field["tag"].value if tag not in self.TAG_TO_KEY: if tag: if isinstance(tag, str): tag = makePrintable(tag, "ISO-8859-1", to_unicode=True) self.warning("Skip ID3v2 tag %s: %s" % (tag, value)) return key = self.TAG_TO_KEY[tag] setattr(self, key, value) def readID3v2(self, id3): for field in id3: if field.is_field_set and "tag" in field: self.processID3v2(field) def extract(self, mp3): if "/frames/frame[0]" in mp3: frame = mp3["/frames/frame[0]"] self.nb_channel = (frame.getNbChannel(), frame["channel_mode"].display) self.format_version = u"MPEG version %s layer %s" % \ (frame["version"].display, frame["layer"].display) self.sample_rate = frame.getSampleRate() self.bits_per_sample = 16 if mp3["frames"].looksConstantBitRate(): self.computeBitrate(frame) else: self.computeVariableBitrate(mp3) if "id3v1" in mp3: id3 = mp3["id3v1"] self.comment = id3["comment"].value self.author = id3["author"].value self.title = id3["song"].value self.album = id3["album"].value if id3["year"].value != "0": self.creation_date = id3["year"].value if "track_nb" in id3: self.track_number = id3["track_nb"].value if "id3v2" in mp3: self.readID3v2(mp3["id3v2"]) if "frames" in mp3: computeComprRate(self, mp3["frames"].size) def computeBitrate(self, frame): bit_rate = frame.getBitRate() # may returns None on error if not bit_rate: return self.bit_rate = (bit_rate, _("%s (constant)") % humanBitRate(bit_rate)) self.duration = timedelta(seconds=float(frame["/frames"].size) / bit_rate) def computeVariableBitrate(self, mp3): if self.quality <= QUALITY_FAST: return count = 0 if QUALITY_BEST <= self.quality: self.warning("Process all MPEG audio frames to compute exact duration") max_count = None else: max_count = 500 * self.quality total_bit_rate = 0.0 for index, frame in enumerate(mp3.array("frames/frame")): if index < 3: continue bit_rate = frame.getBitRate() if bit_rate: total_bit_rate += float(bit_rate) count += 1 if max_count and max_count <= count: break if not count: return bit_rate = total_bit_rate / count self.bit_rate = (bit_rate, _("%s (Variable bit rate)") % humanBitRate(bit_rate)) duration = timedelta(seconds=float(mp3["frames"].size) / bit_rate) self.duration = duration
10,948
[ 0.026294786483049393, -0.0227288119494915, -0.04053589701652527, -0.06471160799264908, 0.0296670813113451, -0.04217647388577461, 0.03458881005644798, 0.02211359702050686, -0.0034264111891388893, 0.009233935736119747, 0.06452932208776474, 0.005457193590700626, -0.02807207591831684, 0.026021...
10
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "field", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "NotIn", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "content"}}, "comparators": [{"_type": "Name", "_fields": {"id": "field", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "content"}}, "value": {"_type": "Name", "_fields": {"id": "field", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "content", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "NotIn", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "text"}}, "comparators": [{"_type": "Name", "_fields": {"id": "content", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": []}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "%s: %s"}}, "right": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "title"}}, "value": {"_type": "Name", "_fields": {"id": "content", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "text"}}, "value": {"_type": "Name", "_fields": {"id": "content", "ctx": {"_type": "Load", "_fields": {}}}}}}}}]}}}}, "targets": [{"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "test": {"_type": "BoolOp", "_fields": {"op": {"_type": "And", "_fields": {}}, "values": [{"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "title"}}, "comparators": [{"_type": "Name", "_fields": {"id": "content", "ctx": {"_type": "Load", "_fields": {}}}}]}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "title"}}, "value": {"_type": "Name", "_fields": {"id": "content", "ctx": {"_type": "Load", "_fields": {}}}}}}}}]}}, "orelse": [{"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "text"}}, "value": {"_type": "Name", "_fields": {"id": "content", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}]}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "tag"}}, "value": {"_type": "Name", "_fields": {"id": "field", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "tag", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "If", "_fields": {"body": [{"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "tag", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": "ISO-8859-1"}}], "func": {"_type": "Name", "_fields": {"id": "makePrintable", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "to_unicode", "value": {"_type": "Constant", "_fields": {"kind": null, "value": true}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "tag", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "test": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "tag", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "str", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "isinstance", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": []}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "Skip ID3v2 tag %s: %s"}}, "right": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "tag", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}]}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "warning", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "test": {"_type": "Name", "_fields": {"id": "tag", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": []}}, {"_type": "Return", "_fields": {"value": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "NotIn", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "tag", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "TAG_TO_KEY", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "orelse": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Name", "_fields": {"id": "tag", "ctx": {"_type": "Load", "_fields": {}}}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "TAG_TO_KEY", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "key", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "key", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "setattr", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "name": "processID3v2", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def processID3v2(self, field): # Read value if "content" not in field: return content = field["content"] if "text" not in content: return if "title" in content and content["title"].value: value = "%s: %s" % (content["title"].value, content["text"].value) else: value = content["text"].value # Known tag? tag = field["tag"].value if tag not in self.TAG_TO_KEY: if tag: if isinstance(tag, str): tag = makePrintable(tag, "ISO-8859-1", to_unicode=True) self.warning("Skip ID3v2 tag %s: %s" % (tag, value)) return key = self.TAG_TO_KEY[tag] setattr(self, key, value)
10,949
[ 0.009003710933029652, -0.003626160090789199, -0.03883150964975357, -0.0854630321264267, 0.005154864862561226, 0.00724028330296278, 0.007294449955224991, -0.0003690106968861073, 0.008660654537379742, 0.010773156769573689, 0.06504819542169571, 0.012590750120580196, -0.013276861980557442, 0.0...
10
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "mp3", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "/frames/frame[0]"}}, "value": {"_type": "Name", "_fields": {"id": "mp3", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "frame", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "getNbChannel", "value": {"_type": "Name", "_fields": {"id": "frame", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "display", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "channel_mode"}}, "value": {"_type": "Name", "_fields": {"id": "frame", "ctx": {"_type": "Load", "_fields": {}}}}}}}}]}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "nb_channel", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": "u", "value": "MPEG version %s layer %s"}}, "right": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "display", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "version"}}, "value": {"_type": "Name", "_fields": {"id": "frame", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "display", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "layer"}}, "value": {"_type": "Name", "_fields": {"id": "frame", "ctx": {"_type": "Load", "_fields": {}}}}}}}}]}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "format_version", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "getSampleRate", "value": {"_type": "Name", "_fields": {"id": "frame", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "sample_rate", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": 16}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "bits_per_sample", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "frame", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "computeBitrate", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "test": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "looksConstantBitRate", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "frames"}}, "value": {"_type": "Name", "_fields": {"id": "mp3", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, "orelse": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "mp3", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "computeVariableBitrate", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}]}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "/frames/frame[0]"}}, "comparators": [{"_type": "Name", "_fields": {"id": "mp3", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": []}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "id3v1"}}, "value": {"_type": "Name", "_fields": {"id": "mp3", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "id3", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "comment"}}, "value": {"_type": "Name", "_fields": {"id": "id3", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "comment", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "author"}}, "value": {"_type": "Name", "_fields": {"id": "id3", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "author", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "song"}}, "value": {"_type": "Name", "_fields": {"id": "id3", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "title", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "album"}}, "value": {"_type": "Name", "_fields": {"id": "id3", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "album", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "year"}}, "value": {"_type": "Name", "_fields": {"id": "id3", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "creation_date", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "NotEq", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "year"}}, "value": {"_type": "Name", "_fields": {"id": "id3", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": "0"}}]}}, "orelse": []}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "track_nb"}}, "value": {"_type": "Name", "_fields": {"id": "id3", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "track_number", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "track_nb"}}, "comparators": [{"_type": "Name", "_fields": {"id": "id3", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": []}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "id3v1"}}, "comparators": [{"_type": "Name", "_fields": {"id": "mp3", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": []}}, {"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "id3v2"}}, "value": {"_type": "Name", "_fields": {"id": "mp3", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "readID3v2", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "id3v2"}}, "comparators": [{"_type": "Name", "_fields": {"id": "mp3", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": []}}, {"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "size", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "frames"}}, "value": {"_type": "Name", "_fields": {"id": "mp3", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "func": {"_type": "Name", "_fields": {"id": "computeComprRate", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "frames"}}, "comparators": [{"_type": "Name", "_fields": {"id": "mp3", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": []}}], "name": "extract", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def extract(self, mp3): if "/frames/frame[0]" in mp3: frame = mp3["/frames/frame[0]"] self.nb_channel = (frame.getNbChannel(), frame["channel_mode"].display) self.format_version = u"MPEG version %s layer %s" % \ (frame["version"].display, frame["layer"].display) self.sample_rate = frame.getSampleRate() self.bits_per_sample = 16 if mp3["frames"].looksConstantBitRate(): self.computeBitrate(frame) else: self.computeVariableBitrate(mp3) if "id3v1" in mp3: id3 = mp3["id3v1"] self.comment = id3["comment"].value self.author = id3["author"].value self.title = id3["song"].value self.album = id3["album"].value if id3["year"].value != "0": self.creation_date = id3["year"].value if "track_nb" in id3: self.track_number = id3["track_nb"].value if "id3v2" in mp3: self.readID3v2(mp3["id3v2"]) if "frames" in mp3: computeComprRate(self, mp3["frames"].size)
10,950
[ 0.020361704751849174, 0.005504795350134373, -0.02458771876990795, -0.06287430971860886, -0.06787966936826706, -0.027968531474471092, 0.0251365527510643, 0.03606930747628212, 0.01617959700524807, -0.006185348145663738, 0.07262158393859863, 0.023029033094644547, -0.03222747519612312, -0.0276...
11
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "mp3", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "LtE", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "quality", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "comparators": [{"_type": "Name", "_fields": {"id": "QUALITY_FAST", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "targets": [{"_type": "Name", "_fields": {"id": "count", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Process all MPEG audio frames to compute exact duration"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "warning", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}, "targets": [{"_type": "Name", "_fields": {"id": "max_count", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "LtE", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "QUALITY_BEST", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "quality", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "orelse": [{"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Mult", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": 500}}, "right": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "quality", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "max_count", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}]}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": 0.0}}, "targets": [{"_type": "Name", "_fields": {"id": "total_bit_rate", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "For", "_fields": {"body": [{"_type": "If", "_fields": {"body": [{"_type": "Continue", "_fields": {}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Lt", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "index", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 3}}]}}, "orelse": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "getBitRate", "value": {"_type": "Name", "_fields": {"id": "frame", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "bit_rate", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "AugAssign", "_fields": {"op": {"_type": "Add", "_fields": {}}, "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "bit_rate", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "float", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "target": {"_type": "Name", "_fields": {"id": "total_bit_rate", "ctx": {"_type": "Store", "_fields": {}}}}}}, {"_type": "AugAssign", "_fields": {"op": {"_type": "Add", "_fields": {}}, "value": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, "target": {"_type": "Name", "_fields": {"id": "count", "ctx": {"_type": "Store", "_fields": {}}}}}}, {"_type": "If", "_fields": {"body": [{"_type": "Break", "_fields": {}}], "test": {"_type": "BoolOp", "_fields": {"op": {"_type": "And", "_fields": {}}, "values": [{"_type": "Name", "_fields": {"id": "max_count", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Compare", "_fields": {"ops": [{"_type": "LtE", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "max_count", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Name", "_fields": {"id": "count", "ctx": {"_type": "Load", "_fields": {}}}}]}}]}}, "orelse": []}}], "test": {"_type": "Name", "_fields": {"id": "bit_rate", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": []}}], "iter": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "frames/frame"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "array", "value": {"_type": "Name", "_fields": {"id": "mp3", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "enumerate", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [], "target": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "index", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "frame", "ctx": {"_type": "Store", "_fields": {}}}}]}}, "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": null}}], "test": {"_type": "UnaryOp", "_fields": {"op": {"_type": "Not", "_fields": {}}, "operand": {"_type": "Name", "_fields": {"id": "count", "ctx": {"_type": "Load", "_fields": {}}}}}}, "orelse": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "total_bit_rate", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Name", "_fields": {"id": "count", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "bit_rate", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "bit_rate", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "%s (Variable bit rate)"}}], "func": {"_type": "Name", "_fields": {"id": "_", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "right": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "bit_rate", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "humanBitRate", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}]}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "bit_rate", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "timedelta", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "seconds", "value": {"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "size", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "frames"}}, "value": {"_type": "Name", "_fields": {"id": "mp3", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "func": {"_type": "Name", "_fields": {"id": "float", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "right": {"_type": "Name", "_fields": {"id": "bit_rate", "ctx": {"_type": "Load", "_fields": {}}}}}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "duration", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Name", "_fields": {"id": "duration", "ctx": {"_type": "Load", "_fields": {}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "duration", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "name": "computeVariableBitrate", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def computeVariableBitrate(self, mp3): if self.quality <= QUALITY_FAST: return count = 0 if QUALITY_BEST <= self.quality: self.warning("Process all MPEG audio frames to compute exact duration") max_count = None else: max_count = 500 * self.quality total_bit_rate = 0.0 for index, frame in enumerate(mp3.array("frames/frame")): if index < 3: continue bit_rate = frame.getBitRate() if bit_rate: total_bit_rate += float(bit_rate) count += 1 if max_count and max_count <= count: break if not count: return bit_rate = total_bit_rate / count self.bit_rate = (bit_rate, _("%s (Variable bit rate)") % humanBitRate(bit_rate)) duration = timedelta(seconds=float(mp3["frames"].size) / bit_rate) self.duration = duration
10,951
[ 0.009438585489988327, -0.003359645139425993, 0.03885375335812569, -0.043017491698265076, 0.02221049927175045, -0.0006465635378845036, -0.012432733550667763, -0.004271924961358309, -0.01871342770755291, 0.006333325989544392, 0.007701745256781578, -0.05015198886394501, -0.034456100314855576, ...
12
{"_type": "Module", "_fields": {"body": [{"_type": "ClassDef", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "aiff", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "common"}}, "value": {"_type": "Name", "_fields": {"id": "aiff", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "useCommon", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "common"}}, "comparators": [{"_type": "Name", "_fields": {"id": "aiff", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": []}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "computeBitRate", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "name": "extract", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "info", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "nb_channel"}}, "value": {"_type": "Name", "_fields": {"id": "info", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "nb_channel", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "sample_size"}}, "value": {"_type": "Name", "_fields": {"id": "info", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "bits_per_sample", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "info", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": "sample_rate"}}], "func": {"_type": "Name", "_fields": {"id": "getValue", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "sample_rate", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "sample_rate"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "rate", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "nb_sample"}}, "value": {"_type": "Name", "_fields": {"id": "info", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "func": {"_type": "Name", "_fields": {"id": "float", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "right": {"_type": "Name", "_fields": {"id": "rate", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "sec", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "timedelta", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "seconds", "value": {"_type": "Name", "_fields": {"id": "sec", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "duration", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "test": {"_type": "Name", "_fields": {"id": "rate", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": []}}], "test": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "sample_rate"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "has", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "orelse": []}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "display", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "codec"}}, "value": {"_type": "Name", "_fields": {"id": "info", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "compression", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "codec"}}, "comparators": [{"_type": "Name", "_fields": {"id": "info", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": []}}], "name": "useCommon", "returns": null, "type_params": [], "type_comment": null, "decorator_list": [{"_type": "Name", "_fields": {"id": "fault_tolerant", "ctx": {"_type": "Load", "_fields": {}}}}]}}], "name": "AiffMetadata", "bases": [{"_type": "Name", "_fields": {"id": "RootMetadata", "ctx": {"_type": "Load", "_fields": {}}}}], "keywords": [], "type_params": [], "decorator_list": []}}], "type_ignores": []}}
class AiffMetadata(RootMetadata): def extract(self, aiff): if "common" in aiff: self.useCommon(aiff["common"]) computeBitRate(self) @fault_tolerant def useCommon(self, info): self.nb_channel = info["nb_channel"].value self.bits_per_sample = info["sample_size"].value self.sample_rate = getValue(info, "sample_rate") if self.has("sample_rate"): rate = self.get("sample_rate") if rate: sec = float(info["nb_sample"].value) / rate self.duration = timedelta(seconds=sec) if "codec" in info: self.compression = info["codec"].display
10,952
[ 0.03936685621738434, -0.029441120103001595, -0.0049180565401911736, -0.02368284948170185, 0.013196971267461777, -0.0015277903294190764, 0.020602062344551086, 0.0019016858423128724, -0.004789223428815603, 0.008430153131484985, 0.0009746489813551307, 0.016524221748113632, -0.016255352646112442...
11
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "info", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "nb_channel"}}, "value": {"_type": "Name", "_fields": {"id": "info", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "nb_channel", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "sample_size"}}, "value": {"_type": "Name", "_fields": {"id": "info", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "bits_per_sample", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "info", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": "sample_rate"}}], "func": {"_type": "Name", "_fields": {"id": "getValue", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "sample_rate", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "sample_rate"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "rate", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "nb_sample"}}, "value": {"_type": "Name", "_fields": {"id": "info", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "func": {"_type": "Name", "_fields": {"id": "float", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "right": {"_type": "Name", "_fields": {"id": "rate", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "sec", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "timedelta", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "seconds", "value": {"_type": "Name", "_fields": {"id": "sec", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "duration", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "test": {"_type": "Name", "_fields": {"id": "rate", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": []}}], "test": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "sample_rate"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "has", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "orelse": []}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "display", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "codec"}}, "value": {"_type": "Name", "_fields": {"id": "info", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "compression", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "codec"}}, "comparators": [{"_type": "Name", "_fields": {"id": "info", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": []}}], "name": "useCommon", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def useCommon(self, info): self.nb_channel = info["nb_channel"].value self.bits_per_sample = info["sample_size"].value self.sample_rate = getValue(info, "sample_rate") if self.has("sample_rate"): rate = self.get("sample_rate") if rate: sec = float(info["nb_sample"].value) / rate self.duration = timedelta(seconds=sec) if "codec" in info: self.compression = info["codec"].display
10,953
[ 0.042438384145498276, -0.032705001533031464, 0.010588482022285461, -0.027679959312081337, 0.0059118145145475864, 0.012615390121936798, 0.006624399218708277, -0.022612690925598145, -0.03487970679998398, 0.0187066700309515, 0.01965678296983242, 0.020955270156264305, -0.02114529348909855, 0.0...
9
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "info", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "nb_channel"}}, "value": {"_type": "Name", "_fields": {"id": "info", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "nb_channel", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "bits_per_sample"}}, "value": {"_type": "Name", "_fields": {"id": "info", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "bits_per_sample", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "sample_hertz"}}, "value": {"_type": "Name", "_fields": {"id": "info", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "sample_rate", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "total_samples"}}, "value": {"_type": "Name", "_fields": {"id": "info", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "sec", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "sec", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "float", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "right": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "sample_hertz"}}, "value": {"_type": "Name", "_fields": {"id": "info", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "sec", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "timedelta", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "seconds", "value": {"_type": "Name", "_fields": {"id": "sec", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "duration", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "test": {"_type": "Name", "_fields": {"id": "sec", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": []}}], "name": "useStreamInfo", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def useStreamInfo(self, info): self.nb_channel = info["nb_channel"].value + 1 self.bits_per_sample = info["bits_per_sample"].value + 1 self.sample_rate = info["sample_hertz"].value sec = info["total_samples"].value if sec: sec = float(sec) / info["sample_hertz"].value self.duration = timedelta(seconds=sec)
10,954
[ 0.016621140763163567, 0.03823445737361908, -0.012235492467880249, -0.050901513546705246, 0.044742945581674576, 0.020738517865538597, -0.016912739723920822, -0.018848957493901253, -0.038607701659202576, 0.009546949528157711, 0.01613125391304493, -0.007284142076969147, -0.004811382852494717, ...
10
{"_type": "Module", "_fields": {"body": [{"_type": "ClassDef", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "flac", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "metadata/stream_info/content"}}, "value": {"_type": "Name", "_fields": {"id": "flac", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "useStreamInfo", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "metadata/stream_info/content"}}, "comparators": [{"_type": "Name", "_fields": {"id": "flac", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": []}}, {"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "metadata/comment/content"}}, "value": {"_type": "Name", "_fields": {"id": "flac", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "readVorbisComment", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "metadata/comment/content"}}, "comparators": [{"_type": "Name", "_fields": {"id": "flac", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": []}}], "name": "extract", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "info", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "nb_channel"}}, "value": {"_type": "Name", "_fields": {"id": "info", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "nb_channel", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "bits_per_sample"}}, "value": {"_type": "Name", "_fields": {"id": "info", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "bits_per_sample", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "sample_hertz"}}, "value": {"_type": "Name", "_fields": {"id": "info", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "sample_rate", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "total_samples"}}, "value": {"_type": "Name", "_fields": {"id": "info", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "sec", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "sec", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "float", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "right": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "value", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "sample_hertz"}}, "value": {"_type": "Name", "_fields": {"id": "info", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "sec", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "timedelta", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "seconds", "value": {"_type": "Name", "_fields": {"id": "sec", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "duration", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "test": {"_type": "Name", "_fields": {"id": "sec", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": []}}], "name": "useStreamInfo", "returns": null, "type_params": [], "type_comment": null, "decorator_list": [{"_type": "Name", "_fields": {"id": "fault_tolerant", "ctx": {"_type": "Load", "_fields": {}}}}]}}], "name": "FlacMetadata", "bases": [{"_type": "Name", "_fields": {"id": "RootMetadata", "ctx": {"_type": "Load", "_fields": {}}}}], "keywords": [], "type_params": [], "decorator_list": []}}], "type_ignores": []}}
class FlacMetadata(RootMetadata): def extract(self, flac): if "metadata/stream_info/content" in flac: self.useStreamInfo(flac["metadata/stream_info/content"]) if "metadata/comment/content" in flac: readVorbisComment(self, flac["metadata/comment/content"]) @fault_tolerant def useStreamInfo(self, info): self.nb_channel = info["nb_channel"].value + 1 self.bits_per_sample = info["bits_per_sample"].value + 1 self.sample_rate = info["sample_hertz"].value sec = info["total_samples"].value if sec: sec = float(sec) / info["sample_hertz"].value self.duration = timedelta(seconds=sec)
10,955
[ 0.017016390338540077, 0.028087813407182693, 0.040257763117551804, -0.048249006271362305, -0.009030533954501152, -0.009138232097029686, -0.05436629056930542, -0.02500763162970543, 0.00019217481894884259, 0.02718314528465271, -0.026881588622927666, -0.03265423700213432, -0.015616307035088539, ...
10
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "sigs_str", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "headers_str", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "ListComp", "_fields": {"elt": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "strip", "value": {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "generators": [{"_type": "comprehension", "_fields": {"ifs": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "strip", "value": {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}], "iter": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": ","}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "split", "value": {"_type": "Name", "_fields": {"id": "sigs_str", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "target": {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Store", "_fields": {}}}}, "is_async": 0}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "sigs", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "ListComp", "_fields": {"elt": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "strip", "value": {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "generators": [{"_type": "comprehension", "_fields": {"ifs": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "strip", "value": {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}], "iter": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": ","}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "split", "value": {"_type": "Name", "_fields": {"id": "headers_str", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "target": {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Store", "_fields": {}}}}, "is_async": 0}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "headers", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Mult", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "headers", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "sigs", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "targets": [{"_type": "Name", "_fields": {"id": "headers", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "headers", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}]}}, "orelse": []}}, {"_type": "If", "_fields": {"body": [{"_type": "Raise", "_fields": {"exc": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "%s: Number of headers and signatures doesn't match: %r -- %r"}}, "right": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "name", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Name", "_fields": {"id": "sigs_str", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "headers_str", "ctx": {"_type": "Load", "_fields": {}}}}]}}}}], "func": {"_type": "Name", "_fields": {"id": "ValueError", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "cause": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "NotEq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "headers", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "sigs", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}]}}, "orelse": []}}, {"_type": "Return", "_fields": {"value": {"_type": "ListComp", "_fields": {"elt": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_parse_signature", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "right": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "h", "ctx": {"_type": "Load", "_fields": {}}}}]}}}}, "generators": [{"_type": "comprehension", "_fields": {"ifs": [], "iter": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "sigs", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "headers", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "zip", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "target": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "h", "ctx": {"_type": "Store", "_fields": {}}}}]}}, "is_async": 0}}]}}}}], "name": "_parse_signatures", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def _parse_signatures(self, sigs_str, headers_str): sigs = [x.strip() for x in sigs_str.split(",") if x.strip()] headers = [x.strip() for x in headers_str.split(",") if x.strip()] if len(headers) == 1: headers = headers * len(sigs) if len(headers) != len(sigs): raise ValueError("%s: Number of headers and signatures doesn't match: %r -- %r" % ( self.name, sigs_str, headers_str)) return [self._parse_signature(x) + (h,) for x, h in zip(sigs, headers)]
10,956
[ 0.027546469122171402, 0.04749986529350281, 0.003073901403695345, -0.013287882320582867, -0.006778761278837919, -0.009237882681190968, -0.030868440866470337, -0.02614433877170086, 0.0204926747828722, -0.01604899950325489, 0.0055653792805969715, -0.00625026598572731, -0.02914274111390114, -0...
9
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "name", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "signatures", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "headers", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Name", "_fields": {"id": "name", "ctx": {"_type": "Load", "_fields": {}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "name", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "signatures", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "headers", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_parse_signatures", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "signatures", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "scipy.special."}}, "right": {"_type": "Name", "_fields": {"id": "name", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Name", "_fields": {"id": "add_newdocs", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "doc", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Raise", "_fields": {"exc": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "No docstring for ufunc %r"}}, "right": {"_type": "Name", "_fields": {"id": "name", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "ValueError", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "cause": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Is", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "doc", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}]}}, "orelse": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "strip", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "doc", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "dedent", "value": {"_type": "Name", "_fields": {"id": "textwrap", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, "keywords": []}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "doc", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Dict", "_fields": {"keys": [], "values": []}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "function_name_overrides", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "name": "__init__", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def __init__(self, name, signatures, headers): self.name = name self.signatures = self._parse_signatures(signatures, headers) self.doc = add_newdocs.get("scipy.special." + name) if self.doc is None: raise ValueError("No docstring for ufunc %r" % name) self.doc = textwrap.dedent(self.doc).strip() self.function_name_overrides = {}
10,957
[ 0.03686638921499252, 0.0017535198712721467, -0.017450254410505295, -0.047035593539476395, -0.05514182895421982, 0.017025524750351906, -0.033128783106803894, -0.05048195645213127, -0.000006020140062901191, 0.04800640046596527, 0.012183626182377338, -0.021903829649090767, 0.025240978226065636,...
11
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "sig", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "\\s*(.*):\\s*([fdgFDGil]*)\\s*\\*\\s*([fdgFDGil]*)\\s*->\\s*([*fdgFDGil]*)\\s*$"}}, {"_type": "Name", "_fields": {"id": "sig", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "match", "value": {"_type": "Name", "_fields": {"id": "re", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "m", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "ListComp", "_fields": {"elt": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "strip", "value": {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "generators": [{"_type": "comprehension", "_fields": {"ifs": [], "iter": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "groups", "value": {"_type": "Name", "_fields": {"id": "m", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "target": {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Store", "_fields": {}}}}, "is_async": 0}}]}}, "targets": [{"_type": "Tuple", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "func", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "inarg", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "outarg", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "ret", "ctx": {"_type": "Store", "_fields": {}}}}]}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Raise", "_fields": {"exc": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "%s: Invalid signature: %r"}}, "right": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "name", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Name", "_fields": {"id": "sig", "ctx": {"_type": "Load", "_fields": {}}}}]}}}}], "func": {"_type": "Name", "_fields": {"id": "ValueError", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "cause": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Gt", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "*"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "count", "value": {"_type": "Name", "_fields": {"id": "ret", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}]}}, "orelse": []}}, {"_type": "Return", "_fields": {"value": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "func", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "inarg", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "outarg", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "ret", "ctx": {"_type": "Load", "_fields": {}}}}]}}}}], "test": {"_type": "Name", "_fields": {"id": "m", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "\\s*(.*):\\s*([fdgFDGil]*)\\s*->\\s*([fdgFDGil]?)\\s*$"}}, {"_type": "Name", "_fields": {"id": "sig", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "match", "value": {"_type": "Name", "_fields": {"id": "re", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "m", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "ListComp", "_fields": {"elt": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "strip", "value": {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "generators": [{"_type": "comprehension", "_fields": {"ifs": [], "iter": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "groups", "value": {"_type": "Name", "_fields": {"id": "m", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "target": {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Store", "_fields": {}}}}, "is_async": 0}}]}}, "targets": [{"_type": "Tuple", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "func", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "inarg", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "ret", "ctx": {"_type": "Store", "_fields": {}}}}]}}], "type_comment": null}}, {"_type": "Return", "_fields": {"value": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "func", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "inarg", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": ""}}, {"_type": "Name", "_fields": {"id": "ret", "ctx": {"_type": "Load", "_fields": {}}}}]}}}}], "test": {"_type": "Name", "_fields": {"id": "m", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": []}}, {"_type": "Raise", "_fields": {"exc": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "%s: Invalid signature: %r"}}, "right": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "name", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Name", "_fields": {"id": "sig", "ctx": {"_type": "Load", "_fields": {}}}}]}}}}], "func": {"_type": "Name", "_fields": {"id": "ValueError", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "cause": null}}], "name": "_parse_signature", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def _parse_signature(self, sig): m = re.match("\s*(.*):\s*([fdgFDGil]*)\s*\\*\s*([fdgFDGil]*)\s*->\s*([*fdgFDGil]*)\s*$", sig) if m: func, inarg, outarg, ret = [x.strip() for x in m.groups()] if ret.count('*') > 1: raise ValueError("%s: Invalid signature: %r" % (self.name, sig)) return (func, inarg, outarg, ret) m = re.match("\s*(.*):\s*([fdgFDGil]*)\s*->\s*([fdgFDGil]?)\s*$", sig) if m: func, inarg, ret = [x.strip() for x in m.groups()] return (func, inarg, "", ret) raise ValueError("%s: Invalid signature: %r" % (self.name, sig))
10,958
[ 0.022998856380581856, 0.044162567704916, 0.00960470363497734, -0.07545531541109085, -0.031245077028870583, -0.004182693548500538, -0.016158781945705414, -0.09056544303894043, 0.012440831400454044, 0.03353304788470268, 0.01746959798038006, -0.02175953984260559, 0.015038629993796349, -0.0294...
11
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "all_loops", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}, "targets": [{"_type": "Name", "_fields": {"id": "inarg_num", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}, "targets": [{"_type": "Name", "_fields": {"id": "outarg_num", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "set", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "seen", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}, "targets": [{"_type": "Name", "_fields": {"id": "variants", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "func_name", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "inarg", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "outarg", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "ret", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "inp", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "outp", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "inp", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Name", "_fields": {"id": "seen", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": []}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "inp", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "add", "value": {"_type": "Name", "_fields": {"id": "seen", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "func_name", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "inp", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "outp", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "sig", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Raise", "_fields": {"exc": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "%s: void signature %r"}}, "right": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "name", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Name", "_fields": {"id": "sig", "ctx": {"_type": "Load", "_fields": {}}}}]}}}}], "func": {"_type": "Name", "_fields": {"id": "ValueError", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "cause": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "v"}}, "comparators": [{"_type": "Name", "_fields": {"id": "outp", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": []}}, {"_type": "If", "_fields": {"body": [{"_type": "Raise", "_fields": {"exc": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "%s: signature %r does not have %d/%d input/output args"}}, "right": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "name", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Name", "_fields": {"id": "sig", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "inarg_num", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "outarg_num", "ctx": {"_type": "Load", "_fields": {}}}}]}}}}], "func": {"_type": "Name", "_fields": {"id": "ValueError", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "cause": null}}], "test": {"_type": "BoolOp", "_fields": {"op": {"_type": "Or", "_fields": {}}, "values": [{"_type": "Compare", "_fields": {"ops": [{"_type": "NotEq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "inp", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "Name", "_fields": {"id": "inarg_num", "ctx": {"_type": "Load", "_fields": {}}}}]}}, {"_type": "Compare", "_fields": {"ops": [{"_type": "NotEq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "outp", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "Name", "_fields": {"id": "outarg_num", "ctx": {"_type": "Load", "_fields": {}}}}]}}]}}, "orelse": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "inarg", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "outarg", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "ret", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "inp", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "outp", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "generate_loop", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Tuple", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "loop_name", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "loop", "ctx": {"_type": "Store", "_fields": {}}}}]}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Name", "_fields": {"id": "loop", "ctx": {"_type": "Load", "_fields": {}}}}, "targets": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "slice": {"_type": "Name", "_fields": {"id": "loop_name", "ctx": {"_type": "Load", "_fields": {}}}}, "value": {"_type": "Name", "_fields": {"id": "all_loops", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "func_name", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "loop_name", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "inp", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "outp", "ctx": {"_type": "Load", "_fields": {}}}}]}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "append", "value": {"_type": "Name", "_fields": {"id": "variants", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "name": "add_variant", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "For", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "\\*.*"}}, {"_type": "Constant", "_fields": {"kind": null, "value": ""}}, {"_type": "Name", "_fields": {"id": "ret", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "sub", "value": {"_type": "Name", "_fields": {"id": "re", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "right": {"_type": "Name", "_fields": {"id": "outarg", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "outp", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "*"}}, {"_type": "Constant", "_fields": {"kind": null, "value": ""}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "replace", "value": {"_type": "Name", "_fields": {"id": "ret", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "ret", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "inarg", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "inarg_num", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "outp", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "outarg_num", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Is", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "inarg_num", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}]}}, "orelse": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "inarg", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "outp", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "iter_variants", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "list", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "targets": [{"_type": "Tuple", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "inp", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "outp", "ctx": {"_type": "Store", "_fields": {}}}}]}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "func_name", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "inarg", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "outarg", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "ret", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "inp", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "outp", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "add_variant", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "iter": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "signatures", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "orelse": [], "target": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "func_name", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "inarg", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "outarg", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "ret", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "header", "ctx": {"_type": "Store", "_fields": {}}}}]}}, "type_comment": null}}, {"_type": "For", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "\\*.*"}}, {"_type": "Constant", "_fields": {"kind": null, "value": ""}}, {"_type": "Name", "_fields": {"id": "ret", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "sub", "value": {"_type": "Name", "_fields": {"id": "re", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "right": {"_type": "Name", "_fields": {"id": "outarg", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "outp", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "*"}}, {"_type": "Constant", "_fields": {"kind": null, "value": ""}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "replace", "value": {"_type": "Name", "_fields": {"id": "ret", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "ret", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "For", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "func_name", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "inarg", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "outarg", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "ret", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "inp", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "outp", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "add_variant", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "iter": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "inarg", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "outp", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "iter_variants", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [], "target": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "inp", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "outp", "ctx": {"_type": "Store", "_fields": {}}}}]}}, "type_comment": null}}], "iter": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "signatures", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "orelse": [], "target": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "func_name", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "inarg", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "outarg", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "ret", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "header", "ctx": {"_type": "Store", "_fields": {}}}}]}}, "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "sort", "value": {"_type": "Name", "_fields": {"id": "variants", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "key", "value": {"_type": "Lambda", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "v", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 2}}, "value": {"_type": "Name", "_fields": {"id": "v", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "cast_order", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}}}]}}}}, {"_type": "Return", "_fields": {"value": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "variants", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "inarg_num", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "outarg_num", "ctx": {"_type": "Load", "_fields": {}}}}]}}}}], "name": "_get_signatures_and_loops", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def _get_signatures_and_loops(self, all_loops): inarg_num = None outarg_num = None seen = set() variants = [] def add_variant(func_name, inarg, outarg, ret, inp, outp): if inp in seen: return seen.add(inp) sig = (func_name, inp, outp) if "v" in outp: raise ValueError("%s: void signature %r" % (self.name, sig)) if len(inp) != inarg_num or len(outp) != outarg_num: raise ValueError("%s: signature %r does not have %d/%d input/output args" % ( self.name, sig, inarg_num, outarg_num)) loop_name, loop = generate_loop(inarg, outarg, ret, inp, outp) all_loops[loop_name] = loop variants.append((func_name, loop_name, inp, outp)) # First add base variants for func_name, inarg, outarg, ret, header in self.signatures: outp = re.sub(r'\*.*', '', ret) + outarg ret = ret.replace('*', '') if inarg_num is None: inarg_num = len(inarg) outarg_num = len(outp) inp, outp = list(iter_variants(inarg, outp))[0] add_variant(func_name, inarg, outarg, ret, inp, outp) # Then the supplementary ones for func_name, inarg, outarg, ret, header in self.signatures: outp = re.sub(r'\*.*', '', ret) + outarg ret = ret.replace('*', '') for inp, outp in iter_variants(inarg, outp): add_variant(func_name, inarg, outarg, ret, inp, outp) # Then sort variants to input argument cast order # -- the sort is stable, so functions earlier in the signature list # are still preferred variants.sort(key=lambda v: cast_order(v[2])) return variants, inarg_num, outarg_num
10,959
[ 0.047517020255327225, 0.031113486737012863, 0.004708757624030113, -0.052017103880643845, -0.025790806859731674, -0.004273265600204468, -0.05153322219848633, -0.0018553775735199451, 0.0028987438417971134, 0.04420244321227074, 0.016609182581305504, -0.03774264454841614, 0.04023462533950806, ...
10
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}, "targets": [{"_type": "Name", "_fields": {"id": "prototypes", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "For", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "*"}}, {"_type": "Constant", "_fields": {"kind": null, "value": ""}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "replace", "value": {"_type": "Name", "_fields": {"id": "ret", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "ret", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "ListComp", "_fields": {"elt": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}, "value": {"_type": "Name", "_fields": {"id": "C_TYPES", "ctx": {"_type": "Load", "_fields": {}}}}}}, "generators": [{"_type": "comprehension", "_fields": {"ifs": [], "iter": {"_type": "Name", "_fields": {"id": "inarg", "ctx": {"_type": "Load", "_fields": {}}}}, "target": {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Store", "_fields": {}}}}, "is_async": 0}}]}}, "right": {"_type": "ListComp", "_fields": {"elt": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}, "value": {"_type": "Name", "_fields": {"id": "C_TYPES", "ctx": {"_type": "Load", "_fields": {}}}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": " *"}}}}, "generators": [{"_type": "comprehension", "_fields": {"ifs": [], "iter": {"_type": "Name", "_fields": {"id": "outarg", "ctx": {"_type": "Load", "_fields": {}}}}, "target": {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Store", "_fields": {}}}}, "is_async": 0}}]}}}}, "targets": [{"_type": "Name", "_fields": {"id": "c_args", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "ListComp", "_fields": {"elt": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}, "value": {"_type": "Name", "_fields": {"id": "CY_TYPES", "ctx": {"_type": "Load", "_fields": {}}}}}}, "generators": [{"_type": "comprehension", "_fields": {"ifs": [], "iter": {"_type": "Name", "_fields": {"id": "inarg", "ctx": {"_type": "Load", "_fields": {}}}}, "target": {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Store", "_fields": {}}}}, "is_async": 0}}]}}, "right": {"_type": "ListComp", "_fields": {"elt": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}, "value": {"_type": "Name", "_fields": {"id": "CY_TYPES", "ctx": {"_type": "Load", "_fields": {}}}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": " *"}}}}, "generators": [{"_type": "comprehension", "_fields": {"ifs": [], "iter": {"_type": "Name", "_fields": {"id": "outarg", "ctx": {"_type": "Load", "_fields": {}}}}, "target": {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Store", "_fields": {}}}}, "is_async": 0}}]}}}}, "targets": [{"_type": "Name", "_fields": {"id": "cy_args", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "%s (*)(%s)"}}, "right": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Name", "_fields": {"id": "ret", "ctx": {"_type": "Load", "_fields": {}}}}, "value": {"_type": "Name", "_fields": {"id": "C_TYPES", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "c_args", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "join", "value": {"_type": "Constant", "_fields": {"kind": null, "value": ", "}}}}, "keywords": []}}]}}}}, "targets": [{"_type": "Name", "_fields": {"id": "c_proto", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "%s (*)(%s) nogil"}}, "right": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Name", "_fields": {"id": "ret", "ctx": {"_type": "Load", "_fields": {}}}}, "value": {"_type": "Name", "_fields": {"id": "CY_TYPES", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "cy_args", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "join", "value": {"_type": "Constant", "_fields": {"kind": null, "value": ", "}}}}, "keywords": []}}]}}}}, "targets": [{"_type": "Name", "_fields": {"id": "cy_proto", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "func_name", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "c_proto", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "cy_proto", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "header", "ctx": {"_type": "Load", "_fields": {}}}}]}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "append", "value": {"_type": "Name", "_fields": {"id": "prototypes", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "iter": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "signatures", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "orelse": [], "target": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "func_name", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "inarg", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "outarg", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "ret", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "header", "ctx": {"_type": "Store", "_fields": {}}}}]}}, "type_comment": null}}, {"_type": "Return", "_fields": {"value": {"_type": "Name", "_fields": {"id": "prototypes", "ctx": {"_type": "Load", "_fields": {}}}}}}], "name": "get_prototypes", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def get_prototypes(self): prototypes = [] for func_name, inarg, outarg, ret, header in self.signatures: ret = ret.replace('*', '') c_args = ([C_TYPES[x] for x in inarg] + [C_TYPES[x] + ' *' for x in outarg]) cy_args = ([CY_TYPES[x] for x in inarg] + [CY_TYPES[x] + ' *' for x in outarg]) c_proto = "%s (*)(%s)" % (C_TYPES[ret], ", ".join(c_args)) cy_proto = "%s (*)(%s) nogil" % (CY_TYPES[ret], ", ".join(cy_args)) prototypes.append((func_name, c_proto, cy_proto, header)) return prototypes
10,960
[ 0.06570042669773102, 0.020168397575616837, -0.032124243676662445, 0.0059949373826384544, -0.006998819764703512, 0.049139201641082764, 0.0072653875686228275, -0.009494347497820854, 0.021200640127062798, -0.01056628953665495, 0.018693769350647926, -0.046121884137392044, 0.009817631915211678, ...
10
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "c_name", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "specialized", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "prefix", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "override", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [{"_type": "Constant", "_fields": {"kind": null, "value": false}}, {"_type": "Constant", "_fields": {"kind": null, "value": "_func_"}}, {"_type": "Constant", "_fields": {"kind": null, "value": true}}], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Name", "_fields": {"id": "c_name", "ctx": {"_type": "Load", "_fields": {}}}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "function_name_overrides", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "c_name", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": ""}}, "targets": [{"_type": "Name", "_fields": {"id": "prefix", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "test": {"_type": "BoolOp", "_fields": {"op": {"_type": "And", "_fields": {}}, "values": [{"_type": "Name", "_fields": {"id": "override", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "c_name", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "function_name_overrides", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}]}}, "orelse": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "^(.*?)(\\[.*\\])$"}}, {"_type": "Name", "_fields": {"id": "c_name", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "match", "value": {"_type": "Name", "_fields": {"id": "re", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "m", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "groups", "value": {"_type": "Name", "_fields": {"id": "m", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Tuple", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "c_base_name", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "fused_part", "ctx": {"_type": "Store", "_fields": {}}}}]}}], "type_comment": null}}], "test": {"_type": "Name", "_fields": {"id": "m", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": [{"_type": "Assign", "_fields": {"value": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "c_name", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": ""}}]}}, "targets": [{"_type": "Tuple", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "c_base_name", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "fused_part", "ctx": {"_type": "Store", "_fields": {}}}}]}}], "type_comment": null}}]}}, {"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "%s%s%s"}}, "right": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "prefix", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "c_base_name", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": " "}}, {"_type": "Constant", "_fields": {"kind": null, "value": "_"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "replace", "value": {"_type": "Name", "_fields": {"id": "fused_part", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}]}}}}}}], "test": {"_type": "Name", "_fields": {"id": "specialized", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": [{"_type": "Return", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "%s%s"}}, "right": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "prefix", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "c_base_name", "ctx": {"_type": "Load", "_fields": {}}}}]}}}}}}]}}], "name": "cython_func_name", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def cython_func_name(self, c_name, specialized=False, prefix="_func_", override=True): # act on function name overrides if override and c_name in self.function_name_overrides: c_name = self.function_name_overrides[c_name] prefix = "" # support fused types m = re.match(r'^(.*?)(\[.*\])$', c_name) if m: c_base_name, fused_part = m.groups() else: c_base_name, fused_part = c_name, "" if specialized: return "%s%s%s" % (prefix, c_base_name, fused_part.replace(' ', '_')) else: return "%s%s" % (prefix, c_base_name,)
10,961
[ -0.03368399292230606, 0.0623246431350708, 0.008958877995610237, -0.043423667550086975, 0.026280919089913368, 0.03396160900592804, -0.02491597644984722, -0.025887630879878998, 0.028316764160990715, 0.051405105739831924, 0.0013063825899735093, -0.03898182138800621, 0.007241133600473404, 0.01...
10
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "cls", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "ufunc_str", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}, "targets": [{"_type": "Name", "_fields": {"id": "ufuncs", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "splitlines", "value": {"_type": "Name", "_fields": {"id": "ufunc_str", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "lines", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "sort", "value": {"_type": "Name", "_fields": {"id": "lines", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "For", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "strip", "value": {"_type": "Name", "_fields": {"id": "line", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "line", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Continue", "_fields": {}}], "test": {"_type": "UnaryOp", "_fields": {"op": {"_type": "Not", "_fields": {}}, "operand": {"_type": "Name", "_fields": {"id": "line", "ctx": {"_type": "Load", "_fields": {}}}}}}, "orelse": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "^([a-z0-9_]+)\\s*--\\s*(.*?)\\s*--(.*)$"}}, {"_type": "Name", "_fields": {"id": "line", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "match", "value": {"_type": "Name", "_fields": {"id": "re", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "m", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Raise", "_fields": {"exc": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "Unparseable line %r"}}, "right": {"_type": "Name", "_fields": {"id": "line", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "ValueError", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "cause": null}}], "test": {"_type": "UnaryOp", "_fields": {"op": {"_type": "Not", "_fields": {}}, "operand": {"_type": "Name", "_fields": {"id": "m", "ctx": {"_type": "Load", "_fields": {}}}}}}, "orelse": []}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "group", "value": {"_type": "Name", "_fields": {"id": "m", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 2}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "group", "value": {"_type": "Name", "_fields": {"id": "m", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 3}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "group", "value": {"_type": "Name", "_fields": {"id": "m", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "cls", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "append", "value": {"_type": "Name", "_fields": {"id": "ufuncs", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "iter": {"_type": "Name", "_fields": {"id": "lines", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "line", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}, {"_type": "Return", "_fields": {"value": {"_type": "Name", "_fields": {"id": "ufuncs", "ctx": {"_type": "Load", "_fields": {}}}}}}], "name": "parse_all", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def parse_all(cls, ufunc_str): ufuncs = [] lines = ufunc_str.splitlines() lines.sort() for line in lines: line = line.strip() if not line: continue m = re.match("^([a-z0-9_]+)\s*--\s*(.*?)\s*--(.*)$", line) if not m: raise ValueError("Unparseable line %r" % line) ufuncs.append(cls(m.group(1), m.group(2), m.group(3))) return ufuncs
10,962
[ 0.012933610938489437, 0.042698632925748825, 0.028018604964017868, -0.039155177772045135, -0.0034200670197606087, 0.0020390686113387346, -0.038927383720874786, -0.049886785447597504, 0.0510004423558712, 0.049456506967544556, 0.012465368956327438, -0.018122240900993347, 0.0015921819722279906, ...
14
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "all_loops", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": ""}}, "targets": [{"_type": "Name", "_fields": {"id": "toplevel", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "all_loops", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_get_signatures_and_loops", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Tuple", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "variants", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "inarg_num", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "outarg_num", "ctx": {"_type": "Store", "_fields": {}}}}]}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}, "targets": [{"_type": "Name", "_fields": {"id": "loops", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}, "targets": [{"_type": "Name", "_fields": {"id": "funcs", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}, "targets": [{"_type": "Name", "_fields": {"id": "types", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "For", "_fields": {"body": [{"_type": "For", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}, "value": {"_type": "Name", "_fields": {"id": "TYPE_NAMES", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "append", "value": {"_type": "Name", "_fields": {"id": "types", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "iter": {"_type": "Name", "_fields": {"id": "inputs", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}, {"_type": "For", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}, "value": {"_type": "Name", "_fields": {"id": "TYPE_NAMES", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "append", "value": {"_type": "Name", "_fields": {"id": "types", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "iter": {"_type": "Name", "_fields": {"id": "outputs", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "loop_name", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "append", "value": {"_type": "Name", "_fields": {"id": "loops", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "func_name", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "append", "value": {"_type": "Name", "_fields": {"id": "funcs", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "iter": {"_type": "Name", "_fields": {"id": "variants", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": [], "target": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "func_name", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "loop_name", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "inputs", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "outputs", "ctx": {"_type": "Store", "_fields": {}}}}]}}, "type_comment": null}}, {"_type": "AugAssign", "_fields": {"op": {"_type": "Add", "_fields": {}}, "value": {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "cdef np.PyUFuncGenericFunction ufunc_%s_loops[%d]\n"}}, "right": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "name", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "loops", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}]}}}}, "target": {"_type": "Name", "_fields": {"id": "toplevel", "ctx": {"_type": "Store", "_fields": {}}}}}}, {"_type": "AugAssign", "_fields": {"op": {"_type": "Add", "_fields": {}}, "value": {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "cdef void *ufunc_%s_ptr[%d]\n"}}, "right": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "name", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "BinOp", "_fields": {"op": {"_type": "Mult", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": 2}}, "right": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "funcs", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}]}}}}, "target": {"_type": "Name", "_fields": {"id": "toplevel", "ctx": {"_type": "Store", "_fields": {}}}}}}, {"_type": "AugAssign", "_fields": {"op": {"_type": "Add", "_fields": {}}, "value": {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "cdef void *ufunc_%s_data[%d]\n"}}, "right": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "name", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "funcs", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}]}}}}, "target": {"_type": "Name", "_fields": {"id": "toplevel", "ctx": {"_type": "Store", "_fields": {}}}}}}, {"_type": "AugAssign", "_fields": {"op": {"_type": "Add", "_fields": {}}, "value": {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "cdef char ufunc_%s_types[%d]\n"}}, "right": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "name", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "types", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}]}}}}, "target": {"_type": "Name", "_fields": {"id": "toplevel", "ctx": {"_type": "Store", "_fields": {}}}}}}, {"_type": "AugAssign", "_fields": {"op": {"_type": "Add", "_fields": {}}, "value": {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "cdef char *ufunc_%s_doc = (\n \"%s\")\n"}}, "right": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "name", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "\n"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "\\n\"\n \""}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "replace", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "\""}}, {"_type": "Constant", "_fields": {"kind": null, "value": "\\\""}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "replace", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "\\"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "\\\\"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "replace", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "doc", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}}}, "keywords": []}}}}, "keywords": []}}]}}}}, "target": {"_type": "Name", "_fields": {"id": "toplevel", "ctx": {"_type": "Store", "_fields": {}}}}}}, {"_type": "For", "_fields": {"body": [{"_type": "AugAssign", "_fields": {"op": {"_type": "Add", "_fields": {}}, "value": {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "ufunc_%s_loops[%d] = <np.PyUFuncGenericFunction>%s\n"}}, "right": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "name", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Name", "_fields": {"id": "j", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "function", "ctx": {"_type": "Load", "_fields": {}}}}]}}}}, "target": {"_type": "Name", "_fields": {"id": "toplevel", "ctx": {"_type": "Store", "_fields": {}}}}}}], "iter": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "loops", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "enumerate", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [], "target": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "j", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "function", "ctx": {"_type": "Store", "_fields": {}}}}]}}, "type_comment": null}}, {"_type": "For", "_fields": {"body": [{"_type": "AugAssign", "_fields": {"op": {"_type": "Add", "_fields": {}}, "value": {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "ufunc_%s_types[%d] = <char>%s\n"}}, "right": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "name", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Name", "_fields": {"id": "j", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "type", "ctx": {"_type": "Load", "_fields": {}}}}]}}}}, "target": {"_type": "Name", "_fields": {"id": "toplevel", "ctx": {"_type": "Store", "_fields": {}}}}}}], "iter": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "types", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "enumerate", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [], "target": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "j", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "type", "ctx": {"_type": "Store", "_fields": {}}}}]}}, "type_comment": null}}, {"_type": "For", "_fields": {"body": [{"_type": "AugAssign", "_fields": {"op": {"_type": "Add", "_fields": {}}, "value": {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "ufunc_%s_ptr[2*%d] = <void*>%s\n"}}, "right": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "name", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Name", "_fields": {"id": "j", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "func", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "cython_func_name", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "specialized", "value": {"_type": "Constant", "_fields": {"kind": null, "value": true}}}}]}}]}}}}, "target": {"_type": "Name", "_fields": {"id": "toplevel", "ctx": {"_type": "Store", "_fields": {}}}}}}, {"_type": "AugAssign", "_fields": {"op": {"_type": "Add", "_fields": {}}, "value": {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "ufunc_%s_ptr[2*%d+1] = <void*>(<char*>\"%s\")\n"}}, "right": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "name", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Name", "_fields": {"id": "j", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "name", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}, "target": {"_type": "Name", "_fields": {"id": "toplevel", "ctx": {"_type": "Store", "_fields": {}}}}}}], "iter": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "funcs", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "enumerate", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [], "target": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "j", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "func", "ctx": {"_type": "Store", "_fields": {}}}}]}}, "type_comment": null}}, {"_type": "For", "_fields": {"body": [{"_type": "AugAssign", "_fields": {"op": {"_type": "Add", "_fields": {}}, "value": {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "ufunc_%s_data[%d] = &ufunc_%s_ptr[2*%d]\n"}}, "right": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "name", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Name", "_fields": {"id": "j", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "name", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Name", "_fields": {"id": "j", "ctx": {"_type": "Load", "_fields": {}}}}]}}}}, "target": {"_type": "Name", "_fields": {"id": "toplevel", "ctx": {"_type": "Store", "_fields": {}}}}}}], "iter": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "funcs", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "enumerate", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [], "target": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "j", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "func", "ctx": {"_type": "Store", "_fields": {}}}}]}}, "type_comment": null}}, {"_type": "AugAssign", "_fields": {"op": {"_type": "Add", "_fields": {}}, "value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "@"}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "name", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "replace", "value": {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "@ = np.PyUFunc_FromFuncAndData(ufunc_@_loops, ufunc_@_data, ufunc_@_types, %d, %d, %d, 0, \"@\", ufunc_@_doc, 0)\n"}}, "right": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "types", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "right": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "inarg_num", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Name", "_fields": {"id": "outarg_num", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "Name", "_fields": {"id": "inarg_num", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "outarg_num", "ctx": {"_type": "Load", "_fields": {}}}}]}}}}}}, "keywords": []}}, "target": {"_type": "Name", "_fields": {"id": "toplevel", "ctx": {"_type": "Store", "_fields": {}}}}}}, {"_type": "Return", "_fields": {"value": {"_type": "Name", "_fields": {"id": "toplevel", "ctx": {"_type": "Load", "_fields": {}}}}}}], "name": "generate", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def generate(self, all_loops): toplevel = "" variants, inarg_num, outarg_num = self._get_signatures_and_loops(all_loops) loops = [] funcs = [] types = [] for func_name, loop_name, inputs, outputs in variants: for x in inputs: types.append(TYPE_NAMES[x]) for x in outputs: types.append(TYPE_NAMES[x]) loops.append(loop_name) funcs.append(func_name) toplevel += "cdef np.PyUFuncGenericFunction ufunc_%s_loops[%d]\n" % (self.name, len(loops)) toplevel += "cdef void *ufunc_%s_ptr[%d]\n" % (self.name, 2*len(funcs)) toplevel += "cdef void *ufunc_%s_data[%d]\n" % (self.name, len(funcs)) toplevel += "cdef char ufunc_%s_types[%d]\n" % (self.name, len(types)) toplevel += 'cdef char *ufunc_%s_doc = (\n "%s")\n' % ( self.name, self.doc.replace("\\", "\\\\").replace('"', '\\"').replace('\n', '\\n\"\n "') ) for j, function in enumerate(loops): toplevel += "ufunc_%s_loops[%d] = <np.PyUFuncGenericFunction>%s\n" % (self.name, j, function) for j, type in enumerate(types): toplevel += "ufunc_%s_types[%d] = <char>%s\n" % (self.name, j, type) for j, func in enumerate(funcs): toplevel += "ufunc_%s_ptr[2*%d] = <void*>%s\n" % (self.name, j, self.cython_func_name(func, specialized=True)) toplevel += "ufunc_%s_ptr[2*%d+1] = <void*>(<char*>\"%s\")\n" % (self.name, j, self.name) for j, func in enumerate(funcs): toplevel += "ufunc_%s_data[%d] = &ufunc_%s_ptr[2*%d]\n" % ( self.name, j, self.name, j) toplevel += ('@ = np.PyUFunc_FromFuncAndData(ufunc_@_loops, ' 'ufunc_@_data, ufunc_@_types, %d, %d, %d, 0, ' '"@", ufunc_@_doc, 0)\n' % (len(types)/(inarg_num+outarg_num), inarg_num, outarg_num) ).replace('@', self.name) return toplevel
10,963
[ -0.014677038416266441, 0.00616912916302681, -0.034198690205812454, -0.05111904814839363, -0.05517611652612686, -0.029282480478286743, 0.008549672551453114, -0.08028220385313034, 0.019175609573721886, 0.04983033239841461, 0.01786302961409092, -0.034270286560058594, 0.040594540536403656, -0....
10
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "func_name", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "inarg", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "outarg", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "ret", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "inp", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "outp", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "inp", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Name", "_fields": {"id": "seen", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": []}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "inp", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "add", "value": {"_type": "Name", "_fields": {"id": "seen", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "func_name", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "inp", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "outp", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "sig", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Raise", "_fields": {"exc": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "%s: void signature %r"}}, "right": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "name", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Name", "_fields": {"id": "sig", "ctx": {"_type": "Load", "_fields": {}}}}]}}}}], "func": {"_type": "Name", "_fields": {"id": "ValueError", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "cause": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "v"}}, "comparators": [{"_type": "Name", "_fields": {"id": "outp", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": []}}, {"_type": "If", "_fields": {"body": [{"_type": "Raise", "_fields": {"exc": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "%s: signature %r does not have %d/%d input/output args"}}, "right": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "name", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Name", "_fields": {"id": "sig", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "inarg_num", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "outarg_num", "ctx": {"_type": "Load", "_fields": {}}}}]}}}}], "func": {"_type": "Name", "_fields": {"id": "ValueError", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "cause": null}}], "test": {"_type": "BoolOp", "_fields": {"op": {"_type": "Or", "_fields": {}}, "values": [{"_type": "Compare", "_fields": {"ops": [{"_type": "NotEq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "inp", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "Name", "_fields": {"id": "inarg_num", "ctx": {"_type": "Load", "_fields": {}}}}]}}, {"_type": "Compare", "_fields": {"ops": [{"_type": "NotEq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "outp", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "Name", "_fields": {"id": "outarg_num", "ctx": {"_type": "Load", "_fields": {}}}}]}}]}}, "orelse": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "inarg", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "outarg", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "ret", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "inp", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "outp", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "generate_loop", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Tuple", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "loop_name", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "loop", "ctx": {"_type": "Store", "_fields": {}}}}]}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Name", "_fields": {"id": "loop", "ctx": {"_type": "Load", "_fields": {}}}}, "targets": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "slice": {"_type": "Name", "_fields": {"id": "loop_name", "ctx": {"_type": "Load", "_fields": {}}}}, "value": {"_type": "Name", "_fields": {"id": "all_loops", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "func_name", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "loop_name", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "inp", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "outp", "ctx": {"_type": "Load", "_fields": {}}}}]}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "append", "value": {"_type": "Name", "_fields": {"id": "variants", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "name": "add_variant", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def add_variant(func_name, inarg, outarg, ret, inp, outp): if inp in seen: return seen.add(inp) sig = (func_name, inp, outp) if "v" in outp: raise ValueError("%s: void signature %r" % (self.name, sig)) if len(inp) != inarg_num or len(outp) != outarg_num: raise ValueError("%s: signature %r does not have %d/%d input/output args" % ( self.name, sig, inarg_num, outarg_num)) loop_name, loop = generate_loop(inarg, outarg, ret, inp, outp) all_loops[loop_name] = loop variants.append((func_name, loop_name, inp, outp))
10,964
[ 0.02198406122624874, 0.027548082172870636, 0.052079230546951294, -0.04715816304087639, 0.003536243923008442, -0.008506768383085728, 0.0026336361188441515, -0.03615376725792885, 0.04394339397549629, 0.0051127164624631405, 0.039937298744916916, -0.013118723407387733, 0.039244890213012695, -0...
13
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "filename", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "cxx_fn_prefix", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "ufuncs", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "filename", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "splitext", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "path", "value": {"_type": "Name", "_fields": {"id": "os", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": "_defs.h"}}}}, "targets": [{"_type": "Name", "_fields": {"id": "proto_h_filename", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "cxx_fn_prefix", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": "_defs.h"}}}}, "targets": [{"_type": "Name", "_fields": {"id": "cxx_proto_h_filename", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "cxx_fn_prefix", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": ".pyx"}}}}, "targets": [{"_type": "Name", "_fields": {"id": "cxx_pyx_filename", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "cxx_fn_prefix", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": ".pxd"}}}}, "targets": [{"_type": "Name", "_fields": {"id": "cxx_pxd_filename", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": ""}}, "targets": [{"_type": "Name", "_fields": {"id": "toplevel", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}, "targets": [{"_type": "Name", "_fields": {"id": "defs", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}, "targets": [{"_type": "Name", "_fields": {"id": "defs_h", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Dict", "_fields": {"keys": [], "values": []}}, "targets": [{"_type": "Name", "_fields": {"id": "all_loops", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}, "targets": [{"_type": "Name", "_fields": {"id": "cxx_defs", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "cdef int _set_errprint(int flag) nogil"}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "cxx_pxd_defs", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}, "targets": [{"_type": "Name", "_fields": {"id": "cxx_defs_h", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "sort", "value": {"_type": "Name", "_fields": {"id": "ufuncs", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "key", "value": {"_type": "Lambda", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "u", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "name", "value": {"_type": "Name", "_fields": {"id": "u", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}]}}}}, {"_type": "For", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get_prototypes", "value": {"_type": "Name", "_fields": {"id": "ufunc", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "cfuncs", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "For", "_fields": {"body": [{"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Slice", "_fields": {"step": null, "lower": null, "upper": {"_type": "UnaryOp", "_fields": {"op": {"_type": "USub", "_fields": {}}, "operand": {"_type": "Constant", "_fields": {"kind": null, "value": 2}}}}}}, "value": {"_type": "Name", "_fields": {"id": "header", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "header", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "ufunc", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "c_name", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "c_proto", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "cy_proto", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "header", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "cxx_proto_h_filename", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "get_declaration", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Tuple", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "item_defs", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "item_defs_h", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "var_name", "ctx": {"_type": "Store", "_fields": {}}}}]}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "item_defs", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "extend", "value": {"_type": "Name", "_fields": {"id": "cxx_defs", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "item_defs_h", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "extend", "value": {"_type": "Name", "_fields": {"id": "cxx_defs_h", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "cdef void *_export_%s = <void*>%s"}}, "right": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "var_name", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "c_name", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "cython_func_name", "value": {"_type": "Name", "_fields": {"id": "ufunc", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "specialized", "value": {"_type": "Constant", "_fields": {"kind": null, "value": true}}}}, {"_type": "keyword", "_fields": {"arg": "override", "value": {"_type": "Constant", "_fields": {"kind": null, "value": false}}}}]}}]}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "append", "value": {"_type": "Name", "_fields": {"id": "cxx_defs", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "cdef void *_export_%s"}}, "right": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "var_name", "ctx": {"_type": "Load", "_fields": {}}}}]}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "append", "value": {"_type": "Name", "_fields": {"id": "cxx_pxd_defs", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "scipy.special._ufuncs_cxx._export_"}}, "right": {"_type": "Name", "_fields": {"id": "var_name", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "slice": {"_type": "Name", "_fields": {"id": "c_name", "ctx": {"_type": "Load", "_fields": {}}}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "function_name_overrides", "value": {"_type": "Name", "_fields": {"id": "ufunc", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "type_comment": null}}], "test": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "++"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "endswith", "value": {"_type": "Name", "_fields": {"id": "header", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "orelse": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "ufunc", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "c_name", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "c_proto", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "cy_proto", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "header", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "proto_h_filename", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "get_declaration", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Tuple", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "item_defs", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "item_defs_h", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "_", "ctx": {"_type": "Store", "_fields": {}}}}]}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "item_defs", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "extend", "value": {"_type": "Name", "_fields": {"id": "defs", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "item_defs_h", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "extend", "value": {"_type": "Name", "_fields": {"id": "defs_h", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}]}}], "iter": {"_type": "Name", "_fields": {"id": "cfuncs", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": [], "target": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "c_name", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "c_proto", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "cy_proto", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "header", "ctx": {"_type": "Store", "_fields": {}}}}]}}, "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "all_loops", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "generate", "value": {"_type": "Name", "_fields": {"id": "ufunc", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "t", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "AugAssign", "_fields": {"op": {"_type": "Add", "_fields": {}}, "value": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "t", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": "\n"}}}}, "target": {"_type": "Name", "_fields": {"id": "toplevel", "ctx": {"_type": "Store", "_fields": {}}}}}}], "iter": {"_type": "Name", "_fields": {"id": "ufuncs", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "ufunc", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "values", "value": {"_type": "Name", "_fields": {"id": "all_loops", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "list", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "right": {"_type": "Name", "_fields": {"id": "defs", "ctx": {"_type": "Load", "_fields": {}}}}}}, "right": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "toplevel", "ctx": {"_type": "Load", "_fields": {}}}}]}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "join", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "\n"}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "toplevel", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "filename", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": "wb"}}], "func": {"_type": "Name", "_fields": {"id": "open", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "f", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "EXTRA_CODE_COMMON", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "write", "value": {"_type": "Name", "_fields": {"id": "f", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "EXTRA_CODE", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "write", "value": {"_type": "Name", "_fields": {"id": "f", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "toplevel", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "write", "value": {"_type": "Name", "_fields": {"id": "f", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "EXTRA_CODE_BOTTOM", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "write", "value": {"_type": "Name", "_fields": {"id": "f", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "close", "value": {"_type": "Name", "_fields": {"id": "f", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "defs_h", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "unique", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "defs_h", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "proto_h_filename", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": "wb"}}], "func": {"_type": "Name", "_fields": {"id": "open", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "f", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "#ifndef UFUNCS_PROTO_H\n#define UFUNCS_PROTO_H 1\n"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "write", "value": {"_type": "Name", "_fields": {"id": "f", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "defs_h", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "join", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "\n"}}}}, "keywords": []}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "write", "value": {"_type": "Name", "_fields": {"id": "f", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "\n#endif\n"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "write", "value": {"_type": "Name", "_fields": {"id": "f", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "close", "value": {"_type": "Name", "_fields": {"id": "f", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "cxx_defs_h", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "unique", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "cxx_defs_h", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "cxx_proto_h_filename", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": "wb"}}], "func": {"_type": "Name", "_fields": {"id": "open", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "f", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "#ifndef UFUNCS_PROTO_H\n#define UFUNCS_PROTO_H 1\n"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "write", "value": {"_type": "Name", "_fields": {"id": "f", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "cxx_defs_h", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "join", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "\n"}}}}, "keywords": []}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "write", "value": {"_type": "Name", "_fields": {"id": "f", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "\n#endif\n"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "write", "value": {"_type": "Name", "_fields": {"id": "f", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "close", "value": {"_type": "Name", "_fields": {"id": "f", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "cxx_pyx_filename", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": "wb"}}], "func": {"_type": "Name", "_fields": {"id": "open", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "f", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "EXTRA_CODE_COMMON", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "write", "value": {"_type": "Name", "_fields": {"id": "f", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "cxx_defs", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "join", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "\n"}}}}, "keywords": []}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "write", "value": {"_type": "Name", "_fields": {"id": "f", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "\n# distutils: language = c++\n"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "write", "value": {"_type": "Name", "_fields": {"id": "f", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "close", "value": {"_type": "Name", "_fields": {"id": "f", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "cxx_pxd_filename", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": "wb"}}], "func": {"_type": "Name", "_fields": {"id": "open", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "f", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "cxx_pxd_defs", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "join", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "\n"}}}}, "keywords": []}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "write", "value": {"_type": "Name", "_fields": {"id": "f", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "close", "value": {"_type": "Name", "_fields": {"id": "f", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "name": "generate", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def generate(filename, cxx_fn_prefix, ufuncs): proto_h_filename = os.path.splitext(filename)[0] + '_defs.h' cxx_proto_h_filename = cxx_fn_prefix + '_defs.h' cxx_pyx_filename = cxx_fn_prefix + ".pyx" cxx_pxd_filename = cxx_fn_prefix + ".pxd" toplevel = "" # for _ufuncs* defs = [] defs_h = [] all_loops = {} # for _ufuncs_cxx* cxx_defs = [] cxx_pxd_defs = ["cdef int _set_errprint(int flag) nogil"] cxx_defs_h = [] ufuncs.sort(key=lambda u: u.name) for ufunc in ufuncs: # generate function declaration and type checking snippets cfuncs = ufunc.get_prototypes() for c_name, c_proto, cy_proto, header in cfuncs: if header.endswith('++'): header = header[:-2] # for the CXX module item_defs, item_defs_h, var_name = get_declaration(ufunc, c_name, c_proto, cy_proto, header, cxx_proto_h_filename) cxx_defs.extend(item_defs) cxx_defs_h.extend(item_defs_h) cxx_defs.append("cdef void *_export_%s = <void*>%s" % ( var_name, ufunc.cython_func_name(c_name, specialized=True, override=False))) cxx_pxd_defs.append("cdef void *_export_%s" % (var_name,)) # let cython grab the function pointer from the c++ shared library ufunc.function_name_overrides[c_name] = "scipy.special._ufuncs_cxx._export_" + var_name else: # usual case item_defs, item_defs_h, _ = get_declaration(ufunc, c_name, c_proto, cy_proto, header, proto_h_filename) defs.extend(item_defs) defs_h.extend(item_defs_h) # ufunc creation code snippet t = ufunc.generate(all_loops) toplevel += t + "\n" # Produce output toplevel = "\n".join(list(all_loops.values()) + defs + [toplevel]) f = open(filename, 'wb') f.write(EXTRA_CODE_COMMON) f.write(EXTRA_CODE) f.write(toplevel) f.write(EXTRA_CODE_BOTTOM) f.close() defs_h = unique(defs_h) f = open(proto_h_filename, 'wb') f.write("#ifndef UFUNCS_PROTO_H\n#define UFUNCS_PROTO_H 1\n") f.write("\n".join(defs_h)) f.write("\n#endif\n") f.close() cxx_defs_h = unique(cxx_defs_h) f = open(cxx_proto_h_filename, 'wb') f.write("#ifndef UFUNCS_PROTO_H\n#define UFUNCS_PROTO_H 1\n") f.write("\n".join(cxx_defs_h)) f.write("\n#endif\n") f.close() f = open(cxx_pyx_filename, 'wb') f.write(EXTRA_CODE_COMMON) f.write("\n".join(cxx_defs)) f.write("\n# distutils: language = c++\n") f.close() f = open(cxx_pxd_filename, 'wb') f.write("\n".join(cxx_pxd_defs)) f.close()
10,965
[ -0.00933157280087471, -0.0012559493770822883, 0.038769979029893875, -0.03474162518978119, -0.03415949270129204, 0.0014167632907629013, -0.03697701171040535, -0.010070879943668842, 0.04244904965162277, 0.03120226413011551, 0.010856757871806622, -0.05183301493525505, 0.00933157280087471, 0.0...
9
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "OptionParser", "value": {"_type": "Name", "_fields": {"id": "optparse", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "usage", "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "strip", "value": {"_type": "Name", "_fields": {"id": "__doc__", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "p", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "parse_args", "value": {"_type": "Name", "_fields": {"id": "p", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Tuple", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "options", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "args", "ctx": {"_type": "Store", "_fields": {}}}}]}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "invalid number of arguments"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "error", "value": {"_type": "Name", "_fields": {"id": "p", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "NotEq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "args", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 0}}]}}, "orelse": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "UFUNCS", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "parse_all", "value": {"_type": "Name", "_fields": {"id": "Ufunc", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "ufuncs", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "_ufuncs.pyx"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "_ufuncs_cxx"}}, {"_type": "Name", "_fields": {"id": "ufuncs", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "generate", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "name": "main", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def main(): p = optparse.OptionParser(usage=__doc__.strip()) options, args = p.parse_args() if len(args) != 0: p.error('invalid number of arguments') ufuncs = Ufunc.parse_all(UFUNCS) generate("_ufuncs.pyx", "_ufuncs_cxx", ufuncs)
10,966
[ -0.030717162415385246, 0.030507666990160942, 0.05294978991150856, -0.04082528129220009, -0.022036224603652954, -0.023830024525523186, -0.011116312816739082, -0.02956494130194187, -0.022494494915008545, 0.02676294930279255, 0.0094861825928092, -0.020281707867980003, -0.021028032526373863, -...
14
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "fname", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "NUCROPS"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "NOUT"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "NPRE"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "NBEGYR"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "NENDYR"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "APDEP"}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "site_names", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "ListComp", "_fields": {"elt": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "lower", "value": {"_type": "Name", "_fields": {"id": "item", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "generators": [{"_type": "comprehension", "_fields": {"ifs": [], "iter": {"_type": "Name", "_fields": {"id": "site_names", "ctx": {"_type": "Load", "_fields": {}}}}, "target": {"_type": "Name", "_fields": {"id": "item", "ctx": {"_type": "Store", "_fields": {}}}}, "is_async": 0}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "site_names", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "With", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "lower", "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "strip", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "f", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}], "func": {"_type": "Name", "_fields": {"id": "islice", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "list", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}}}, "keywords": []}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "site_name", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "upper", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "value": {"_type": "Name", "_fields": {"id": "site_name", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, "right": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Slice", "_fields": {"step": null, "lower": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, "upper": null}}, "value": {"_type": "Name", "_fields": {"id": "site_name", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "site_name", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Try", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": " "}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "index", "value": {"_type": "Name", "_fields": {"id": "site_name", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}}}, "targets": [{"_type": "Name", "_fields": {"id": "idx", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Slice", "_fields": {"step": null, "lower": null, "upper": {"_type": "Name", "_fields": {"id": "idx", "ctx": {"_type": "Load", "_fields": {}}}}}}, "value": {"_type": "Name", "_fields": {"id": "site_name", "ctx": {"_type": "Load", "_fields": {}}}}}}, "right": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "upper", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Name", "_fields": {"id": "idx", "ctx": {"_type": "Load", "_fields": {}}}}, "value": {"_type": "Name", "_fields": {"id": "site_name", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}}}, "right": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Slice", "_fields": {"step": null, "lower": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "idx", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}}}, "upper": null}}, "value": {"_type": "Name", "_fields": {"id": "site_name", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "site_name", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "orelse": [], "handlers": [{"_type": "ExceptHandler", "_fields": {"body": [{"_type": "Pass", "_fields": {}}], "name": null, "type": null}}], "finalbody": []}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "f", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": 2}}], "func": {"_type": "Name", "_fields": {"id": "islice", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "list", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "ListComp", "_fields": {"elt": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "item", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "float", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "generators": [{"_type": "comprehension", "_fields": {"ifs": [], "iter": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "split", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "f", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}], "func": {"_type": "Name", "_fields": {"id": "islice", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "list", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}}}, "keywords": []}}, "target": {"_type": "Name", "_fields": {"id": "item", "ctx": {"_type": "Store", "_fields": {}}}}, "is_async": 0}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "site_vals", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "ListComp", "_fields": {"elt": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "item", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "int", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "generators": [{"_type": "comprehension", "_fields": {"ifs": [], "iter": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Slice", "_fields": {"step": null, "lower": null, "upper": {"_type": "UnaryOp", "_fields": {"op": {"_type": "USub", "_fields": {}}, "operand": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}}}}}, "value": {"_type": "Name", "_fields": {"id": "site_vals", "ctx": {"_type": "Load", "_fields": {}}}}}}, "target": {"_type": "Name", "_fields": {"id": "item", "ctx": {"_type": "Store", "_fields": {}}}}, "is_async": 0}}]}}, "targets": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "slice": {"_type": "Slice", "_fields": {"step": null, "lower": null, "upper": {"_type": "UnaryOp", "_fields": {"op": {"_type": "USub", "_fields": {}}, "operand": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}}}}}, "value": {"_type": "Name", "_fields": {"id": "site_vals", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "site_names", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "site_vals", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "zip", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "dict", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "site_params", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Name", "_fields": {"id": "site_name", "ctx": {"_type": "Load", "_fields": {}}}}, "targets": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "site_name"}}, "value": {"_type": "Name", "_fields": {"id": "site_params", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Sub", "_fields": {}}, "left": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "nendyr"}}, "value": {"_type": "Name", "_fields": {"id": "site_params", "ctx": {"_type": "Load", "_fields": {}}}}}}, "right": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "nbegyr"}}, "value": {"_type": "Name", "_fields": {"id": "site_params", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}}}], "func": {"_type": "Name", "_fields": {"id": "int", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "numyrs"}}, "value": {"_type": "Name", "_fields": {"id": "site_params", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "OrderedDict", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "crop_params", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "split", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "f", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}], "func": {"_type": "Name", "_fields": {"id": "islice", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "list", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "line", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "While", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "value": {"_type": "Name", "_fields": {"id": "line", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "cname", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "split", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "f", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}], "func": {"_type": "Name", "_fields": {"id": "islice", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "list", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "sline", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "value": {"_type": "Name", "_fields": {"id": "sline", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "int", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "param_vals", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "ListComp", "_fields": {"elt": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "item", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "int", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "append", "value": {"_type": "Name", "_fields": {"id": "param_vals", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "generators": [{"_type": "comprehension", "_fields": {"ifs": [], "iter": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Slice", "_fields": {"step": null, "lower": {"_type": "Constant", "_fields": {"kind": null, "value": 2}}, "upper": null}}, "value": {"_type": "Name", "_fields": {"id": "sline", "ctx": {"_type": "Load", "_fields": {}}}}}}, "target": {"_type": "Name", "_fields": {"id": "item", "ctx": {"_type": "Store", "_fields": {}}}}, "is_async": 0}}]}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "NCROP"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "NBTEMP"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "NETEMP"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "MBEGMO"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "MBEGDA"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "MENDMO"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "MENDDA"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "NGROWS"}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "param_names", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "ListComp", "_fields": {"elt": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "lower", "value": {"_type": "Name", "_fields": {"id": "item", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "generators": [{"_type": "comprehension", "_fields": {"ifs": [], "iter": {"_type": "Name", "_fields": {"id": "param_names", "ctx": {"_type": "Load", "_fields": {}}}}, "target": {"_type": "Name", "_fields": {"id": "item", "ctx": {"_type": "Store", "_fields": {}}}}, "is_async": 0}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "param_names", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "param_names", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "param_vals", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "zip", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "dict", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "slice": {"_type": "Name", "_fields": {"id": "cname", "ctx": {"_type": "Load", "_fields": {}}}}, "value": {"_type": "Name", "_fields": {"id": "crop_params", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "split", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "f", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}], "func": {"_type": "Name", "_fields": {"id": "islice", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "list", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "line", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "line", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}]}}, "orelse": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "ListComp", "_fields": {"elt": {"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "item", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "float", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 100.0}}}}, "generators": [{"_type": "comprehension", "_fields": {"ifs": [], "iter": {"_type": "Name", "_fields": {"id": "line", "ctx": {"_type": "Load", "_fields": {}}}}, "target": {"_type": "Name", "_fields": {"id": "item", "ctx": {"_type": "Store", "_fields": {}}}}, "is_async": 0}}]}}, "targets": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "pclite"}}, "value": {"_type": "Name", "_fields": {"id": "site_params", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "ListComp", "_fields": {"elt": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "item", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "int", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "generators": [{"_type": "comprehension", "_fields": {"ifs": [], "iter": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "split", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "f", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}], "func": {"_type": "Name", "_fields": {"id": "islice", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "list", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}}}, "keywords": []}}, "target": {"_type": "Name", "_fields": {"id": "item", "ctx": {"_type": "Store", "_fields": {}}}}, "is_async": 0}}]}}, "targets": [{"_type": "Tuple", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "elts": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "nts"}}, "value": {"_type": "Name", "_fields": {"id": "site_params", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Subscript", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "nps"}}, "value": {"_type": "Name", "_fields": {"id": "site_params", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "split", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "f", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}], "func": {"_type": "Name", "_fields": {"id": "islice", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "list", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}}}, "keywords": []}}}}], "func": {"_type": "Name", "_fields": {"id": "float", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 100.0}}}}, "targets": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "wts"}}, "value": {"_type": "Name", "_fields": {"id": "site_params", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "split", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "f", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}], "func": {"_type": "Name", "_fields": {"id": "islice", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "list", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}}}, "keywords": []}}}}], "func": {"_type": "Name", "_fields": {"id": "float", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 100.0}}}}, "targets": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "wps"}}, "value": {"_type": "Name", "_fields": {"id": "site_params", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Sub", "_fields": {}}, "left": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "nendyr"}}, "value": {"_type": "Name", "_fields": {"id": "site_params", "ctx": {"_type": "Load", "_fields": {}}}}}}, "right": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "nbegyr"}}, "value": {"_type": "Name", "_fields": {"id": "site_params", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}}}, "targets": [{"_type": "Name", "_fields": {"id": "nyrs", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "f", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "nyrs", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "islice", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "list", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "lines", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "OrderedDict", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "temp", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "For", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "split", "value": {"_type": "Name", "_fields": {"id": "line", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "sline", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "value": {"_type": "Name", "_fields": {"id": "sline", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "yr", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "ListComp", "_fields": {"elt": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "item", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "float", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "generators": [{"_type": "comprehension", "_fields": {"ifs": [], "iter": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Slice", "_fields": {"step": null, "lower": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, "upper": null}}, "value": {"_type": "Name", "_fields": {"id": "sline", "ctx": {"_type": "Load", "_fields": {}}}}}}, "target": {"_type": "Name", "_fields": {"id": "item", "ctx": {"_type": "Store", "_fields": {}}}}, "is_async": 0}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "data", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Name", "_fields": {"id": "data", "ctx": {"_type": "Load", "_fields": {}}}}, "targets": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "slice": {"_type": "Name", "_fields": {"id": "yr", "ctx": {"_type": "Load", "_fields": {}}}}, "value": {"_type": "Name", "_fields": {"id": "temp", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "iter": {"_type": "Name", "_fields": {"id": "lines", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "line", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "temp", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "DataFrame", "value": {"_type": "Name", "_fields": {"id": "pd", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "temperature"}}, "value": {"_type": "Name", "_fields": {"id": "site_params", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "OrderedDict", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "precip", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "For", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "ListComp", "_fields": {"elt": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "item", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "float", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "generators": [{"_type": "comprehension", "_fields": {"ifs": [], "iter": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "split", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "f", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}], "func": {"_type": "Name", "_fields": {"id": "islice", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "list", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}}}, "keywords": []}}, "target": {"_type": "Name", "_fields": {"id": "item", "ctx": {"_type": "Store", "_fields": {}}}}, "is_async": 0}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "data", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Name", "_fields": {"id": "data", "ctx": {"_type": "Load", "_fields": {}}}}, "targets": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "slice": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Name", "_fields": {"id": "yr", "ctx": {"_type": "Load", "_fields": {}}}}, "value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "keys", "value": {"_type": "Name", "_fields": {"id": "temp", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "list", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "value": {"_type": "Name", "_fields": {"id": "precip", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "iter": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "nyrs", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "range", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "yr", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "precip", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "DataFrame", "value": {"_type": "Name", "_fields": {"id": "pd", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "precip"}}, "value": {"_type": "Name", "_fields": {"id": "site_params", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "nyrs", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "nucrops"}}, "value": {"_type": "Name", "_fields": {"id": "site_params", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "zeros", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "pccrop", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "nyrs", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "zeros", "value": {"_type": "Name", "_fields": {"id": "np", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "areat", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "For", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "ListComp", "_fields": {"elt": {"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "item", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "float", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 10.0}}}}, "generators": [{"_type": "comprehension", "_fields": {"ifs": [], "iter": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "split", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "f", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}], "func": {"_type": "Name", "_fields": {"id": "islice", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "list", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}}}, "keywords": []}}, "target": {"_type": "Name", "_fields": {"id": "item", "ctx": {"_type": "Store", "_fields": {}}}}, "is_async": 0}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "data", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Name", "_fields": {"id": "data", "ctx": {"_type": "Load", "_fields": {}}}}, "targets": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "slice": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "yr", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Slice", "_fields": {"step": null, "lower": null, "upper": null}}]}}, "value": {"_type": "Name", "_fields": {"id": "pccrop", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "ListComp", "_fields": {"elt": {"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "item", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "float", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": 10.0}}}}, "generators": [{"_type": "comprehension", "_fields": {"ifs": [], "iter": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "split", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "f", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}], "func": {"_type": "Name", "_fields": {"id": "islice", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "list", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}}}, "keywords": []}}, "target": {"_type": "Name", "_fields": {"id": "item", "ctx": {"_type": "Store", "_fields": {}}}}, "is_async": 0}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "data", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "value": {"_type": "Name", "_fields": {"id": "data", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "slice": {"_type": "Name", "_fields": {"id": "yr", "ctx": {"_type": "Load", "_fields": {}}}}, "value": {"_type": "Name", "_fields": {"id": "areat", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "iter": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "nyrs", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "range", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "yr", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Name", "_fields": {"id": "areat", "ctx": {"_type": "Load", "_fields": {}}}}, "targets": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "areat"}}, "value": {"_type": "Name", "_fields": {"id": "site_params", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Name", "_fields": {"id": "pccrop", "ctx": {"_type": "Load", "_fields": {}}}}, "targets": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "pccrop"}}, "value": {"_type": "Name", "_fields": {"id": "site_params", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "f", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}], "func": {"_type": "Name", "_fields": {"id": "islice", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "list", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "targets": [{"_type": "Name", "_fields": {"id": "line", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "strip", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Slice", "_fields": {"step": null, "lower": null, "upper": {"_type": "Constant", "_fields": {"kind": null, "value": 8}}}}, "value": {"_type": "Name", "_fields": {"id": "line", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, "targets": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "ibasin"}}, "value": {"_type": "Name", "_fields": {"id": "site_params", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "strip", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Slice", "_fields": {"step": null, "lower": {"_type": "Constant", "_fields": {"kind": null, "value": 8}}, "upper": {"_type": "Constant", "_fields": {"kind": null, "value": 23}}}}, "value": {"_type": "Name", "_fields": {"id": "line", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, "targets": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "cname2"}}, "value": {"_type": "Name", "_fields": {"id": "site_params", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "strip", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Slice", "_fields": {"step": null, "lower": {"_type": "Constant", "_fields": {"kind": null, "value": 23}}, "upper": {"_type": "Constant", "_fields": {"kind": null, "value": 34}}}}, "value": {"_type": "Name", "_fields": {"id": "line", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, "targets": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "st"}}, "value": {"_type": "Name", "_fields": {"id": "site_params", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "items": [{"_type": "withitem", "_fields": {"context_expr": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "fname", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": "r"}}], "func": {"_type": "Name", "_fields": {"id": "open", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "optional_vars": {"_type": "Name", "_fields": {"id": "f", "ctx": {"_type": "Store", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Return", "_fields": {"value": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "site_params", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "crop_params", "ctx": {"_type": "Load", "_fields": {}}}}]}}}}], "name": "get_data", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def get_data(fname): site_names = ['NUCROPS', 'NOUT', 'NPRE', 'NBEGYR', 'NENDYR', 'APDEP'] site_names = [item.lower() for item in site_names] with open(fname, 'r') as f: site_name = list(islice(f, 1))[0].strip().lower() site_name = site_name[0].upper() + site_name[1:] try: idx = site_name.index(' ') + 1 site_name = site_name[:idx] + site_name[idx].upper() + site_name[idx+1:] except: pass list(islice(f, 2)) site_vals = [float(item) for item in list(islice(f, 1))[0].split()] site_vals[:-1] = [int(item) for item in site_vals[:-1]] site_params = dict(zip(site_names, site_vals)) site_params['site_name'] = site_name site_params['numyrs'] = int(site_params['nendyr'] \ - site_params['nbegyr'] + 1) crop_params = OrderedDict() line = list(islice(f, 1))[0].split() while len(line) == 1: cname = line[0] sline = list(islice(f, 1))[0].split() param_vals = [int(sline[0])] [param_vals.append(int(item)) for item in sline[2:]] # param_vals[0] -= 1 param_names = ['NCROP', 'NBTEMP', 'NETEMP', 'MBEGMO', 'MBEGDA', 'MENDMO', 'MENDDA', 'NGROWS'] param_names = [item.lower() for item in param_names] crop_params[cname] = dict(zip(param_names, param_vals)) line = list(islice(f, 1))[0].split() site_params['pclite'] = [float(item) / 100.0 for item in line] site_params['nts'], site_params['nps'] = [int(item) for item in \ list(islice(f, 1))[0].split()] site_params['wts'] = float(list(islice(f, 1))[0].split()[0]) / 100.0 site_params['wps'] = float(list(islice(f, 1))[0].split()[0]) / 100.0 nyrs = site_params['nendyr'] - site_params['nbegyr'] + 1 lines = list(islice(f, nyrs)) temp = OrderedDict() for line in lines: sline = line.split() yr = sline[0] data = [float(item) for item in sline[1:]] temp[yr] = data site_params['temperature'] = pd.DataFrame(temp) precip = OrderedDict() for yr in range(nyrs): data = [float(item) for item in list(islice(f, 1))[0].split()] precip[list(temp.keys())[yr]] = data site_params['precip'] = pd.DataFrame(precip) # pccrop = OrderedDict() # areat = OrderedDict() # for yr in range(nyrs): # data = [float(item) / 10.0 for item in list(islice(f, 1))[0].split()] # pccrop[list(temp.keys())[yr]] = data # data = [float(item) / 10.0 for item in list(islice(f, 1))[0].split()] # areat[list(temp.keys())[yr]] = data pccrop = np.zeros((nyrs, site_params['nucrops'])) areat = np.zeros((nyrs)) for yr in range(nyrs): data = [float(item) / 10.0 for item in \ list(islice(f,1))[0].split()] pccrop[yr, :] = data data = [float(item) / 10.0 for item in \ list(islice(f,1))[0].split()] areat[yr] = data[0] site_params['areat'] = areat site_params['pccrop'] = pccrop line = list(islice(f, 1))[0] site_params['ibasin'] = line[:8].strip() site_params['cname2'] = line[8:23].strip() site_params['st'] = line[23:34].strip() return site_params, crop_params
10,967
[ -0.007304976228624582, 0.05083788186311722, 0.06561412662267685, -0.02367287315428257, -0.015655217692255974, -0.013980417512357235, -0.0043057785369455814, -0.034351203590631485, -0.050220225006341934, -0.0008017656509764493, 0.0009658306953497231, -0.0020459871739149094, -0.053593579679727...
6
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "noga.i"}}, "targets": [{"_type": "Name", "_fields": {"id": "fname", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "fname", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "get_data", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Tuple", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "site_params", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "crop_params", "ctx": {"_type": "Store", "_fields": {}}}}]}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "crop_params", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "site_params", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "name": "main", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def main(): fname = 'noga.i' site_params, crop_params = get_data(fname) print(crop_params) print(site_params)
10,968
[ 0.011997964233160019, 0.027220945805311203, 0.007831377908587456, -0.051961109042167664, -0.020511558279395103, -0.030197883024811745, 0.034888818860054016, 0.004662742838263512, -0.06310207396745682, -0.02097388543188572, 0.009985147975385189, 0.015132770873606205, -0.00513070821762085, -...
15
{"_type": "Module", "_fields": {"body": [{"_type": "ClassDef", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "po/update-mo.sh"}}], "func": {"_type": "Name", "_fields": {"id": "check_call", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "For", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "langdir", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "basename", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "path", "value": {"_type": "Name", "_fields": {"id": "os", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "lang", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "langdir", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": "LC_MESSAGES"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "live-magic.mo"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "join", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "path", "value": {"_type": "Name", "_fields": {"id": "os", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "src", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "share"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "locale"}}, {"_type": "Name", "_fields": {"id": "lang", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": "LC_MESSAGES"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "join", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "path", "value": {"_type": "Name", "_fields": {"id": "os", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "dst", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "dst", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "src", "ctx": {"_type": "Load", "_fields": {}}}}]}}]}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "append", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "data_files", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}}}], "iter": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "mo/*"}}], "func": {"_type": "Name", "_fields": {"id": "glob", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "langdir", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}, {"_type": "Try", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "misc/translator-credits.txt"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "w"}}], "func": {"_type": "Name", "_fields": {"id": "file", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "credits", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "For", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "po", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "file", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "f", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Try", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "."}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "split", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "po", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "basename", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "path", "value": {"_type": "Name", "_fields": {"id": "os", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}}}, "keywords": []}}}}, "targets": [{"_type": "Name", "_fields": {"id": "lang", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "For", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "\"Last-Translator: ([^\\\\]*)"}}, {"_type": "Name", "_fields": {"id": "line", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "match", "value": {"_type": "Name", "_fields": {"id": "re", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "m", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "BinOp", "_fields": {"op": {"_type": "RShift", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Name", "_fields": {"id": "credits", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "group", "value": {"_type": "Name", "_fields": {"id": "m", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "(%s)"}}, "right": {"_type": "Name", "_fields": {"id": "lang", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}, {"_type": "Break", "_fields": {}}], "test": {"_type": "Name", "_fields": {"id": "m", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": []}}], "iter": {"_type": "Name", "_fields": {"id": "f", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "line", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}], "orelse": [], "handlers": [], "finalbody": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "close", "value": {"_type": "Name", "_fields": {"id": "f", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}]}}], "iter": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "po/*.po"}}], "func": {"_type": "Name", "_fields": {"id": "glob", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "po", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}], "orelse": [], "handlers": [], "finalbody": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "close", "value": {"_type": "Name", "_fields": {"id": "credits", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}]}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "run", "value": {"_type": "Name", "_fields": {"id": "install_data", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "name": "run", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "name": "my_install", "bases": [{"_type": "Name", "_fields": {"id": "install_data", "ctx": {"_type": "Load", "_fields": {}}}}], "keywords": [], "type_params": [], "decorator_list": []}}], "type_ignores": []}}
class my_install(install_data): def run(self): # Generating and installing .mo files check_call('po/update-mo.sh') for langdir in glob('mo/*'): lang = os.path.basename(langdir) src = os.path.join(langdir, 'LC_MESSAGES', 'live-magic.mo') dst = os.path.join('share', 'locale', lang, 'LC_MESSAGES') self.data_files.append((dst, [src])) try: credits = file('misc/translator-credits.txt', 'w') for po in glob('po/*.po'): f = file(po) try: lang = os.path.basename(po).split('.')[0] for line in f: m = re.match(r'"Last-Translator: ([^\\]*)', line) if m: print >>credits, m.group(1), '(%s)' % lang break finally: f.close() finally: credits.close() install_data.run(self)
10,969
[ 0.013339090161025524, 0.030597839504480362, 0.023493457585573196, -0.0533563606441021, -0.024951081722974777, -0.03209220990538597, 0.0407644547522068, -0.004434114322066307, -0.05913785845041275, -0.02241555042564869, -0.00036325748078525066, 0.02582075446844101, -0.012353051453828812, -0...
14
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "po/update-mo.sh"}}], "func": {"_type": "Name", "_fields": {"id": "check_call", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "For", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "langdir", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "basename", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "path", "value": {"_type": "Name", "_fields": {"id": "os", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "lang", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "langdir", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": "LC_MESSAGES"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "live-magic.mo"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "join", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "path", "value": {"_type": "Name", "_fields": {"id": "os", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "src", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "share"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "locale"}}, {"_type": "Name", "_fields": {"id": "lang", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": "LC_MESSAGES"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "join", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "path", "value": {"_type": "Name", "_fields": {"id": "os", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "dst", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "dst", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "src", "ctx": {"_type": "Load", "_fields": {}}}}]}}]}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "append", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "data_files", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}}}], "iter": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "mo/*"}}], "func": {"_type": "Name", "_fields": {"id": "glob", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "langdir", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}, {"_type": "Try", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "misc/translator-credits.txt"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "w"}}], "func": {"_type": "Name", "_fields": {"id": "file", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "credits", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "For", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "po", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "file", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "f", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Try", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "."}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "split", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "po", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "basename", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "path", "value": {"_type": "Name", "_fields": {"id": "os", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}}}, "keywords": []}}}}, "targets": [{"_type": "Name", "_fields": {"id": "lang", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "For", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "\"Last-Translator: ([^\\\\]*)"}}, {"_type": "Name", "_fields": {"id": "line", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "match", "value": {"_type": "Name", "_fields": {"id": "re", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "m", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "BinOp", "_fields": {"op": {"_type": "RShift", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "print", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Name", "_fields": {"id": "credits", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "group", "value": {"_type": "Name", "_fields": {"id": "m", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "(%s)"}}, "right": {"_type": "Name", "_fields": {"id": "lang", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}, {"_type": "Break", "_fields": {}}], "test": {"_type": "Name", "_fields": {"id": "m", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": []}}], "iter": {"_type": "Name", "_fields": {"id": "f", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "line", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}], "orelse": [], "handlers": [], "finalbody": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "close", "value": {"_type": "Name", "_fields": {"id": "f", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}]}}], "iter": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "po/*.po"}}], "func": {"_type": "Name", "_fields": {"id": "glob", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "po", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}], "orelse": [], "handlers": [], "finalbody": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "close", "value": {"_type": "Name", "_fields": {"id": "credits", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}]}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "run", "value": {"_type": "Name", "_fields": {"id": "install_data", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "name": "run", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def run(self): # Generating and installing .mo files check_call('po/update-mo.sh') for langdir in glob('mo/*'): lang = os.path.basename(langdir) src = os.path.join(langdir, 'LC_MESSAGES', 'live-magic.mo') dst = os.path.join('share', 'locale', lang, 'LC_MESSAGES') self.data_files.append((dst, [src])) try: credits = file('misc/translator-credits.txt', 'w') for po in glob('po/*.po'): f = file(po) try: lang = os.path.basename(po).split('.')[0] for line in f: m = re.match(r'"Last-Translator: ([^\\]*)', line) if m: print >>credits, m.group(1), '(%s)' % lang break finally: f.close() finally: credits.close() install_data.run(self)
10,970
[ 0.0017155276145786047, 0.046071745455265045, 0.05136682838201523, -0.0644913911819458, -0.030503295361995697, -0.009843423031270504, -0.004811397287994623, -0.04279060289263725, -0.030752209946513176, 0.05525893718004227, 0.010776850394904613, -0.012581477873027325, 0.012581477873027325, 0...
13
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "filename", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "lines", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "options", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "report", "annotation": null, "type_comment": null}}], "kwarg": {"_type": "arg", "_fields": {"arg": "kwargs", "annotation": null, "type_comment": null}}, "vararg": null, "defaults": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}, {"_type": "Constant", "_fields": {"kind": null, "value": null}}, {"_type": "Constant", "_fields": {"kind": null, "value": null}}, {"_type": "Constant", "_fields": {"kind": null, "value": null}}], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "options", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "kwargs", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "StyleGuide", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "targets": [{"_type": "Name", "_fields": {"id": "options", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Is", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "options", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}]}}, "orelse": [{"_type": "Assert", "_fields": {"msg": null, "test": {"_type": "UnaryOp", "_fields": {"op": {"_type": "Not", "_fields": {}}, "operand": {"_type": "Name", "_fields": {"id": "kwargs", "ctx": {"_type": "Load", "_fields": {}}}}}}}}]}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "_io_error", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "physical_checks", "value": {"_type": "Name", "_fields": {"id": "options", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "_physical_checks", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "logical_checks", "value": {"_type": "Name", "_fields": {"id": "options", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "_logical_checks", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "ast_checks", "value": {"_type": "Name", "_fields": {"id": "options", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "_ast_checks", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "max_line_length", "value": {"_type": "Name", "_fields": {"id": "options", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "max_line_length", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": false}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "multiline", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "hang_closing", "value": {"_type": "Name", "_fields": {"id": "options", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "hang_closing", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "verbose", "value": {"_type": "Name", "_fields": {"id": "options", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "verbose", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Name", "_fields": {"id": "filename", "ctx": {"_type": "Load", "_fields": {}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "filename", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "stdin"}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "filename", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "BoolOp", "_fields": {"op": {"_type": "Or", "_fields": {}}, "values": [{"_type": "Name", "_fields": {"id": "lines", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}]}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "lines", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Is", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "filename", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}]}}, "orelse": [{"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "stdin"}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "filename", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": true}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "splitlines", "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "stdin_get_value", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "keywords": []}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "lines", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "filename", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": "-"}}]}}, "orelse": [{"_type": "If", "_fields": {"body": [{"_type": "Try", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "filename", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "readlines", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "lines", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "orelse": [], "handlers": [{"_type": "ExceptHandler", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Slice", "_fields": {"step": null, "lower": null, "upper": {"_type": "Constant", "_fields": {"kind": null, "value": 2}}}}, "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "exc_info", "value": {"_type": "Name", "_fields": {"id": "sys", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, "targets": [{"_type": "Tuple", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "exc_type", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "exc", "ctx": {"_type": "Store", "_fields": {}}}}]}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "%s: %s"}}, "right": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "__name__", "value": {"_type": "Name", "_fields": {"id": "exc_type", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Name", "_fields": {"id": "exc", "ctx": {"_type": "Load", "_fields": {}}}}]}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "_io_error", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "lines", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "name": null, "type": {"_type": "Name", "_fields": {"id": "IOError", "ctx": {"_type": "Load", "_fields": {}}}}}}], "finalbody": []}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Is", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "lines", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}]}}, "orelse": [{"_type": "Assign", "_fields": {"value": {"_type": "Name", "_fields": {"id": "lines", "ctx": {"_type": "Load", "_fields": {}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "lines", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}]}}]}}]}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "lines", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}], "func": {"_type": "Name", "_fields": {"id": "ord", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "ord0", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Slice", "_fields": {"step": null, "lower": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, "upper": null}}, "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "lines", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "targets": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "lines", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "type_comment": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "ord0", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 65279}}]}}, "orelse": [{"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Slice", "_fields": {"step": null, "lower": {"_type": "Constant", "_fields": {"kind": null, "value": 3}}, "upper": null}}, "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "lines", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "targets": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "lines", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "type_comment": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Slice", "_fields": {"step": null, "lower": null, "upper": {"_type": "Constant", "_fields": {"kind": null, "value": 3}}}}, "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "lines", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": ""}}]}}, "orelse": []}}]}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "ord0", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 239}}, {"_type": "Constant", "_fields": {"kind": null, "value": 65279}}]}}]}}, "orelse": []}}], "test": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "lines", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "orelse": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "BoolOp", "_fields": {"op": {"_type": "Or", "_fields": {}}, "values": [{"_type": "Name", "_fields": {"id": "report", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "report", "value": {"_type": "Name", "_fields": {"id": "options", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "report", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "error", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "report", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "report_error", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "name": "__init__", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def __init__(self, filename=None, lines=None, options=None, report=None, **kwargs): if options is None: options = StyleGuide(kwargs).options else: assert not kwargs self._io_error = None self._physical_checks = options.physical_checks self._logical_checks = options.logical_checks self._ast_checks = options.ast_checks self.max_line_length = options.max_line_length self.multiline = False # in a multiline string? self.hang_closing = options.hang_closing self.verbose = options.verbose self.filename = filename if filename is None: self.filename = 'stdin' self.lines = lines or [] elif filename == '-': self.filename = 'stdin' self.lines = stdin_get_value().splitlines(True) elif lines is None: try: self.lines = readlines(filename) except IOError: (exc_type, exc) = sys.exc_info()[:2] self._io_error = '%s: %s' % (exc_type.__name__, exc) self.lines = [] else: self.lines = lines if self.lines: ord0 = ord(self.lines[0][0]) if ord0 in (0xef, 0xfeff): # Strip the UTF-8 BOM if ord0 == 0xfeff: self.lines[0] = self.lines[0][1:] elif self.lines[0][:3] == '\xef\xbb\xbf': self.lines[0] = self.lines[0][3:] self.report = report or options.report self.report_error = self.report.error
10,971
[ 0.009098393842577934, 0.020830677822232246, 0.045639511197805405, -0.03346460312604904, -0.013617536053061485, -0.014163986779749393, 0.01486344262957573, -0.024393532425165176, -0.026797913014888763, 0.07549754530191422, 0.021169476211071014, -0.020000074058771133, 0.00850822776556015, -0...
9
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": {"_type": "arg", "_fields": {"arg": "kwargs", "annotation": null, "type_comment": null}}, "vararg": {"_type": "arg", "_fields": {"arg": "args", "annotation": null, "type_comment": null}}, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "checker_class"}}, {"_type": "Name", "_fields": {"id": "Checker", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "pop", "value": {"_type": "Name", "_fields": {"id": "kwargs", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "checker_class", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "parse_argv"}}, {"_type": "Constant", "_fields": {"kind": null, "value": false}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "pop", "value": {"_type": "Name", "_fields": {"id": "kwargs", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "parse_argv", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "config_file"}}, {"_type": "Constant", "_fields": {"kind": null, "value": null}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "pop", "value": {"_type": "Name", "_fields": {"id": "kwargs", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "config_file", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "parser"}}, {"_type": "Constant", "_fields": {"kind": null, "value": null}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "pop", "value": {"_type": "Name", "_fields": {"id": "kwargs", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "parser", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Starred", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "value": {"_type": "Name", "_fields": {"id": "args", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "dict", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": null, "value": {"_type": "Name", "_fields": {"id": "kwargs", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "options_dict", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "IfExp", "_fields": {"body": {"_type": "Constant", "_fields": {"kind": null, "value": null}}, "test": {"_type": "Name", "_fields": {"id": "parse_argv", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "paths"}}, {"_type": "Constant", "_fields": {"kind": null, "value": null}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Name", "_fields": {"id": "options_dict", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, "targets": [{"_type": "Name", "_fields": {"id": "arglist", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "arglist", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "parse_argv", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "config_file", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "parser", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "process_options", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Tuple", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "options", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "paths", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "options_dict", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "update", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "__dict__", "value": {"_type": "Name", "_fields": {"id": "options", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "paths"}}, "value": {"_type": "Name", "_fields": {"id": "options_dict", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "paths", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "In", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "paths"}}, "comparators": [{"_type": "Name", "_fields": {"id": "options_dict", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": []}}], "test": {"_type": "Name", "_fields": {"id": "options_dict", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "input_file", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "runner", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Name", "_fields": {"id": "options", "ctx": {"_type": "Load", "_fields": {}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "options", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "IfExp", "_fields": {"body": {"_type": "Name", "_fields": {"id": "BaseReport", "ctx": {"_type": "Load", "_fields": {}}}}, "test": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "quiet", "value": {"_type": "Name", "_fields": {"id": "options", "ctx": {"_type": "Load", "_fields": {}}}}}}, "orelse": {"_type": "Name", "_fields": {"id": "StandardReport", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "reporter", "value": {"_type": "Name", "_fields": {"id": "options", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "test": {"_type": "UnaryOp", "_fields": {"op": {"_type": "Not", "_fields": {}}, "operand": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "reporter", "value": {"_type": "Name", "_fields": {"id": "options", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "orelse": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "BoolOp", "_fields": {"op": {"_type": "Or", "_fields": {}}, "values": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "select", "value": {"_type": "Name", "_fields": {"id": "options", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}]}}], "func": {"_type": "Name", "_fields": {"id": "tuple", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "select", "value": {"_type": "Name", "_fields": {"id": "options", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": ","}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "split", "value": {"_type": "Name", "_fields": {"id": "DEFAULT_IGNORE", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "tuple", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "ignore", "value": {"_type": "Name", "_fields": {"id": "options", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "test": {"_type": "BoolOp", "_fields": {"op": {"_type": "And", "_fields": {}}, "values": [{"_type": "UnaryOp", "_fields": {"op": {"_type": "Not", "_fields": {}}, "operand": {"_type": "BoolOp", "_fields": {"op": {"_type": "Or", "_fields": {}}, "values": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "select", "value": {"_type": "Name", "_fields": {"id": "options", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "ignore", "value": {"_type": "Name", "_fields": {"id": "options", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "testsuite", "value": {"_type": "Name", "_fields": {"id": "options", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "doctest", "value": {"_type": "Name", "_fields": {"id": "options", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}, {"_type": "Name", "_fields": {"id": "DEFAULT_IGNORE", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": [{"_type": "Assign", "_fields": {"value": {"_type": "IfExp", "_fields": {"body": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": ""}}]}}, "test": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "select", "value": {"_type": "Name", "_fields": {"id": "options", "ctx": {"_type": "Load", "_fields": {}}}}}}, "orelse": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "ignore", "value": {"_type": "Name", "_fields": {"id": "options", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "tuple", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "ignore", "value": {"_type": "Name", "_fields": {"id": "options", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}]}}, {"_type": "Assign", "_fields": {"value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Slice", "_fields": {"step": null, "lower": null, "upper": null}}, "value": {"_type": "Name", "_fields": {"id": "BENCHMARK_KEYS", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "benchmark_keys", "value": {"_type": "Name", "_fields": {"id": "options", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "ignore_code", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "ignore_code", "value": {"_type": "Name", "_fields": {"id": "options", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "physical_line"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get_checks", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "physical_checks", "value": {"_type": "Name", "_fields": {"id": "options", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "logical_line"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get_checks", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "logical_checks", "value": {"_type": "Name", "_fields": {"id": "options", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "tree"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get_checks", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "ast_checks", "value": {"_type": "Name", "_fields": {"id": "options", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "init_report", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "name": "__init__", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def __init__(self, *args, **kwargs): # build options from the command line self.checker_class = kwargs.pop('checker_class', Checker) parse_argv = kwargs.pop('parse_argv', False) config_file = kwargs.pop('config_file', None) parser = kwargs.pop('parser', None) # build options from dict options_dict = dict(*args, **kwargs) arglist = None if parse_argv else options_dict.get('paths', None) options, self.paths = process_options( arglist, parse_argv, config_file, parser) if options_dict: options.__dict__.update(options_dict) if 'paths' in options_dict: self.paths = options_dict['paths'] self.runner = self.input_file self.options = options if not options.reporter: options.reporter = BaseReport if options.quiet else StandardReport options.select = tuple(options.select or ()) if not (options.select or options.ignore or options.testsuite or options.doctest) and DEFAULT_IGNORE: # The default choice: ignore controversial checks options.ignore = tuple(DEFAULT_IGNORE.split(',')) else: # Ignore all checks which are not explicitly selected options.ignore = ('',) if options.select else tuple(options.ignore) options.benchmark_keys = BENCHMARK_KEYS[:] options.ignore_code = self.ignore_code options.physical_checks = self.get_checks('physical_line') options.logical_checks = self.get_checks('logical_line') options.ast_checks = self.get_checks('tree') self.init_report()
10,972
[ -0.02285686321556568, 0.011188946664333344, 0.019381549209356308, -0.04780782386660576, -0.03976559266448021, 0.024928683415055275, -0.015694599598646164, -0.00842094887048006, 0.007702495437115431, 0.039631929248571396, 0.020439738407731056, 0.00020589416089933366, 0.026666339486837387, 0...
8
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "prog", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "version", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [{"_type": "Constant", "_fields": {"kind": null, "value": "pep8"}}, {"_type": "Name", "_fields": {"id": "__version__", "ctx": {"_type": "Load", "_fields": {}}}}], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "OptionParser", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "prog", "value": {"_type": "Name", "_fields": {"id": "prog", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "keyword", "_fields": {"arg": "version", "value": {"_type": "Name", "_fields": {"id": "version", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "keyword", "_fields": {"arg": "usage", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "%prog [options] input ..."}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "parser", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "exclude"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "filename"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "select"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "ignore"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "max-line-length"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "hang-closing"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "count"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "format"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "quiet"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "show-pep8"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "show-source"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "statistics"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "verbose"}}]}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "config_options", "value": {"_type": "Name", "_fields": {"id": "parser", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "-v"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "--verbose"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "add_option", "value": {"_type": "Name", "_fields": {"id": "parser", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "default", "value": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}}}, {"_type": "keyword", "_fields": {"arg": "action", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "count"}}}}, {"_type": "keyword", "_fields": {"arg": "help", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "print status messages, or debug with -vv"}}}}]}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "-q"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "--quiet"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "add_option", "value": {"_type": "Name", "_fields": {"id": "parser", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "default", "value": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}}}, {"_type": "keyword", "_fields": {"arg": "action", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "count"}}}}, {"_type": "keyword", "_fields": {"arg": "help", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "report only file names, or nothing with -qq"}}}}]}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "-r"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "--repeat"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "add_option", "value": {"_type": "Name", "_fields": {"id": "parser", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "default", "value": {"_type": "Constant", "_fields": {"kind": null, "value": true}}}}, {"_type": "keyword", "_fields": {"arg": "action", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "store_true"}}}}, {"_type": "keyword", "_fields": {"arg": "help", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "(obsolete) show all occurrences of the same error"}}}}]}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "--first"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "add_option", "value": {"_type": "Name", "_fields": {"id": "parser", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "action", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "store_false"}}}}, {"_type": "keyword", "_fields": {"arg": "dest", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "repeat"}}}}, {"_type": "keyword", "_fields": {"arg": "help", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "show first occurrence of each error"}}}}]}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "--exclude"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "add_option", "value": {"_type": "Name", "_fields": {"id": "parser", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "metavar", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "patterns"}}}}, {"_type": "keyword", "_fields": {"arg": "default", "value": {"_type": "Name", "_fields": {"id": "DEFAULT_EXCLUDE", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "keyword", "_fields": {"arg": "help", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "exclude files or directories which match these comma separated patterns (default: %default)"}}}}]}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "--filename"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "add_option", "value": {"_type": "Name", "_fields": {"id": "parser", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "metavar", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "patterns"}}}}, {"_type": "keyword", "_fields": {"arg": "default", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "*.py"}}}}, {"_type": "keyword", "_fields": {"arg": "help", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "when parsing directories, only check filenames matching these comma separated patterns (default: %default)"}}}}]}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "--select"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "add_option", "value": {"_type": "Name", "_fields": {"id": "parser", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "metavar", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "errors"}}}}, {"_type": "keyword", "_fields": {"arg": "default", "value": {"_type": "Constant", "_fields": {"kind": null, "value": ""}}}}, {"_type": "keyword", "_fields": {"arg": "help", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "select errors and warnings (e.g. E,W6)"}}}}]}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "--ignore"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "add_option", "value": {"_type": "Name", "_fields": {"id": "parser", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "metavar", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "errors"}}}}, {"_type": "keyword", "_fields": {"arg": "default", "value": {"_type": "Constant", "_fields": {"kind": null, "value": ""}}}}, {"_type": "keyword", "_fields": {"arg": "help", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "skip errors and warnings (e.g. E4,W)"}}}}]}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "--show-source"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "add_option", "value": {"_type": "Name", "_fields": {"id": "parser", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "action", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "store_true"}}}}, {"_type": "keyword", "_fields": {"arg": "help", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "show source code for each error"}}}}]}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "--show-pep8"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "add_option", "value": {"_type": "Name", "_fields": {"id": "parser", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "action", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "store_true"}}}}, {"_type": "keyword", "_fields": {"arg": "help", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "show text of PEP 8 for each error (implies --first)"}}}}]}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "--statistics"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "add_option", "value": {"_type": "Name", "_fields": {"id": "parser", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "action", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "store_true"}}}}, {"_type": "keyword", "_fields": {"arg": "help", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "count errors and warnings"}}}}]}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "--count"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "add_option", "value": {"_type": "Name", "_fields": {"id": "parser", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "action", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "store_true"}}}}, {"_type": "keyword", "_fields": {"arg": "help", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "print total number of errors and warnings to standard error and set exit code to 1 if total is not null"}}}}]}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "--max-line-length"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "add_option", "value": {"_type": "Name", "_fields": {"id": "parser", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "type", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "int"}}}}, {"_type": "keyword", "_fields": {"arg": "metavar", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "n"}}}}, {"_type": "keyword", "_fields": {"arg": "default", "value": {"_type": "Name", "_fields": {"id": "MAX_LINE_LENGTH", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "keyword", "_fields": {"arg": "help", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "set maximum allowed line length (default: %default)"}}}}]}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "--hang-closing"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "add_option", "value": {"_type": "Name", "_fields": {"id": "parser", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "action", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "store_true"}}}}, {"_type": "keyword", "_fields": {"arg": "help", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "hang closing bracket instead of matching indentation of opening bracket's line"}}}}]}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "--format"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "add_option", "value": {"_type": "Name", "_fields": {"id": "parser", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "metavar", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "format"}}}}, {"_type": "keyword", "_fields": {"arg": "default", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "default"}}}}, {"_type": "keyword", "_fields": {"arg": "help", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "set the error format [default|pylint|<custom>]"}}}}]}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "--diff"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "add_option", "value": {"_type": "Name", "_fields": {"id": "parser", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "action", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "store_true"}}}}, {"_type": "keyword", "_fields": {"arg": "help", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "report only lines changed according to the unified diff received on STDIN"}}}}]}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Testing Options"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "add_option_group", "value": {"_type": "Name", "_fields": {"id": "parser", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "group", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "--testsuite"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "add_option", "value": {"_type": "Name", "_fields": {"id": "group", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "metavar", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "dir"}}}}, {"_type": "keyword", "_fields": {"arg": "help", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "run regression tests from dir"}}}}]}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "--doctest"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "add_option", "value": {"_type": "Name", "_fields": {"id": "group", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "action", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "store_true"}}}}, {"_type": "keyword", "_fields": {"arg": "help", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "run doctest on myself"}}}}]}}}}], "test": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "TESTSUITE_PATH", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "exists", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "path", "value": {"_type": "Name", "_fields": {"id": "os", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, "orelse": []}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "--benchmark"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "add_option", "value": {"_type": "Name", "_fields": {"id": "group", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "action", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "store_true"}}}}, {"_type": "keyword", "_fields": {"arg": "help", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "measure processing speed"}}}}]}}}}, {"_type": "Return", "_fields": {"value": {"_type": "Name", "_fields": {"id": "parser", "ctx": {"_type": "Load", "_fields": {}}}}}}], "name": "get_parser", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def get_parser(prog='pep8', version=__version__): parser = OptionParser(prog=prog, version=version, usage="%prog [options] input ...") parser.config_options = [ 'exclude', 'filename', 'select', 'ignore', 'max-line-length', 'hang-closing', 'count', 'format', 'quiet', 'show-pep8', 'show-source', 'statistics', 'verbose'] parser.add_option('-v', '--verbose', default=0, action='count', help="print status messages, or debug with -vv") parser.add_option('-q', '--quiet', default=0, action='count', help="report only file names, or nothing with -qq") parser.add_option('-r', '--repeat', default=True, action='store_true', help="(obsolete) show all occurrences of the same error") parser.add_option('--first', action='store_false', dest='repeat', help="show first occurrence of each error") parser.add_option('--exclude', metavar='patterns', default=DEFAULT_EXCLUDE, help="exclude files or directories which match these " "comma separated patterns (default: %default)") parser.add_option('--filename', metavar='patterns', default='*.py', help="when parsing directories, only check filenames " "matching these comma separated patterns " "(default: %default)") parser.add_option('--select', metavar='errors', default='', help="select errors and warnings (e.g. E,W6)") parser.add_option('--ignore', metavar='errors', default='', help="skip errors and warnings (e.g. E4,W)") parser.add_option('--show-source', action='store_true', help="show source code for each error") parser.add_option('--show-pep8', action='store_true', help="show text of PEP 8 for each error " "(implies --first)") parser.add_option('--statistics', action='store_true', help="count errors and warnings") parser.add_option('--count', action='store_true', help="print total number of errors and warnings " "to standard error and set exit code to 1 if " "total is not null") parser.add_option('--max-line-length', type='int', metavar='n', default=MAX_LINE_LENGTH, help="set maximum allowed line length " "(default: %default)") parser.add_option('--hang-closing', action='store_true', help="hang closing bracket instead of matching " "indentation of opening bracket's line") parser.add_option('--format', metavar='format', default='default', help="set the error format [default|pylint|<custom>]") parser.add_option('--diff', action='store_true', help="report only lines changed according to the " "unified diff received on STDIN") group = parser.add_option_group("Testing Options") if os.path.exists(TESTSUITE_PATH): group.add_option('--testsuite', metavar='dir', help="run regression tests from dir") group.add_option('--doctest', action='store_true', help="run doctest on myself") group.add_option('--benchmark', action='store_true', help="measure processing speed") return parser
10,973
[ -0.027703434228897095, 0.026719171553850174, 0.040930986404418945, 0.032504722476005554, -0.03922652825713158, -0.048709072172641754, 0.009548562578856945, -0.007333968300372362, -0.02849564701318741, 0.010640855878591537, -0.006595770362764597, 0.02083759196102619, -0.0315924771130085, -0...
8
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "labels", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "xyzw", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "xyzw", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": 0}}, {"_type": "Constant", "_fields": {"kind": null, "value": 2}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1}}]}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "transpose", "value": {"_type": "Name", "_fields": {"id": "tf", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "xyzw", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "to_world_L"}}, "value": {"_type": "Name", "_fields": {"id": "labels", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "keys_uvd_L"}}, "value": {"_type": "Name", "_fields": {"id": "labels", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": true}}], "func": {"_type": "Name", "_fields": {"id": "project", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "gt_world_coords", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Sub", "_fields": {}}, "left": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Slice", "_fields": {"step": null, "lower": null, "upper": null}}, {"_type": "Slice", "_fields": {"step": null, "lower": null, "upper": {"_type": "Constant", "_fields": {"kind": null, "value": 3}}}}, {"_type": "Slice", "_fields": {"step": null, "lower": null, "upper": null}}]}}, "value": {"_type": "Name", "_fields": {"id": "xyzw", "ctx": {"_type": "Load", "_fields": {}}}}}}, "right": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Slice", "_fields": {"step": null, "lower": null, "upper": null}}, {"_type": "Slice", "_fields": {"step": null, "lower": null, "upper": {"_type": "Constant", "_fields": {"kind": null, "value": 3}}}}, {"_type": "Slice", "_fields": {"step": null, "lower": null, "upper": null}}]}}, "value": {"_type": "Name", "_fields": {"id": "gt_world_coords", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "sub", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "sub", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "square", "value": {"_type": "Name", "_fields": {"id": "tf", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "wd", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "wd", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "reduce_sum", "value": {"_type": "Name", "_fields": {"id": "tf", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "axis", "value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "UnaryOp", "_fields": {"op": {"_type": "USub", "_fields": {}}, "operand": {"_type": "Constant", "_fields": {"kind": null, "value": 2}}}}]}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "wd", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "wd", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "sqrt", "value": {"_type": "Name", "_fields": {"id": "tf", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "wd", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Return", "_fields": {"value": {"_type": "Name", "_fields": {"id": "wd", "ctx": {"_type": "Load", "_fields": {}}}}}}], "name": "world_error", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def world_error(labels, xyzw): xyzw = tf.transpose(xyzw, [0, 2, 1]) # [batch, 4, num_kp] # [batch, 4, num_kp] gt_world_coords = project(labels['to_world_L'], labels['keys_uvd_L'], True) sub = xyzw[:, :3, :] - gt_world_coords[:, :3, :] wd = tf.square(sub) wd = tf.reduce_sum(wd, axis=[-2]) # [batch, num_kp] result. wd = tf.sqrt(wd) return wd
10,974
[ -0.012666190974414349, 0.0190317090600729, 0.01876152493059635, -0.0014846570556983352, -0.045606933534145355, -0.009132194332778454, 0.022695394232869148, 0.0234519075602293, 0.009083561599254608, 0.06964243948459625, 0.008575616404414177, 0.0073597920127213, -0.021679503843188286, 0.0094...
11
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "step", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "loss_step", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "minf", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [{"_type": "Constant", "_fields": {"kind": null, "value": 0.0}}], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": 1.0}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, "value": {"_type": "Name", "_fields": {"id": "loss_step", "ctx": {"_type": "Load", "_fields": {}}}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 0}}]}}, "orelse": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "step", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "float32", "value": {"_type": "Name", "_fields": {"id": "tf", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "cast", "value": {"_type": "Name", "_fields": {"id": "tf", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "step", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "minf", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Div", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Sub", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "step", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "value": {"_type": "Name", "_fields": {"id": "loss_step", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "right": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Sub", "_fields": {}}, "left": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}, "value": {"_type": "Name", "_fields": {"id": "loss_step", "ctx": {"_type": "Load", "_fields": {}}}}}}, "right": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "value": {"_type": "Name", "_fields": {"id": "loss_step", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "float32", "value": {"_type": "Name", "_fields": {"id": "tf", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "cast", "value": {"_type": "Name", "_fields": {"id": "tf", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": 1.0}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "minimum", "value": {"_type": "Name", "_fields": {"id": "tf", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "maximum", "value": {"_type": "Name", "_fields": {"id": "tf", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "name": "adjust_proj_factor", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def adjust_proj_factor(step, loss_step, minf=0.0): if loss_step[1] == 0: return 1.0 step = tf.cast(step, tf.float32) return tf.maximum( minf, tf.minimum((step - loss_step[0]) / tf.cast(loss_step[1] - loss_step[0], tf.float32), 1.0))
10,975
[ 0.06530410051345825, 0.014375734142959118, 0.01848483830690384, -0.008058751933276653, -0.004498549737036228, 0.023268572986125946, -0.02429891563951969, 0.0015424474840983748, 0.02306004986166954, 0.026102015748620033, -0.008696583099663258, -0.020496459677815437, 0.028604276478290558, -0...
8
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "sender", "annotation": null, "type_comment": null}}], "kwarg": {"_type": "arg", "_fields": {"arg": "kwargs", "annotation": null, "type_comment": null}}, "vararg": {"_type": "arg", "_fields": {"arg": "args", "annotation": null, "type_comment": null}}, "defaults": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}, "targets": [{"_type": "Name", "_fields": {"id": "retval", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "sender", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Starred", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "value": {"_type": "Name", "_fields": {"id": "args", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_default_handler", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": null, "value": {"_type": "Name", "_fields": {"id": "kwargs", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "retval", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "test": {"_type": "BoolOp", "_fields": {"op": {"_type": "And", "_fields": {}}, "values": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_default_handler", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Compare", "_fields": {"ops": [{"_type": "Is", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_flag", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "comparators": [{"_type": "Name", "_fields": {"id": "SIGNAL_RUN_FIRST", "ctx": {"_type": "Load", "_fields": {}}}}]}}]}}, "orelse": []}}, {"_type": "For", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "IfExp", "_fields": {"body": {"_type": "Name", "_fields": {"id": "ckwargs", "ctx": {"_type": "Load", "_fields": {}}}}, "test": {"_type": "Name", "_fields": {"id": "ckwargs", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": {"_type": "Dict", "_fields": {"keys": [], "values": []}}}}], "func": {"_type": "Name", "_fields": {"id": "dict", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "kw", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "IfExp", "_fields": {"body": {"_type": "Name", "_fields": {"id": "kwargs", "ctx": {"_type": "Load", "_fields": {}}}}, "test": {"_type": "Name", "_fields": {"id": "kwargs", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": {"_type": "Dict", "_fields": {"keys": [], "values": []}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "update", "value": {"_type": "Name", "_fields": {"id": "kw", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "sender", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Starred", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "value": {"_type": "Name", "_fields": {"id": "args", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "cb", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": null, "value": {"_type": "Name", "_fields": {"id": "kw", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}], "iter": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_callbacks", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "orelse": [], "target": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "cb", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "ckwargs", "ctx": {"_type": "Store", "_fields": {}}}}]}}, "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "sender", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Starred", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "value": {"_type": "Name", "_fields": {"id": "args", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_default_handler", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": null, "value": {"_type": "Name", "_fields": {"id": "kwargs", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "retval", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "test": {"_type": "BoolOp", "_fields": {"op": {"_type": "And", "_fields": {}}, "values": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_default_handler", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Compare", "_fields": {"ops": [{"_type": "Is", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_flag", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "comparators": [{"_type": "Name", "_fields": {"id": "SIGNAL_RUN_LAST", "ctx": {"_type": "Load", "_fields": {}}}}]}}]}}, "orelse": []}}, {"_type": "For", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "IfExp", "_fields": {"body": {"_type": "Name", "_fields": {"id": "ckwargs", "ctx": {"_type": "Load", "_fields": {}}}}, "test": {"_type": "Name", "_fields": {"id": "ckwargs", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": {"_type": "Dict", "_fields": {"keys": [], "values": []}}}}], "func": {"_type": "Name", "_fields": {"id": "dict", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "kw", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "IfExp", "_fields": {"body": {"_type": "Name", "_fields": {"id": "kwargs", "ctx": {"_type": "Load", "_fields": {}}}}, "test": {"_type": "Name", "_fields": {"id": "kwargs", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": {"_type": "Dict", "_fields": {"keys": [], "values": []}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "update", "value": {"_type": "Name", "_fields": {"id": "kw", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "sender", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Starred", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "value": {"_type": "Name", "_fields": {"id": "args", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "cb", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": null, "value": {"_type": "Name", "_fields": {"id": "kw", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}], "iter": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_callbacks_after", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "orelse": [], "target": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "cb", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "ckwargs", "ctx": {"_type": "Store", "_fields": {}}}}]}}, "type_comment": null}}, {"_type": "Return", "_fields": {"value": {"_type": "Name", "_fields": {"id": "retval", "ctx": {"_type": "Load", "_fields": {}}}}}}], "name": "emit", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def emit(self, sender=None, *args, **kwargs): retval = None if self._default_handler and self._flag is SIGNAL_RUN_FIRST: retval = self._default_handler(sender, *args, **kwargs) for cb, ckwargs in self._callbacks: kw = dict(ckwargs if ckwargs else {}) kw.update(kwargs if kwargs else {}) cb(sender, *args, **kw) if self._default_handler and self._flag is SIGNAL_RUN_LAST: retval = self._default_handler(sender, *args, **kwargs) for cb, ckwargs in self._callbacks_after: kw = dict(ckwargs if ckwargs else {}) kw.update(kwargs if kwargs else {}) cb(sender, *args, **kw) return retval
10,976
[ 0.04250336065888405, 0.038785796612501144, -0.05143025144934654, -0.003483736654743552, 0.003980990499258041, 0.07510900497436523, -0.0391409806907177, -0.03947248309850693, -0.007879105396568775, -0.012159040197730064, -0.027183208614587784, -0.039448801428079605, 0.03999341279268265, -0....
13
{"_type": "Module", "_fields": {"body": [{"_type": "ClassDef", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Dict", "_fields": {"keys": [], "values": []}}, "targets": [{"_type": "Name", "_fields": {"id": "__signals__", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "do_"}}, "targets": [{"_type": "Name", "_fields": {"id": "_signal_prefix", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "name", "annotation": null, "type_comment": null}}], "kwarg": {"_type": "arg", "_fields": {"arg": "kwargs", "annotation": null, "type_comment": null}}, "vararg": {"_type": "arg", "_fields": {"arg": "args", "annotation": null, "type_comment": null}}, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "NotIn", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "name", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_decl_signals", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "orelse": [{"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Starred", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "value": {"_type": "Name", "_fields": {"id": "args", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "emit", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Name", "_fields": {"id": "name", "ctx": {"_type": "Load", "_fields": {}}}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_decl_signals", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": null, "value": {"_type": "Name", "_fields": {"id": "kwargs", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}]}}], "name": "emit", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "name", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "callback", "annotation": null, "type_comment": null}}], "kwarg": {"_type": "arg", "_fields": {"arg": "data", "annotation": null, "type_comment": null}}, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "name", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "Signal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "slice": {"_type": "Name", "_fields": {"id": "name", "ctx": {"_type": "Load", "_fields": {}}}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_decl_signals", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "type_comment": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "NotIn", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "name", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_decl_signals", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "orelse": []}}, {"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "callback", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "connect", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Name", "_fields": {"id": "name", "ctx": {"_type": "Load", "_fields": {}}}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_decl_signals", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": null, "value": {"_type": "Name", "_fields": {"id": "data", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}], "name": "connect", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "name", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "callback", "annotation": null, "type_comment": null}}], "kwarg": {"_type": "arg", "_fields": {"arg": "data", "annotation": null, "type_comment": null}}, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "name", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "Signal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "slice": {"_type": "Name", "_fields": {"id": "name", "ctx": {"_type": "Load", "_fields": {}}}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_decl_signals", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "type_comment": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "NotIn", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "name", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_decl_signals", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "orelse": []}}, {"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "callback", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "connect_after", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Name", "_fields": {"id": "name", "ctx": {"_type": "Load", "_fields": {}}}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_decl_signals", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": null, "value": {"_type": "Name", "_fields": {"id": "data", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}], "name": "connect_after", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "cls", "annotation": null, "type_comment": null}}], "kwarg": {"_type": "arg", "_fields": {"arg": "kwargs", "annotation": null, "type_comment": null}}, "vararg": {"_type": "arg", "_fields": {"arg": "args", "annotation": null, "type_comment": null}}, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "cls", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "__new__", "value": {"_type": "Name", "_fields": {"id": "object", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Dict", "_fields": {"keys": [], "values": []}}, "targets": [{"_type": "Name", "_fields": {"id": "signals", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Dict", "_fields": {"keys": [], "values": []}}, "targets": [{"_type": "Name", "_fields": {"id": "declared", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "For", "_fields": {"body": [{"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "__signals__", "value": {"_type": "Name", "_fields": {"id": "base", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "update", "value": {"_type": "Name", "_fields": {"id": "declared", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "test": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "base", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": "__signals__"}}], "func": {"_type": "Name", "_fields": {"id": "hasattr", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": []}}], "iter": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "mro", "value": {"_type": "Name", "_fields": {"id": "cls", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "reversed", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "base", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "__signals__", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "update", "value": {"_type": "Name", "_fields": {"id": "declared", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "For", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "handler"}}, {"_type": "Constant", "_fields": {"kind": null, "value": null}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Name", "_fields": {"id": "args", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "handler", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "flag"}}, {"_type": "Name", "_fields": {"id": "SIGNAL_RUN_LAST", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Name", "_fields": {"id": "args", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "flag", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "cls", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "handler", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "getattr", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "handler", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "test": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "cls", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "handler", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "hasattr", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [{"_type": "Raise", "_fields": {"exc": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "%s does not have '%s' method to call"}}, "right": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "__name__", "value": {"_type": "Name", "_fields": {"id": "cls", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Name", "_fields": {"id": "handler", "ctx": {"_type": "Load", "_fields": {}}}}]}}}}], "func": {"_type": "Name", "_fields": {"id": "TypeError", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "cause": null}}]}}], "test": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "handler", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "string_type", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "isinstance", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [{"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_signal_prefix", "value": {"_type": "Name", "_fields": {"id": "cls", "ctx": {"_type": "Load", "_fields": {}}}}}}, "right": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "name", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "norm", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "targets": [{"_type": "Name", "_fields": {"id": "handler_name", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "cls", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "handler_name", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "getattr", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "handler", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "test": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "cls", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "handler_name", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "hasattr", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": []}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Is", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "handler", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}]}}, "orelse": []}}]}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "name", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "handler", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "flag", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "Signal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "slice": {"_type": "Name", "_fields": {"id": "name", "ctx": {"_type": "Load", "_fields": {}}}}, "value": {"_type": "Name", "_fields": {"id": "signals", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "iter": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "items", "value": {"_type": "Name", "_fields": {"id": "declared", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "orelse": [], "target": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "name", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "args", "ctx": {"_type": "Store", "_fields": {}}}}]}}, "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Name", "_fields": {"id": "signals", "ctx": {"_type": "Load", "_fields": {}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "_decl_signals", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Return", "_fields": {"value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "name": "__new__", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "name": "SignaledObject", "bases": [{"_type": "Name", "_fields": {"id": "object", "ctx": {"_type": "Load", "_fields": {}}}}], "keywords": [], "type_params": [], "decorator_list": []}}], "type_ignores": []}}
class SignaledObject(object): __signals__ = {} _signal_prefix = 'do_' def emit(self, name, *args, **kwargs): if name not in self._decl_signals: return [] else: return self._decl_signals[name].emit(self, *args, **kwargs) def connect(self, name, callback, **data): if name not in self._decl_signals: self._decl_signals[name] = Signal(name) return self._decl_signals[name].connect(callback, **data) def connect_after(self, name, callback, **data): if name not in self._decl_signals: self._decl_signals[name] = Signal(name) return self._decl_signals[name].connect_after(callback, **data) def __new__(cls, *args, **kwargs): self = object.__new__(cls) signals = {} # copy base __signals__ declarations declared = {} for base in reversed(cls.mro()): if hasattr(base, '__signals__'): declared.update(base.__signals__) declared.update(self.__signals__) for name, args in declared.items(): handler = args.get('handler', None) flag = args.get('flag', SIGNAL_RUN_LAST) if isinstance(handler, string_type): if hasattr(cls, handler): handler = getattr(cls, handler) else: raise TypeError("%s does not have '%s' method to call" %\ (cls.__name__, handler)) elif handler is None: handler_name = cls._signal_prefix + norm(name) if hasattr(cls, handler_name): handler = getattr(cls, handler_name) signals[name] = Signal(name, handler, flag) self._decl_signals = signals return self
10,977
[ 0.03736235946416855, 0.050489675253629684, -0.03169374540448189, 0.0017269763629883528, 0.005984174087643623, 0.026461180299520493, -0.014733805321156979, -0.024946488440036774, -0.02083846554160118, 0.02827421762049198, -0.02776932157576084, -0.028388967737555504, 0.031533095985651016, -0...
12
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "cls", "annotation": null, "type_comment": null}}], "kwarg": {"_type": "arg", "_fields": {"arg": "kwargs", "annotation": null, "type_comment": null}}, "vararg": {"_type": "arg", "_fields": {"arg": "args", "annotation": null, "type_comment": null}}, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "cls", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "__new__", "value": {"_type": "Name", "_fields": {"id": "object", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Dict", "_fields": {"keys": [], "values": []}}, "targets": [{"_type": "Name", "_fields": {"id": "signals", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Dict", "_fields": {"keys": [], "values": []}}, "targets": [{"_type": "Name", "_fields": {"id": "declared", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "For", "_fields": {"body": [{"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "__signals__", "value": {"_type": "Name", "_fields": {"id": "base", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "update", "value": {"_type": "Name", "_fields": {"id": "declared", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "test": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "base", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": "__signals__"}}], "func": {"_type": "Name", "_fields": {"id": "hasattr", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": []}}], "iter": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "mro", "value": {"_type": "Name", "_fields": {"id": "cls", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "reversed", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "base", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "__signals__", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "update", "value": {"_type": "Name", "_fields": {"id": "declared", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "For", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "handler"}}, {"_type": "Constant", "_fields": {"kind": null, "value": null}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Name", "_fields": {"id": "args", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "handler", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "flag"}}, {"_type": "Name", "_fields": {"id": "SIGNAL_RUN_LAST", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Name", "_fields": {"id": "args", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "flag", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "cls", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "handler", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "getattr", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "handler", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "test": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "cls", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "handler", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "hasattr", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [{"_type": "Raise", "_fields": {"exc": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "%s does not have '%s' method to call"}}, "right": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "__name__", "value": {"_type": "Name", "_fields": {"id": "cls", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Name", "_fields": {"id": "handler", "ctx": {"_type": "Load", "_fields": {}}}}]}}}}], "func": {"_type": "Name", "_fields": {"id": "TypeError", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "cause": null}}]}}], "test": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "handler", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "string_type", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "isinstance", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [{"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_signal_prefix", "value": {"_type": "Name", "_fields": {"id": "cls", "ctx": {"_type": "Load", "_fields": {}}}}}}, "right": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "name", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "norm", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "targets": [{"_type": "Name", "_fields": {"id": "handler_name", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "cls", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "handler_name", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "getattr", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "handler", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "test": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "cls", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "handler_name", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "hasattr", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": []}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Is", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "handler", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}]}}, "orelse": []}}]}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "name", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "handler", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "flag", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "Signal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "slice": {"_type": "Name", "_fields": {"id": "name", "ctx": {"_type": "Load", "_fields": {}}}}, "value": {"_type": "Name", "_fields": {"id": "signals", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "iter": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "items", "value": {"_type": "Name", "_fields": {"id": "declared", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "orelse": [], "target": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "elts": [{"_type": "Name", "_fields": {"id": "name", "ctx": {"_type": "Store", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "args", "ctx": {"_type": "Store", "_fields": {}}}}]}}, "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Name", "_fields": {"id": "signals", "ctx": {"_type": "Load", "_fields": {}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "_decl_signals", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Return", "_fields": {"value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "name": "__new__", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def __new__(cls, *args, **kwargs): self = object.__new__(cls) signals = {} # copy base __signals__ declarations declared = {} for base in reversed(cls.mro()): if hasattr(base, '__signals__'): declared.update(base.__signals__) declared.update(self.__signals__) for name, args in declared.items(): handler = args.get('handler', None) flag = args.get('flag', SIGNAL_RUN_LAST) if isinstance(handler, string_type): if hasattr(cls, handler): handler = getattr(cls, handler) else: raise TypeError("%s does not have '%s' method to call" %\ (cls.__name__, handler)) elif handler is None: handler_name = cls._signal_prefix + norm(name) if hasattr(cls, handler_name): handler = getattr(cls, handler_name) signals[name] = Signal(name, handler, flag) self._decl_signals = signals return self
10,978
[ 0.026243820786476135, 0.04940779134631157, 0.06762664020061493, 0.014336501248180866, 0.07474067062139511, 0.044896453619003296, 0.03225170448422432, -0.02459544874727726, -0.032099880278110504, -0.033509671688079834, 0.010025790892541409, -0.05339858680963516, 0.020170871168375015, -0.023...
13
{"_type": "Module", "_fields": {"body": [{"_type": "ClassDef", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "records"}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "metadata", "value": {"_type": "Name", "_fields": {"id": "Base", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "id"}}, {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "UUID", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "as_uuid", "value": {"_type": "Constant", "_fields": {"kind": null, "value": true}}}}]}}], "func": {"_type": "Name", "_fields": {"id": "Column", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "server_default", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "uuid_generate_v4()"}}], "func": {"_type": "Name", "_fields": {"id": "text", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "keyword", "_fields": {"arg": "primary_key", "value": {"_type": "Constant", "_fields": {"kind": null, "value": true}}}}, {"_type": "keyword", "_fields": {"arg": "unique", "value": {"_type": "Constant", "_fields": {"kind": null, "value": true}}}}]}}, {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "domain_id"}}, {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "domains.id"}}], "func": {"_type": "Name", "_fields": {"id": "ForeignKey", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "onupdate", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "CASCADE"}}}}, {"_type": "keyword", "_fields": {"arg": "ondelete", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "CASCADE"}}}}]}}], "func": {"_type": "Name", "_fields": {"id": "Column", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "nullable", "value": {"_type": "Constant", "_fields": {"kind": null, "value": false}}}}, {"_type": "keyword", "_fields": {"arg": "index", "value": {"_type": "Constant", "_fields": {"kind": null, "value": true}}}}]}}, {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "resource"}}, {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 256}}], "func": {"_type": "Name", "_fields": {"id": "String", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "Column", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "index", "value": {"_type": "Constant", "_fields": {"kind": null, "value": true}}}}, {"_type": "keyword", "_fields": {"arg": "unique", "value": {"_type": "Constant", "_fields": {"kind": null, "value": true}}}}]}}, {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "ttl"}}, {"_type": "Name", "_fields": {"id": "Integer", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "Column", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "server_default", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "3600"}}], "func": {"_type": "Name", "_fields": {"id": "text", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}]}}, {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "class"}}, {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 10}}], "func": {"_type": "Name", "_fields": {"id": "String", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "Column", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "default", "value": {"_type": "Constant", "_fields": {"kind": "u", "value": "IN"}}}}]}}, {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "type"}}, {"_type": "Call", "_fields": {"args": [{"_type": "Starred", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "keys", "value": {"_type": "Name", "_fields": {"id": "type_to_value", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "func": {"_type": "Name", "_fields": {"id": "Enum", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "name", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "resource_type"}}}}]}}], "func": {"_type": "Name", "_fields": {"id": "Column", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "record"}}, {"_type": "Name", "_fields": {"id": "Text", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "Column", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "priority"}}, {"_type": "Name", "_fields": {"id": "Integer", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "Column", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "server_default", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "0"}}], "func": {"_type": "Name", "_fields": {"id": "text", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "keyword", "_fields": {"arg": "nullable", "value": {"_type": "Constant", "_fields": {"kind": null, "value": true}}}}]}}, {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "created"}}, {"_type": "Name", "_fields": {"id": "DateTime", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "Column", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "server_default", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "current_timestamp"}}], "func": {"_type": "Name", "_fields": {"id": "text", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}]}}, {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "updated"}}, {"_type": "Name", "_fields": {"id": "DateTime", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "Column", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "server_default", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "current_timestamp"}}], "func": {"_type": "Name", "_fields": {"id": "text", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "keyword", "_fields": {"arg": "server_onupdate", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "current_timestamp"}}], "func": {"_type": "Name", "_fields": {"id": "text", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}]}}], "func": {"_type": "Name", "_fields": {"id": "Table", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "__table__", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "resource", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "c", "value": {"_type": "Name", "_fields": {"id": "__table__", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "_resource", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "idna"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "decode", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "ascii"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "encode", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_resource", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}}}, "keywords": []}}}}], "test": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "Domain", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "isinstance", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": []}}, {"_type": "Return", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_resource", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "name": "resource", "returns": null, "type_params": [], "type_comment": null, "decorator_list": [{"_type": "Name", "_fields": {"id": "hybrid_property", "ctx": {"_type": "Load", "_fields": {}}}}]}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "value", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "lower", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "utf-8"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "decode", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "idna"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "encode", "value": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, "keywords": []}}}}, "keywords": []}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "_resource", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "test": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "text_type", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "isinstance", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [{"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "_resource", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "test": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "binary_type", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "isinstance", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [{"_type": "Raise", "_fields": {"exc": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Unable to store value as requested."}}], "func": {"_type": "Name", "_fields": {"id": "ValueError", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "cause": null}}]}}]}}], "name": "resource", "returns": null, "type_params": [], "type_comment": null, "decorator_list": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "setter", "value": {"_type": "Name", "_fields": {"id": "resource", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "cls", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_resource", "value": {"_type": "Name", "_fields": {"id": "cls", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "IdnaComparator", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}], "name": "resource", "returns": null, "type_params": [], "type_comment": null, "decorator_list": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "comparator", "value": {"_type": "Name", "_fields": {"id": "resource", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}], "name": "Record", "bases": [{"_type": "Name", "_fields": {"id": "Base", "ctx": {"_type": "Load", "_fields": {}}}}], "keywords": [], "type_params": [], "decorator_list": []}}], "type_ignores": []}}
class Record(Base): __table__ = Table('records', Base.metadata, Column('id', UUID(as_uuid=True), server_default=text('uuid_generate_v4()'), primary_key=True, unique=True), Column('domain_id', ForeignKey('domains.id', onupdate='CASCADE', ondelete='CASCADE'), nullable=False, index=True), Column('resource', String(256), index=True, unique=True), Column('ttl', Integer, server_default=text('3600')), Column('class', String(10), default=u"IN"), Column('type', Enum(*type_to_value.keys(), name='resource_type')), Column('record', Text), Column('priority', Integer, server_default=text('0'), nullable=True), Column('created', DateTime, server_default=text('current_timestamp')), Column('updated', DateTime, server_default=text('current_timestamp'), server_onupdate=text('current_timestamp')), ) _resource = __table__.c.resource # cls.resource @hybrid_property def resource(self): if isinstance(self, Domain): return self._resource.encode('ascii').decode('idna') return self._resource @resource.setter def resource(self, value): if isinstance(value, text_type): self._resource = value.encode('idna').decode('utf-8').lower() elif isinstance(value, binary_type): self._resource = value else: raise ValueError("Unable to store value as requested.") @resource.comparator def resource(cls): return IdnaComparator(cls._resource)
10,979
[ 0.017629286274313927, 0.012374402955174446, -0.03693109378218651, -0.005421570502221584, 0.0007804632186889648, 0.04651419445872307, -0.01119911763817072, -0.012057979591190815, -0.015956765040755272, 0.006938706152141094, 0.0037207964342087507, -0.03620784357190132, -0.016408797353506088, ...
15
{"_type": "Module", "_fields": {"body": [{"_type": "ClassDef", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": {"_type": "arg", "_fields": {"arg": "kwargs", "annotation": null, "type_comment": null}}, "vararg": {"_type": "arg", "_fields": {"arg": "args", "annotation": null, "type_comment": null}}, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Starred", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "value": {"_type": "Name", "_fields": {"id": "args", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "__init__", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "EntityNicsModule", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "super", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": null, "value": {"_type": "Name", "_fields": {"id": "kwargs", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "vnic_id", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "name": "__init__", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Return", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_vnic_id", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "name": "vnic_id", "returns": null, "type_params": [], "type_comment": null, "decorator_list": [{"_type": "Name", "_fields": {"id": "property", "ctx": {"_type": "Load", "_fields": {}}}}]}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "vnic_id", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Name", "_fields": {"id": "vnic_id", "ctx": {"_type": "Load", "_fields": {}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "_vnic_id", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "name": "vnic_id", "returns": null, "type_params": [], "type_comment": null, "decorator_list": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "setter", "value": {"_type": "Name", "_fields": {"id": "vnic_id", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "Nic", "value": {"_type": "Name", "_fields": {"id": "otypes", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "id", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "id"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "params", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_module", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "keywords": []}}}}, {"_type": "keyword", "_fields": {"arg": "name", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "name"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "params", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_module", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "keywords": []}}}}, {"_type": "keyword", "_fields": {"arg": "interface", "value": {"_type": "IfExp", "_fields": {"body": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "interface"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "params", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_module", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "keywords": []}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "NicInterface", "value": {"_type": "Name", "_fields": {"id": "otypes", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "test": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "interface"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "params", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_module", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "keywords": []}}, "orelse": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}}}, {"_type": "keyword", "_fields": {"arg": "vnic_profile", "value": {"_type": "IfExp", "_fields": {"body": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "VnicProfile", "value": {"_type": "Name", "_fields": {"id": "otypes", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "id", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "vnic_id", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}]}}, "test": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "vnic_id", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "orelse": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}}}, {"_type": "keyword", "_fields": {"arg": "mac", "value": {"_type": "IfExp", "_fields": {"body": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "Mac", "value": {"_type": "Name", "_fields": {"id": "otypes", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "address", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "mac_address"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "params", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_module", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "keywords": []}}}}]}}, "test": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "mac_address"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "params", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_module", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "keywords": []}}, "orelse": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}}}, {"_type": "keyword", "_fields": {"arg": "linked", "value": {"_type": "IfExp", "_fields": {"body": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "linked"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "param", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "IsNot", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "linked"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "param", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}]}}, "orelse": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}}}]}}}}], "name": "build_entity", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "entity", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": {"_type": "BoolOp", "_fields": {"op": {"_type": "And", "_fields": {}}, "values": [{"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "interface"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "params", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_module", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "keywords": []}}, {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "interface", "value": {"_type": "Name", "_fields": {"id": "entity", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "str", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "linked"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "params", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_module", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "keywords": []}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "linked", "value": {"_type": "Name", "_fields": {"id": "entity", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "name"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "params", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_module", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "keywords": []}}, {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "name", "value": {"_type": "Name", "_fields": {"id": "entity", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "str", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "profile"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "params", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_module", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "keywords": []}}, {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_connection", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "vnic_profile", "value": {"_type": "Name", "_fields": {"id": "entity", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "get_link_name", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "mac_address"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "params", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_module", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "keywords": []}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "address", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "mac", "value": {"_type": "Name", "_fields": {"id": "entity", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "func": {"_type": "Name", "_fields": {"id": "equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}]}}}}], "test": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "vm"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "params", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_module", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "keywords": []}}, "orelse": [{"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": {"_type": "BoolOp", "_fields": {"op": {"_type": "And", "_fields": {}}, "values": [{"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "interface"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "params", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_module", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "keywords": []}}, {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "interface", "value": {"_type": "Name", "_fields": {"id": "entity", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "str", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "linked"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "params", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_module", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "keywords": []}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "linked", "value": {"_type": "Name", "_fields": {"id": "entity", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "name"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "params", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_module", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "keywords": []}}, {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "name", "value": {"_type": "Name", "_fields": {"id": "entity", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "str", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "profile"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "params", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_module", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "keywords": []}}, {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_connection", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "vnic_profile", "value": {"_type": "Name", "_fields": {"id": "entity", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "get_link_name", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}]}}}}], "test": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "template"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "params", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_module", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "keywords": []}}, "orelse": []}}]}}], "name": "update_check", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "name": "EntityNicsModule", "bases": [{"_type": "Name", "_fields": {"id": "BaseModule", "ctx": {"_type": "Load", "_fields": {}}}}], "keywords": [], "type_params": [], "decorator_list": []}}], "type_ignores": []}}
class EntityNicsModule(BaseModule): def __init__(self, *args, **kwargs): super(EntityNicsModule, self).__init__(*args, **kwargs) self.vnic_id = None @property def vnic_id(self): return self._vnic_id @vnic_id.setter def vnic_id(self, vnic_id): self._vnic_id = vnic_id def build_entity(self): return otypes.Nic( id=self._module.params.get('id'), name=self._module.params.get('name'), interface=otypes.NicInterface( self._module.params.get('interface') ) if self._module.params.get('interface') else None, vnic_profile=otypes.VnicProfile( id=self.vnic_id, ) if self.vnic_id else None, mac=otypes.Mac( address=self._module.params.get('mac_address') ) if self._module.params.get('mac_address') else None, linked=self.param('linked') if self.param('linked') is not None else None, ) def update_check(self, entity): if self._module.params.get('vm'): return ( equal(self._module.params.get('interface'), str(entity.interface)) and equal(self._module.params.get('linked'), entity.linked) and equal(self._module.params.get('name'), str(entity.name)) and equal(self._module.params.get('profile'), get_link_name(self._connection, entity.vnic_profile)) and equal(self._module.params.get('mac_address'), entity.mac.address) ) elif self._module.params.get('template'): return ( equal(self._module.params.get('interface'), str(entity.interface)) and equal(self._module.params.get('linked'), entity.linked) and equal(self._module.params.get('name'), str(entity.name)) and equal(self._module.params.get('profile'), get_link_name(self._connection, entity.vnic_profile)) )
10,980
[ 0.026455122977495193, -0.006201869808137417, -0.04318682849407196, 0.005958204157650471, 0.011289839632809162, -0.013053514063358307, -0.0026353595312684774, -0.011632131412625313, 0.0020406993571668863, -0.00974082201719284, 0.017335066571831703, 0.015768645331263542, 0.019528057426214218, ...
14
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "Nic", "value": {"_type": "Name", "_fields": {"id": "otypes", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "id", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "id"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "params", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_module", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "keywords": []}}}}, {"_type": "keyword", "_fields": {"arg": "name", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "name"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "params", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_module", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "keywords": []}}}}, {"_type": "keyword", "_fields": {"arg": "interface", "value": {"_type": "IfExp", "_fields": {"body": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "interface"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "params", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_module", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "keywords": []}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "NicInterface", "value": {"_type": "Name", "_fields": {"id": "otypes", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "test": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "interface"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "params", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_module", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "keywords": []}}, "orelse": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}}}, {"_type": "keyword", "_fields": {"arg": "vnic_profile", "value": {"_type": "IfExp", "_fields": {"body": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "VnicProfile", "value": {"_type": "Name", "_fields": {"id": "otypes", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "id", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "vnic_id", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}]}}, "test": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "vnic_id", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "orelse": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}}}, {"_type": "keyword", "_fields": {"arg": "mac", "value": {"_type": "IfExp", "_fields": {"body": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "Mac", "value": {"_type": "Name", "_fields": {"id": "otypes", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "address", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "mac_address"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "params", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_module", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "keywords": []}}}}]}}, "test": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "mac_address"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "params", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_module", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "keywords": []}}, "orelse": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}}}, {"_type": "keyword", "_fields": {"arg": "linked", "value": {"_type": "IfExp", "_fields": {"body": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "linked"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "param", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "IsNot", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "linked"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "param", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}]}}, "orelse": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}}}]}}}}], "name": "build_entity", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def build_entity(self): return otypes.Nic( id=self._module.params.get('id'), name=self._module.params.get('name'), interface=otypes.NicInterface( self._module.params.get('interface') ) if self._module.params.get('interface') else None, vnic_profile=otypes.VnicProfile( id=self.vnic_id, ) if self.vnic_id else None, mac=otypes.Mac( address=self._module.params.get('mac_address') ) if self._module.params.get('mac_address') else None, linked=self.param('linked') if self.param('linked') is not None else None, )
10,981
[ -0.009187007322907448, 0.023308679461479187, -0.02343052439391613, 0.010180032812058926, -0.0000023143143152992707, 0.06004452332854271, 0.023503629490733147, 0.002621160354465246, 0.012525522150099277, 0.039550431072711945, -0.023004071786999702, -0.06160412356257439, 0.005208813585340977, ...
13
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "entity", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": {"_type": "BoolOp", "_fields": {"op": {"_type": "And", "_fields": {}}, "values": [{"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "interface"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "params", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_module", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "keywords": []}}, {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "interface", "value": {"_type": "Name", "_fields": {"id": "entity", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "str", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "linked"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "params", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_module", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "keywords": []}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "linked", "value": {"_type": "Name", "_fields": {"id": "entity", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "name"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "params", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_module", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "keywords": []}}, {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "name", "value": {"_type": "Name", "_fields": {"id": "entity", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "str", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "profile"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "params", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_module", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "keywords": []}}, {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_connection", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "vnic_profile", "value": {"_type": "Name", "_fields": {"id": "entity", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "get_link_name", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "mac_address"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "params", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_module", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "keywords": []}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "address", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "mac", "value": {"_type": "Name", "_fields": {"id": "entity", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "func": {"_type": "Name", "_fields": {"id": "equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}]}}}}], "test": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "vm"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "params", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_module", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "keywords": []}}, "orelse": [{"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": {"_type": "BoolOp", "_fields": {"op": {"_type": "And", "_fields": {}}, "values": [{"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "interface"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "params", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_module", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "keywords": []}}, {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "interface", "value": {"_type": "Name", "_fields": {"id": "entity", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "str", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "linked"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "params", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_module", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "keywords": []}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "linked", "value": {"_type": "Name", "_fields": {"id": "entity", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "name"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "params", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_module", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "keywords": []}}, {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "name", "value": {"_type": "Name", "_fields": {"id": "entity", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "str", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "profile"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "params", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_module", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "keywords": []}}, {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_connection", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "vnic_profile", "value": {"_type": "Name", "_fields": {"id": "entity", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "get_link_name", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "equal", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}]}}}}], "test": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "template"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "params", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_module", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "keywords": []}}, "orelse": []}}]}}], "name": "update_check", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def update_check(self, entity): if self._module.params.get('vm'): return ( equal(self._module.params.get('interface'), str(entity.interface)) and equal(self._module.params.get('linked'), entity.linked) and equal(self._module.params.get('name'), str(entity.name)) and equal(self._module.params.get('profile'), get_link_name(self._connection, entity.vnic_profile)) and equal(self._module.params.get('mac_address'), entity.mac.address) ) elif self._module.params.get('template'): return ( equal(self._module.params.get('interface'), str(entity.interface)) and equal(self._module.params.get('linked'), entity.linked) and equal(self._module.params.get('name'), str(entity.name)) and equal(self._module.params.get('profile'), get_link_name(self._connection, entity.vnic_profile)) )
10,982
[ 0.007291113492101431, 0.03858834132552147, -0.048979420214891434, -0.03152042627334595, -0.02936285175383091, 0.037844352424144745, -0.0303796399384737, 0.014148232527077198, 0.023472921922802925, 0.045805055648088455, 0.0441930778324604, -0.02262973226606846, 0.0524761788547039, 0.0015383...
15
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "ovirt_full_argument_spec", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "state", "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "dict", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "type", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "str"}}}}, {"_type": "keyword", "_fields": {"arg": "default", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "present"}}}}, {"_type": "keyword", "_fields": {"arg": "choices", "value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "absent"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "plugged"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "present"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "unplugged"}}]}}}}]}}}}, {"_type": "keyword", "_fields": {"arg": "vm", "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "dict", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "type", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "str"}}}}]}}}}, {"_type": "keyword", "_fields": {"arg": "id", "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "dict", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "default", "value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}]}}}}, {"_type": "keyword", "_fields": {"arg": "template", "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "dict", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "type", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "str"}}}}]}}}}, {"_type": "keyword", "_fields": {"arg": "name", "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "dict", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "type", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "str"}}}}, {"_type": "keyword", "_fields": {"arg": "required", "value": {"_type": "Constant", "_fields": {"kind": null, "value": true}}}}]}}}}, {"_type": "keyword", "_fields": {"arg": "interface", "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "dict", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "type", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "str"}}}}]}}}}, {"_type": "keyword", "_fields": {"arg": "profile", "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "dict", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "type", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "str"}}}}]}}}}, {"_type": "keyword", "_fields": {"arg": "network", "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "dict", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "type", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "str"}}}}]}}}}, {"_type": "keyword", "_fields": {"arg": "mac_address", "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "dict", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "type", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "str"}}}}]}}}}, {"_type": "keyword", "_fields": {"arg": "linked", "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "dict", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "type", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "bool"}}}}]}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "argument_spec", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "AnsibleModule", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "argument_spec", "value": {"_type": "Name", "_fields": {"id": "argument_spec", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "keyword", "_fields": {"arg": "supports_check_mode", "value": {"_type": "Constant", "_fields": {"kind": null, "value": true}}}}, {"_type": "keyword", "_fields": {"arg": "required_one_of", "value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Constant", "_fields": {"kind": null, "value": "vm"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "template"}}]}}]}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "module", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "module", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "check_sdk", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "Try", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "auth"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "pop", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "params", "value": {"_type": "Name", "_fields": {"id": "module", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "auth", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "auth", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "create_connection", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "connection", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}, "targets": [{"_type": "Name", "_fields": {"id": "entity_name", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "vm"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "params", "value": {"_type": "Name", "_fields": {"id": "module", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "entity_name", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "vms_service", "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "system_service", "value": {"_type": "Name", "_fields": {"id": "connection", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "collection_service", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "test": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "vm"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "params", "value": {"_type": "Name", "_fields": {"id": "module", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, "orelse": [{"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "template"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "params", "value": {"_type": "Name", "_fields": {"id": "module", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "entity_name", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "templates_service", "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "system_service", "value": {"_type": "Name", "_fields": {"id": "connection", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "collection_service", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "test": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "template"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "params", "value": {"_type": "Name", "_fields": {"id": "module", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, "orelse": []}}]}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "collection_service", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "entity_name", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "search_by_name", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "entity", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Raise", "_fields": {"exc": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "Vm/Template '%s' was not found."}}, "right": {"_type": "Name", "_fields": {"id": "entity_name", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "Exception", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "cause": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Is", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "entity", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}]}}, "orelse": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "id", "value": {"_type": "Name", "_fields": {"id": "entity", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "service", "value": {"_type": "Name", "_fields": {"id": "collection_service", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "service", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "cluster", "value": {"_type": "Name", "_fields": {"id": "entity", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "cluster_id", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "nics_service", "value": {"_type": "Name", "_fields": {"id": "service", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "nics_service", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "EntityNicsModule", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "connection", "value": {"_type": "Name", "_fields": {"id": "connection", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "keyword", "_fields": {"arg": "module", "value": {"_type": "Name", "_fields": {"id": "module", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "keyword", "_fields": {"arg": "service", "value": {"_type": "Name", "_fields": {"id": "nics_service", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "entitynics_module", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "profile"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "params", "value": {"_type": "Name", "_fields": {"id": "module", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "profile", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "connection", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "cluster_id", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "get_link_name", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "cluster_name", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "data_centers_service", "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "system_service", "value": {"_type": "Name", "_fields": {"id": "connection", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "dcs_service", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "list", "value": {"_type": "Name", "_fields": {"id": "dcs_service", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "search", "value": {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "Clusters.name=%s"}}, "right": {"_type": "Name", "_fields": {"id": "cluster_name", "ctx": {"_type": "Load", "_fields": {}}}}}}}}]}}}}, "targets": [{"_type": "Name", "_fields": {"id": "dc", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "networks_service", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "id", "value": {"_type": "Name", "_fields": {"id": "dc", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "service", "value": {"_type": "Name", "_fields": {"id": "dcs_service", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "networks_service", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "GeneratorExp", "_fields": {"elt": {"_type": "Name", "_fields": {"id": "n", "ctx": {"_type": "Load", "_fields": {}}}}, "generators": [{"_type": "comprehension", "_fields": {"ifs": [{"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "name", "value": {"_type": "Name", "_fields": {"id": "n", "ctx": {"_type": "Load", "_fields": {}}}}}}, "comparators": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "network"}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "params", "value": {"_type": "Name", "_fields": {"id": "module", "ctx": {"_type": "Load", "_fields": {}}}}}}}}]}}], "iter": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "list", "value": {"_type": "Name", "_fields": {"id": "networks_service", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "target": {"_type": "Name", "_fields": {"id": "n", "ctx": {"_type": "Store", "_fields": {}}}}, "is_async": 0}}]}}, {"_type": "Constant", "_fields": {"kind": null, "value": null}}], "func": {"_type": "Name", "_fields": {"id": "next", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "network", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Raise", "_fields": {"exc": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "Network '%s' was not found in datacenter '%s'."}}, "right": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "network"}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "params", "value": {"_type": "Name", "_fields": {"id": "module", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "name", "value": {"_type": "Name", "_fields": {"id": "dc", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}], "func": {"_type": "Name", "_fields": {"id": "Exception", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "cause": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Is", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "network", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}]}}, "orelse": []}}, {"_type": "If", "_fields": {"body": [{"_type": "For", "_fields": {"body": [{"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "id", "value": {"_type": "Name", "_fields": {"id": "vnic", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "vnic_id", "value": {"_type": "Name", "_fields": {"id": "entitynics_module", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "test": {"_type": "BoolOp", "_fields": {"op": {"_type": "And", "_fields": {}}, "values": [{"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "name", "value": {"_type": "Name", "_fields": {"id": "vnic", "ctx": {"_type": "Load", "_fields": {}}}}}}, "comparators": [{"_type": "Name", "_fields": {"id": "profile", "ctx": {"_type": "Load", "_fields": {}}}}]}}, {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "id", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "network", "value": {"_type": "Name", "_fields": {"id": "vnic", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "comparators": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "id", "value": {"_type": "Name", "_fields": {"id": "network", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}]}}, "orelse": []}}], "iter": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "list", "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "vnic_profiles_service", "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "system_service", "value": {"_type": "Name", "_fields": {"id": "connection", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, "keywords": []}}}}, "keywords": []}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "vnic", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}], "test": {"_type": "Name", "_fields": {"id": "profile", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "networks_service", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "network", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "connection", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "get_vnics", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "vnics", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "id", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "value": {"_type": "Name", "_fields": {"id": "vnics", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "vnic_id", "value": {"_type": "Name", "_fields": {"id": "entitynics_module", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "vnics", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}]}}, "orelse": [{"_type": "Raise", "_fields": {"exc": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "You didn't specify any vnic profile. Following vnic profiles are in system: '%s', please specify one of them"}}, "right": {"_type": "ListComp", "_fields": {"elt": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "name", "value": {"_type": "Name", "_fields": {"id": "vnic", "ctx": {"_type": "Load", "_fields": {}}}}}}, "generators": [{"_type": "comprehension", "_fields": {"ifs": [], "iter": {"_type": "Name", "_fields": {"id": "vnics", "ctx": {"_type": "Load", "_fields": {}}}}, "target": {"_type": "Name", "_fields": {"id": "vnic", "ctx": {"_type": "Store", "_fields": {}}}}, "is_async": 0}}]}}}}], "func": {"_type": "Name", "_fields": {"id": "Exception", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "cause": null}}]}}]}}], "test": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "network"}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "params", "value": {"_type": "Name", "_fields": {"id": "module", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "orelse": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "state"}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "params", "value": {"_type": "Name", "_fields": {"id": "module", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "state", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "create", "value": {"_type": "Name", "_fields": {"id": "entitynics_module", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "ret", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "state", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": "present"}}]}}, "orelse": [{"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "remove", "value": {"_type": "Name", "_fields": {"id": "entitynics_module", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "ret", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "state", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": "absent"}}]}}, "orelse": [{"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "create", "value": {"_type": "Name", "_fields": {"id": "entitynics_module", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "action", "value": {"_type": "Name", "_fields": {"id": "entitynics_module", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "action", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "activate"}}}}, {"_type": "keyword", "_fields": {"arg": "action_condition", "value": {"_type": "Lambda", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "nic", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": {"_type": "UnaryOp", "_fields": {"op": {"_type": "Not", "_fields": {}}, "operand": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "plugged", "value": {"_type": "Name", "_fields": {"id": "nic", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}}}, {"_type": "keyword", "_fields": {"arg": "wait_condition", "value": {"_type": "Lambda", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "nic", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "plugged", "value": {"_type": "Name", "_fields": {"id": "nic", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "ret", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "state", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": "plugged"}}]}}, "orelse": [{"_type": "If", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "create", "value": {"_type": "Name", "_fields": {"id": "entitynics_module", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "action", "value": {"_type": "Name", "_fields": {"id": "entitynics_module", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "action", "value": {"_type": "Constant", "_fields": {"kind": null, "value": "deactivate"}}}}, {"_type": "keyword", "_fields": {"arg": "action_condition", "value": {"_type": "Lambda", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "nic", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "plugged", "value": {"_type": "Name", "_fields": {"id": "nic", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, {"_type": "keyword", "_fields": {"arg": "wait_condition", "value": {"_type": "Lambda", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "nic", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": {"_type": "UnaryOp", "_fields": {"op": {"_type": "Not", "_fields": {}}, "operand": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "plugged", "value": {"_type": "Name", "_fields": {"id": "nic", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "ret", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "state", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": "unplugged"}}]}}, "orelse": []}}]}}]}}]}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "exit_json", "value": {"_type": "Name", "_fields": {"id": "module", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": null, "value": {"_type": "Name", "_fields": {"id": "ret", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}], "orelse": [], "handlers": [{"_type": "ExceptHandler", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "fail_json", "value": {"_type": "Name", "_fields": {"id": "module", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "msg", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "e", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "str", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, {"_type": "keyword", "_fields": {"arg": "exception", "value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "format_exc", "value": {"_type": "Name", "_fields": {"id": "traceback", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}]}}}}], "name": "e", "type": {"_type": "Name", "_fields": {"id": "Exception", "ctx": {"_type": "Load", "_fields": {}}}}}}], "finalbody": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "close", "value": {"_type": "Name", "_fields": {"id": "connection", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "logout", "value": {"_type": "Compare", "_fields": {"ops": [{"_type": "Is", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "token"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get", "value": {"_type": "Name", "_fields": {"id": "auth", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}]}}}}]}}}}]}}], "name": "main", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def main(): argument_spec = ovirt_full_argument_spec( state=dict(type='str', default='present', choices=['absent', 'plugged', 'present', 'unplugged']), vm=dict(type='str'), id=dict(default=None), template=dict(type='str'), name=dict(type='str', required=True), interface=dict(type='str'), profile=dict(type='str'), network=dict(type='str'), mac_address=dict(type='str'), linked=dict(type='bool'), ) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, required_one_of=[['vm', 'template']], ) check_sdk(module) try: # Locate the service that manages the virtual machines and use it to # search for the NIC: auth = module.params.pop('auth') connection = create_connection(auth) entity_name = None if module.params.get('vm'): # Locate the VM, where we will manage NICs: entity_name = module.params.get('vm') collection_service = connection.system_service().vms_service() elif module.params.get('template'): entity_name = module.params.get('template') collection_service = connection.system_service().templates_service() # TODO: We have to modify the search_by_name function to accept raise_error=True/False, entity = search_by_name(collection_service, entity_name) if entity is None: raise Exception("Vm/Template '%s' was not found." % entity_name) service = collection_service.service(entity.id) cluster_id = entity.cluster nics_service = service.nics_service() entitynics_module = EntityNicsModule( connection=connection, module=module, service=nics_service, ) # Find vNIC id of the network interface (if any): if module.params['network']: profile = module.params.get('profile') cluster_name = get_link_name(connection, cluster_id) dcs_service = connection.system_service().data_centers_service() dc = dcs_service.list(search='Clusters.name=%s' % cluster_name)[0] networks_service = dcs_service.service(dc.id).networks_service() network = next( (n for n in networks_service.list() if n.name == module.params['network']), None ) if network is None: raise Exception( "Network '%s' was not found in datacenter '%s'." % ( module.params['network'], dc.name ) ) if profile: for vnic in connection.system_service().vnic_profiles_service().list(): if vnic.name == profile and vnic.network.id == network.id: entitynics_module.vnic_id = vnic.id else: # When not specified which vnic use ovirtmgmt/ovirtmgmt vnics = get_vnics(networks_service, network, connection) if len(vnics) == 1: entitynics_module.vnic_id = vnics[0].id else: raise Exception( "You didn't specify any vnic profile. " "Following vnic profiles are in system: '%s', please specify one of them" % ([vnic.name for vnic in vnics]) ) # Handle appropriate action: state = module.params['state'] if state == 'present': ret = entitynics_module.create() elif state == 'absent': ret = entitynics_module.remove() elif state == 'plugged': entitynics_module.create() ret = entitynics_module.action( action='activate', action_condition=lambda nic: not nic.plugged, wait_condition=lambda nic: nic.plugged, ) elif state == 'unplugged': entitynics_module.create() ret = entitynics_module.action( action='deactivate', action_condition=lambda nic: nic.plugged, wait_condition=lambda nic: not nic.plugged, ) module.exit_json(**ret) except Exception as e: module.fail_json(msg=str(e), exception=traceback.format_exc()) finally: connection.close(logout=auth.get('token') is None)
10,983
[ 0.021391594782471657, 0.004353320226073265, 0.04682672396302223, -0.0009953939588740468, -0.023009007796645164, -0.01540455687791109, 0.00133045285474509, 0.01972200721502304, 0.03336567059159279, -0.018743732944130898, 0.02362206019461155, -0.013063221238553524, 0.0023364447988569736, 0.0...
9
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "client_info", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Dict", "_fields": {"keys": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "set_iam_policy", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get_iam_policy", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "test_iam_permissions", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get_vulnerability_occurrences_summary", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "values": [{"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "set_iam_policy", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "wrap_method", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "method", "value": {"_type": "Name", "_fields": {"id": "gapic_v1", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "default_timeout", "value": {"_type": "Constant", "_fields": {"kind": null, "value": 30.0}}}}, {"_type": "keyword", "_fields": {"arg": "client_info", "value": {"_type": "Name", "_fields": {"id": "client_info", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get_iam_policy", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "wrap_method", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "method", "value": {"_type": "Name", "_fields": {"id": "gapic_v1", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "default_timeout", "value": {"_type": "Constant", "_fields": {"kind": null, "value": 30.0}}}}, {"_type": "keyword", "_fields": {"arg": "client_info", "value": {"_type": "Name", "_fields": {"id": "client_info", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "test_iam_permissions", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "wrap_method", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "method", "value": {"_type": "Name", "_fields": {"id": "gapic_v1", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "default_timeout", "value": {"_type": "Constant", "_fields": {"kind": null, "value": 30.0}}}}, {"_type": "keyword", "_fields": {"arg": "client_info", "value": {"_type": "Name", "_fields": {"id": "client_info", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get_vulnerability_occurrences_summary", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "wrap_method", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "method", "value": {"_type": "Name", "_fields": {"id": "gapic_v1", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "default_timeout", "value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}, {"_type": "keyword", "_fields": {"arg": "client_info", "value": {"_type": "Name", "_fields": {"id": "client_info", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}]}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "_wrapped_methods", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "name": "_prep_wrapped_messages", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { self.set_iam_policy: gapic_v1.method.wrap_method( self.set_iam_policy, default_timeout=30.0, client_info=client_info, ), self.get_iam_policy: gapic_v1.method.wrap_method( self.get_iam_policy, default_timeout=30.0, client_info=client_info, ), self.test_iam_permissions: gapic_v1.method.wrap_method( self.test_iam_permissions, default_timeout=30.0, client_info=client_info, ), self.get_vulnerability_occurrences_summary: gapic_v1.method.wrap_method( self.get_vulnerability_occurrences_summary, default_timeout=None, client_info=client_info, ), }
10,984
[ 0.01595897786319256, -0.004576815292239189, 0.04740961268544197, -0.029698185622692108, -0.007056531962007284, -0.03649769350886345, 0.02602972462773323, 0.025211913511157036, 0.003595443209633231, -0.002345362212508917, 0.017092229798436165, 0.0024578110314905643, -0.0014720580074936152, ...
9
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "ListComp", "_fields": {"elt": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Slice", "_fields": {"step": null, "lower": null, "upper": {"_type": "UnaryOp", "_fields": {"op": {"_type": "USub", "_fields": {}}, "operand": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}}}}}, "value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "|"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "split", "value": {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, "generators": [{"_type": "comprehension", "_fields": {"ifs": [], "iter": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "splitlines", "value": {"_type": "Name", "_fields": {"id": "data", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "target": {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Store", "_fields": {}}}}, "is_async": 0}}]}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "data", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "ListComp", "_fields": {"elt": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Slice", "_fields": {"step": null, "lower": null, "upper": {"_type": "UnaryOp", "_fields": {"op": {"_type": "USub", "_fields": {}}, "operand": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}}}}}, "value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "|"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "split", "value": {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, "generators": [{"_type": "comprehension", "_fields": {"ifs": [], "iter": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "splitlines", "value": {"_type": "Name", "_fields": {"id": "posix_data", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "target": {"_type": "Name", "_fields": {"id": "x", "ctx": {"_type": "Store", "_fields": {}}}}, "is_async": 0}}]}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "posix_data", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}, {"_type": "For", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "\\n"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "\n"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "replace", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "value": {"_type": "Name", "_fields": {"id": "item", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, "targets": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "value": {"_type": "Name", "_fields": {"id": "item", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "iter": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "data", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "item", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}, {"_type": "For", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "\\n"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "\n"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "replace", "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "value": {"_type": "Name", "_fields": {"id": "item", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, "targets": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, "value": {"_type": "Name", "_fields": {"id": "item", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "iter": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "posix_data", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "item", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}], "name": "setUp", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def setUp(self): self.data = [x.split("|")[:-1] for x in data.splitlines()] self.posix_data = [x.split("|")[:-1] for x in posix_data.splitlines()] for item in self.data: item[0] = item[0].replace(r"\n", "\n") for item in self.posix_data: item[0] = item[0].replace(r"\n", "\n")
10,985
[ 0.03775130212306976, -0.02429194003343582, -0.01634185016155243, -0.0049048797227442265, 0.023641055449843407, 0.015935048460960388, -0.028011281043291092, 0.04121493920683861, 0.03954123705625534, -0.002183659467846155, 0.012529526837170124, -0.008996154181659222, -0.010106144472956657, 0...
9
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "ascii_letters", "value": {"_type": "Name", "_fields": {"id": "string", "ctx": {"_type": "Load", "_fields": {}}}}}}, "right": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "digits", "value": {"_type": "Name", "_fields": {"id": "string", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": "@%_-+=:,./"}}}}, "targets": [{"_type": "Name", "_fields": {"id": "safeunquoted", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "éàß"}}, "targets": [{"_type": "Name", "_fields": {"id": "unicode_sample", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "\"`$\\!"}}, "right": {"_type": "Name", "_fields": {"id": "unicode_sample", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "unsafe", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": ""}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "quote", "value": {"_type": "Name", "_fields": {"id": "shlex", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, {"_type": "Constant", "_fields": {"kind": null, "value": "''"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertEqual", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "safeunquoted", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "quote", "value": {"_type": "Name", "_fields": {"id": "shlex", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, {"_type": "Name", "_fields": {"id": "safeunquoted", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertEqual", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "test file name"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "quote", "value": {"_type": "Name", "_fields": {"id": "shlex", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, {"_type": "Constant", "_fields": {"kind": null, "value": "'test file name'"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertEqual", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "For", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "test%sname"}}, "right": {"_type": "Name", "_fields": {"id": "u", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "quote", "value": {"_type": "Name", "_fields": {"id": "shlex", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "'test%sname'"}}, "right": {"_type": "Name", "_fields": {"id": "u", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertEqual", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "iter": {"_type": "Name", "_fields": {"id": "unsafe", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "u", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}, {"_type": "For", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "test%s'name'"}}, "right": {"_type": "Name", "_fields": {"id": "u", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "quote", "value": {"_type": "Name", "_fields": {"id": "shlex", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "'test%s'\"'\"'name'\"'\"''"}}, "right": {"_type": "Name", "_fields": {"id": "u", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "assertEqual", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}], "iter": {"_type": "Name", "_fields": {"id": "unsafe", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": [], "target": {"_type": "Name", "_fields": {"id": "u", "ctx": {"_type": "Store", "_fields": {}}}}, "type_comment": null}}], "name": "testQuote", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def testQuote(self): safeunquoted = string.ascii_letters + string.digits + '@%_-+=:,./' unicode_sample = '\xe9\xe0\xdf' # e + acute accent, a + grave, sharp s unsafe = '"`$\\!' + unicode_sample self.assertEqual(shlex.quote(''), "''") self.assertEqual(shlex.quote(safeunquoted), safeunquoted) self.assertEqual(shlex.quote('test file name'), "'test file name'") for u in unsafe: self.assertEqual(shlex.quote('test%sname' % u), "'test%sname'" % u) for u in unsafe: self.assertEqual(shlex.quote("test%s'name'" % u), "'test%s'\"'\"'name'\"'\"''" % u)
10,986
[ 0.01641729287803173, 0.0010446524247527122, 0.006413391791284084, -0.04254133999347687, -0.003547175321727991, -0.0273126307874918, -0.03449364751577377, 0.05447668954730034, -0.004138370975852013, 0.005788148380815983, 0.0013595958007499576, -0.06344058364629745, 0.008821508847177029, 0.0...
8
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "s", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "List", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": []}}, "targets": [{"_type": "Name", "_fields": {"id": "ret", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "s", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "StringIO", "value": {"_type": "Name", "_fields": {"id": "io", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "shlex", "value": {"_type": "Name", "_fields": {"id": "shlex", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "lex", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get_token", "value": {"_type": "Name", "_fields": {"id": "lex", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "tok", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "While", "_fields": {"body": [{"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "tok", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "append", "value": {"_type": "Name", "_fields": {"id": "ret", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get_token", "value": {"_type": "Name", "_fields": {"id": "lex", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "tok", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}], "test": {"_type": "Name", "_fields": {"id": "tok", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": []}}, {"_type": "Return", "_fields": {"value": {"_type": "Name", "_fields": {"id": "ret", "ctx": {"_type": "Load", "_fields": {}}}}}}], "name": "oldSplit", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def oldSplit(self, s): ret = [] lex = shlex.shlex(io.StringIO(s)) tok = lex.get_token() while tok: ret.append(tok) tok = lex.get_token() return ret
10,987
[ -0.011294838041067123, 0.010855350643396378, 0.030789263546466827, 0.03952879458665848, -0.040282201021909714, 0.0025082200299948454, 0.026745975017547607, 0.03425493836402893, -0.00011448266741354018, 0.001787773915566504, 0.014754235744476318, -0.0194504763931036, -0.05660603567957878, 0...
11
{"_type": "Module", "_fields": {"body": [{"_type": "ClassDef", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "form", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "now", "value": {"_type": "Name", "_fields": {"id": "timezone", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "now", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Sub", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "now", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "last_posted_on", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "user", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "previous_post", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Raise", "_fields": {"exc": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "You can't post message so quickly after previous one."}}], "func": {"_type": "Name", "_fields": {"id": "_", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "PostingInterrupt", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "cause": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Lt", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "total_seconds", "value": {"_type": "Name", "_fields": {"id": "previous_post", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "comparators": [{"_type": "Name", "_fields": {"id": "MIN_POSTING_PAUSE", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": []}}], "test": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "last_posted_on", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "user", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "orelse": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "now", "value": {"_type": "Name", "_fields": {"id": "timezone", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "last_posted_on", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "user", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "last_posted_on"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "append", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "update_fields", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "user", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "keywords": []}}}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Sub", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "now", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "timedelta", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "hours", "value": {"_type": "Constant", "_fields": {"kind": null, "value": 24}}}}]}}}}, "targets": [{"_type": "Name", "_fields": {"id": "cutoff", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "filter", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "post_set", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "user", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "posted_on__gte", "value": {"_type": "Name", "_fields": {"id": "cutoff", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "count_qs", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "count", "value": {"_type": "Name", "_fields": {"id": "count_qs", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "posts_count", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Raise", "_fields": {"exc": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Your account has excceed hourly post limit."}}], "func": {"_type": "Name", "_fields": {"id": "_", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "PostingInterrupt", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "cause": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Gt", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "posts_count", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "MISAGO_HOURLY_POST_LIMIT", "value": {"_type": "Name", "_fields": {"id": "settings", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "orelse": []}}], "test": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "MISAGO_HOURLY_POST_LIMIT", "value": {"_type": "Name", "_fields": {"id": "settings", "ctx": {"_type": "Load", "_fields": {}}}}}}, "orelse": []}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Sub", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "now", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "timedelta", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "hours", "value": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}}}]}}}}, "targets": [{"_type": "Name", "_fields": {"id": "cutoff", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "filter", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "post_set", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "user", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "posted_on__gte", "value": {"_type": "Name", "_fields": {"id": "cutoff", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "count_qs", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "count", "value": {"_type": "Name", "_fields": {"id": "count_qs", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "posts_count", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Raise", "_fields": {"exc": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Your account has excceed dialy post limit."}}], "func": {"_type": "Name", "_fields": {"id": "_", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "PostingInterrupt", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "cause": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Gt", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "posts_count", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "MISAGO_DIALY_POST_LIMIT", "value": {"_type": "Name", "_fields": {"id": "settings", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "orelse": []}}], "test": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "MISAGO_DIALY_POST_LIMIT", "value": {"_type": "Name", "_fields": {"id": "settings", "ctx": {"_type": "Load", "_fields": {}}}}}}, "orelse": []}}], "name": "interrupt_posting", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "name": "FloodProtectionMiddleware", "bases": [{"_type": "Name", "_fields": {"id": "PostingMiddleware", "ctx": {"_type": "Load", "_fields": {}}}}], "keywords": [], "type_params": [], "decorator_list": []}}], "type_ignores": []}}
class FloodProtectionMiddleware(PostingMiddleware): def interrupt_posting(self, form): now = timezone.now() if self.user.last_posted_on: previous_post = now - self.user.last_posted_on if previous_post.total_seconds() < MIN_POSTING_PAUSE: raise PostingInterrupt(_("You can't post message so " "quickly after previous one.")) self.user.last_posted_on = timezone.now() self.user.update_fields.append('last_posted_on') if settings.MISAGO_HOURLY_POST_LIMIT: cutoff = now - timedelta(hours=24) count_qs = self.user.post_set.filter(posted_on__gte=cutoff) posts_count = count_qs.count() if posts_count > settings.MISAGO_HOURLY_POST_LIMIT: raise PostingInterrupt(_("Your account has excceed " "hourly post limit.")) if settings.MISAGO_DIALY_POST_LIMIT: cutoff = now - timedelta(hours=1) count_qs = self.user.post_set.filter(posted_on__gte=cutoff) posts_count = count_qs.count() if posts_count > settings.MISAGO_DIALY_POST_LIMIT: raise PostingInterrupt(_("Your account has excceed " "dialy post limit."))
10,988
[ -0.019813915714621544, -0.011641591787338257, 0.0035028608981519938, 0.02682574652135372, -0.015233016572892666, 0.00967485923320055, 0.05379807949066162, 0.0231610257178545, 0.002931775525212288, 0.016039256006479263, 0.025213269516825676, 0.012264594435691833, -0.030661486089229584, 0.00...
10
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "form", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "now", "value": {"_type": "Name", "_fields": {"id": "timezone", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "now", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Sub", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "now", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "last_posted_on", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "user", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "previous_post", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Raise", "_fields": {"exc": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "You can't post message so quickly after previous one."}}], "func": {"_type": "Name", "_fields": {"id": "_", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "PostingInterrupt", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "cause": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Lt", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "total_seconds", "value": {"_type": "Name", "_fields": {"id": "previous_post", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "comparators": [{"_type": "Name", "_fields": {"id": "MIN_POSTING_PAUSE", "ctx": {"_type": "Load", "_fields": {}}}}]}}, "orelse": []}}], "test": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "last_posted_on", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "user", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "orelse": []}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "now", "value": {"_type": "Name", "_fields": {"id": "timezone", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "last_posted_on", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "user", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "last_posted_on"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "append", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "update_fields", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "user", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "keywords": []}}}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Sub", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "now", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "timedelta", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "hours", "value": {"_type": "Constant", "_fields": {"kind": null, "value": 24}}}}]}}}}, "targets": [{"_type": "Name", "_fields": {"id": "cutoff", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "filter", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "post_set", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "user", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "posted_on__gte", "value": {"_type": "Name", "_fields": {"id": "cutoff", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "count_qs", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "count", "value": {"_type": "Name", "_fields": {"id": "count_qs", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "posts_count", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Raise", "_fields": {"exc": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Your account has excceed hourly post limit."}}], "func": {"_type": "Name", "_fields": {"id": "_", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "PostingInterrupt", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "cause": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Gt", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "posts_count", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "MISAGO_HOURLY_POST_LIMIT", "value": {"_type": "Name", "_fields": {"id": "settings", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "orelse": []}}], "test": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "MISAGO_HOURLY_POST_LIMIT", "value": {"_type": "Name", "_fields": {"id": "settings", "ctx": {"_type": "Load", "_fields": {}}}}}}, "orelse": []}}, {"_type": "If", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Sub", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "now", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Name", "_fields": {"id": "timedelta", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "hours", "value": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}}}]}}}}, "targets": [{"_type": "Name", "_fields": {"id": "cutoff", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "filter", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "post_set", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "user", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "posted_on__gte", "value": {"_type": "Name", "_fields": {"id": "cutoff", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "count_qs", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "count", "value": {"_type": "Name", "_fields": {"id": "count_qs", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "posts_count", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "Raise", "_fields": {"exc": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "Your account has excceed dialy post limit."}}], "func": {"_type": "Name", "_fields": {"id": "_", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}], "func": {"_type": "Name", "_fields": {"id": "PostingInterrupt", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "cause": null}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Gt", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "posts_count", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "MISAGO_DIALY_POST_LIMIT", "value": {"_type": "Name", "_fields": {"id": "settings", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "orelse": []}}], "test": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "MISAGO_DIALY_POST_LIMIT", "value": {"_type": "Name", "_fields": {"id": "settings", "ctx": {"_type": "Load", "_fields": {}}}}}}, "orelse": []}}], "name": "interrupt_posting", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def interrupt_posting(self, form): now = timezone.now() if self.user.last_posted_on: previous_post = now - self.user.last_posted_on if previous_post.total_seconds() < MIN_POSTING_PAUSE: raise PostingInterrupt(_("You can't post message so " "quickly after previous one.")) self.user.last_posted_on = timezone.now() self.user.update_fields.append('last_posted_on') if settings.MISAGO_HOURLY_POST_LIMIT: cutoff = now - timedelta(hours=24) count_qs = self.user.post_set.filter(posted_on__gte=cutoff) posts_count = count_qs.count() if posts_count > settings.MISAGO_HOURLY_POST_LIMIT: raise PostingInterrupt(_("Your account has excceed " "hourly post limit.")) if settings.MISAGO_DIALY_POST_LIMIT: cutoff = now - timedelta(hours=1) count_qs = self.user.post_set.filter(posted_on__gte=cutoff) posts_count = count_qs.count() if posts_count > settings.MISAGO_DIALY_POST_LIMIT: raise PostingInterrupt(_("Your account has excceed " "dialy post limit."))
10,989
[ 0.022238219156861305, -0.01892254874110222, 0.03015781193971634, -0.004297699313610792, 0.036936983466148376, -0.0030754422768950462, 0.04832008108496666, 0.006525745149701834, -0.009360959753394127, -0.022681716829538345, 0.01444533932954073, -0.026947736740112305, 0.02074933610856533, -0...
12
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "dialect", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "datetime", "value": {"_type": "Name", "_fields": {"id": "datetime", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "datetime_datetime", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "date", "value": {"_type": "Name", "_fields": {"id": "datetime", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "datetime_date", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_storage_format", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "format", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "value", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Is", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}]}}, "orelse": [{"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "format", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "year"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "month"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "day"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "hour"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "minute"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "second"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "microsecond"}}], "values": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "year", "value": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "month", "value": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "day", "value": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "hour", "value": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "minute", "value": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "second", "value": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "microsecond", "value": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}}}], "test": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "datetime_datetime", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "isinstance", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [{"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "format", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "year"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "month"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "day"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "hour"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "minute"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "second"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "microsecond"}}], "values": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "year", "value": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "month", "value": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "day", "value": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, {"_type": "Constant", "_fields": {"kind": null, "value": 0}}]}}}}}}], "test": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "datetime_date", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "isinstance", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [{"_type": "Raise", "_fields": {"exc": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "SQLite DateTime type only accepts Python datetime and date objects as input."}}], "func": {"_type": "Name", "_fields": {"id": "TypeError", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "cause": null}}]}}]}}]}}], "name": "process", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "Return", "_fields": {"value": {"_type": "Name", "_fields": {"id": "process", "ctx": {"_type": "Load", "_fields": {}}}}}}], "name": "bind_processor", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def bind_processor(self, dialect): datetime_datetime = datetime.datetime datetime_date = datetime.date format = self._storage_format def process(value): if value is None: return None elif isinstance(value, datetime_datetime): return format % { 'year': value.year, 'month': value.month, 'day': value.day, 'hour': value.hour, 'minute': value.minute, 'second': value.second, 'microsecond': value.microsecond, } elif isinstance(value, datetime_date): return format % { 'year': value.year, 'month': value.month, 'day': value.day, 'hour': 0, 'minute': 0, 'second': 0, 'microsecond': 0, } else: raise TypeError("SQLite DateTime type only accepts Python " "datetime and date objects as input.") return process
10,990
[ 0.009196490049362183, 0.04137662053108215, 0.03249864652752876, -0.018544653430581093, 0.011153082363307476, 0.03357047215104103, 0.04327759891748428, -0.019151348620653152, -0.034925427287817, 0.050921957939863205, 0.01231591496616602, -0.0002598994178697467, -0.01231591496616602, -0.0327...
8
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": {"_type": "arg", "_fields": {"arg": "kwargs", "annotation": null, "type_comment": null}}, "vararg": {"_type": "arg", "_fields": {"arg": "args", "annotation": null, "type_comment": null}}, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "truncate_microseconds"}}, {"_type": "Constant", "_fields": {"kind": null, "value": false}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "pop", "value": {"_type": "Name", "_fields": {"id": "kwargs", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "truncate_microseconds", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Starred", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "value": {"_type": "Name", "_fields": {"id": "args", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "__init__", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "DATETIME", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "super", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": null, "value": {"_type": "Name", "_fields": {"id": "kwargs", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}, {"_type": "If", "_fields": {"body": [{"_type": "Assert", "_fields": {"msg": {"_type": "Constant", "_fields": {"kind": null, "value": "You can specify only one of truncate_microseconds or storage_format."}}, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "NotIn", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "storage_format"}}, "comparators": [{"_type": "Name", "_fields": {"id": "kwargs", "ctx": {"_type": "Load", "_fields": {}}}}]}}}}, {"_type": "Assert", "_fields": {"msg": {"_type": "Constant", "_fields": {"kind": null, "value": "You can specify only one of truncate_microseconds or regexp."}}, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "NotIn", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "regexp"}}, "comparators": [{"_type": "Name", "_fields": {"id": "kwargs", "ctx": {"_type": "Load", "_fields": {}}}}]}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "%(year)04d-%(month)02d-%(day)02d %(hour)02d:%(minute)02d:%(second)02d"}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "_storage_format", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "test": {"_type": "Name", "_fields": {"id": "truncate_microseconds", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": []}}], "name": "__init__", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def __init__(self, *args, **kwargs): truncate_microseconds = kwargs.pop('truncate_microseconds', False) super(DATETIME, self).__init__(*args, **kwargs) if truncate_microseconds: assert 'storage_format' not in kwargs, "You can specify only "\ "one of truncate_microseconds or storage_format." assert 'regexp' not in kwargs, "You can specify only one of "\ "truncate_microseconds or regexp." self._storage_format = ( "%(year)04d-%(month)02d-%(day)02d " "%(hour)02d:%(minute)02d:%(second)02d" )
10,991
[ 0.019328013062477112, -0.01535044889897108, 0.024651072919368744, -0.007159614469856024, 0.040011342614889145, -0.00495722284540534, 0.033627599477767944, 0.000776484259404242, -0.023413609713315964, -0.03794890269637108, 0.007557370699942112, -0.029797352850437164, 0.014859392307698727, -...
11
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "dialect", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "date", "value": {"_type": "Name", "_fields": {"id": "datetime", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "datetime_date", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_storage_format", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "format", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "value", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Is", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}]}}, "orelse": [{"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "format", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "year"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "month"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "day"}}], "values": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "year", "value": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "month", "value": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "day", "value": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}}}], "test": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "datetime_date", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "isinstance", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [{"_type": "Raise", "_fields": {"exc": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "SQLite Date type only accepts Python date objects as input."}}], "func": {"_type": "Name", "_fields": {"id": "TypeError", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "cause": null}}]}}]}}], "name": "process", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "Return", "_fields": {"value": {"_type": "Name", "_fields": {"id": "process", "ctx": {"_type": "Load", "_fields": {}}}}}}], "name": "bind_processor", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def bind_processor(self, dialect): datetime_date = datetime.date format = self._storage_format def process(value): if value is None: return None elif isinstance(value, datetime_date): return format % { 'year': value.year, 'month': value.month, 'day': value.day, } else: raise TypeError("SQLite Date type only accepts Python " "date objects as input.") return process
10,992
[ 0.017322571948170662, -0.009893760085105896, 0.00838955957442522, -0.035343870520591736, 0.029443521052598953, -0.015740735456347466, 0.028298387303948402, -0.002382460283115506, 0.008573945611715317, 0.018331842496991158, 0.01390658039599657, -0.014741169288754463, 0.028764205053448677, -...
11
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "value", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Is", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}]}}, "orelse": [{"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "format", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "year"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "month"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "day"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "hour"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "minute"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "second"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "microsecond"}}], "values": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "year", "value": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "month", "value": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "day", "value": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "hour", "value": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "minute", "value": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "second", "value": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "microsecond", "value": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}}}], "test": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "datetime_datetime", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "isinstance", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [{"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "format", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "year"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "month"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "day"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "hour"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "minute"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "second"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "microsecond"}}], "values": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "year", "value": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "month", "value": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "day", "value": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, {"_type": "Constant", "_fields": {"kind": null, "value": 0}}, {"_type": "Constant", "_fields": {"kind": null, "value": 0}}]}}}}}}], "test": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "datetime_date", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "isinstance", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [{"_type": "Raise", "_fields": {"exc": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "SQLite DateTime type only accepts Python datetime and date objects as input."}}], "func": {"_type": "Name", "_fields": {"id": "TypeError", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "cause": null}}]}}]}}]}}], "name": "process", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def process(value): if value is None: return None elif isinstance(value, datetime_datetime): return format % { 'year': value.year, 'month': value.month, 'day': value.day, 'hour': value.hour, 'minute': value.minute, 'second': value.second, 'microsecond': value.microsecond, } elif isinstance(value, datetime_date): return format % { 'year': value.year, 'month': value.month, 'day': value.day, 'hour': 0, 'minute': 0, 'second': 0, 'microsecond': 0, } else: raise TypeError("SQLite DateTime type only accepts Python " "datetime and date objects as input.")
10,993
[ 0.01871197298169136, -0.006131783127784729, 0.009917880408465862, -0.036086101084947586, 0.03778070583939552, -0.02516929805278778, 0.024027671664953232, -0.0035006909165531397, -0.0056769163347780704, 0.0075320596806705, 0.015215741470456123, -0.016063041985034943, 0.026917414739727974, -...
10
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "value", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Is", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}]}}, "orelse": [{"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "format", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "year"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "month"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "day"}}], "values": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "year", "value": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "month", "value": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "day", "value": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}}}], "test": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "datetime_date", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "isinstance", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [{"_type": "Raise", "_fields": {"exc": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "SQLite Date type only accepts Python date objects as input."}}], "func": {"_type": "Name", "_fields": {"id": "TypeError", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "cause": null}}]}}]}}], "name": "process", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def process(value): if value is None: return None elif isinstance(value, datetime_date): return format % { 'year': value.year, 'month': value.month, 'day': value.day, } else: raise TypeError("SQLite Date type only accepts Python " "date objects as input.")
10,994
[ -0.0062987953424453735, 0.044139083474874496, 0.01892278529703617, -0.025089586153626442, 0.023716839030385017, 0.01605057716369629, 0.05545896664261818, 0.004936608020216227, -0.03602932021021843, 0.04641995579004288, -0.0062090386636555195, -0.006879572756588459, -0.017993541434407234, -...
8
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}], "kwarg": {"_type": "arg", "_fields": {"arg": "kwargs", "annotation": null, "type_comment": null}}, "vararg": {"_type": "arg", "_fields": {"arg": "args", "annotation": null, "type_comment": null}}, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "truncate_microseconds"}}, {"_type": "Constant", "_fields": {"kind": null, "value": false}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "pop", "value": {"_type": "Name", "_fields": {"id": "kwargs", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "truncate_microseconds", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Expr", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Starred", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "value": {"_type": "Name", "_fields": {"id": "args", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "__init__", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "TIME", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "super", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": null, "value": {"_type": "Name", "_fields": {"id": "kwargs", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}, {"_type": "If", "_fields": {"body": [{"_type": "Assert", "_fields": {"msg": {"_type": "Constant", "_fields": {"kind": null, "value": "You can specify only one of truncate_microseconds or storage_format."}}, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "NotIn", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "storage_format"}}, "comparators": [{"_type": "Name", "_fields": {"id": "kwargs", "ctx": {"_type": "Load", "_fields": {}}}}]}}}}, {"_type": "Assert", "_fields": {"msg": {"_type": "Constant", "_fields": {"kind": null, "value": "You can specify only one of truncate_microseconds or regexp."}}, "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "NotIn", "_fields": {}}], "left": {"_type": "Constant", "_fields": {"kind": null, "value": "regexp"}}, "comparators": [{"_type": "Name", "_fields": {"id": "kwargs", "ctx": {"_type": "Load", "_fields": {}}}}]}}}}, {"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "%(hour)02d:%(minute)02d:%(second)02d"}}, "targets": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Store", "_fields": {}}, "attr": "_storage_format", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}], "type_comment": null}}], "test": {"_type": "Name", "_fields": {"id": "truncate_microseconds", "ctx": {"_type": "Load", "_fields": {}}}}, "orelse": []}}], "name": "__init__", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def __init__(self, *args, **kwargs): truncate_microseconds = kwargs.pop('truncate_microseconds', False) super(TIME, self).__init__(*args, **kwargs) if truncate_microseconds: assert 'storage_format' not in kwargs, "You can specify only "\ "one of truncate_microseconds or storage_format." assert 'regexp' not in kwargs, "You can specify only one of "\ "truncate_microseconds or regexp." self._storage_format = "%(hour)02d:%(minute)02d:%(second)02d"
10,995
[ 0.026959897950291634, -0.011827895417809486, 0.009831241331994534, -0.003331979736685753, 0.030041029676795006, -0.009679211303591728, 0.04033849388360977, 0.0053565059788525105, -0.011199505999684334, -0.042892590165138245, 0.0069173420779407024, -0.021993601694703102, 0.022703072056174278,...
11
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "dialect", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "time", "value": {"_type": "Name", "_fields": {"id": "datetime", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "datetime_time", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_storage_format", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "format", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "value", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Is", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}]}}, "orelse": [{"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "format", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "hour"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "minute"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "second"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "microsecond"}}], "values": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "hour", "value": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "minute", "value": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "second", "value": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "microsecond", "value": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}}}], "test": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "datetime_time", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "isinstance", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [{"_type": "Raise", "_fields": {"exc": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "SQLite Time type only accepts Python time objects as input."}}], "func": {"_type": "Name", "_fields": {"id": "TypeError", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "cause": null}}]}}]}}], "name": "process", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "Return", "_fields": {"value": {"_type": "Name", "_fields": {"id": "process", "ctx": {"_type": "Load", "_fields": {}}}}}}], "name": "bind_processor", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def bind_processor(self, dialect): datetime_time = datetime.time format = self._storage_format def process(value): if value is None: return None elif isinstance(value, datetime_time): return format % { 'hour': value.hour, 'minute': value.minute, 'second': value.second, 'microsecond': value.microsecond, } else: raise TypeError("SQLite Time type only accepts Python " "time objects as input.") return process
10,996
[ 0.022692762315273285, -0.0022295776288956404, -0.010358534753322601, -0.035876352339982986, 0.015999412164092064, -0.028601372614502907, 0.025610139593482018, -0.009075257927179337, 0.015676286071538925, -0.0024072977248579264, 0.01690416969358921, -0.006185577716678381, 0.030743245035409927...
10
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "value", "annotation": null, "type_comment": null}}], "kwarg": null, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": null}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Is", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}]}}, "orelse": [{"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Name", "_fields": {"id": "format", "ctx": {"_type": "Load", "_fields": {}}}}, "right": {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "hour"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "minute"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "second"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "microsecond"}}], "values": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "hour", "value": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "minute", "value": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "second", "value": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "microsecond", "value": {"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}}}], "test": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "value", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "datetime_time", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "isinstance", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "orelse": [{"_type": "Raise", "_fields": {"exc": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "SQLite Time type only accepts Python time objects as input."}}], "func": {"_type": "Name", "_fields": {"id": "TypeError", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "cause": null}}]}}]}}], "name": "process", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def process(value): if value is None: return None elif isinstance(value, datetime_time): return format % { 'hour': value.hour, 'minute': value.minute, 'second': value.second, 'microsecond': value.microsecond, } else: raise TypeError("SQLite Time type only accepts Python " "time objects as input.")
10,997
[ 0.051936712116003036, -0.0011941330740228295, 0.03327709808945656, -0.050902675837278366, -0.009506063535809517, 0.04693104699254036, 0.009347433224320412, -0.07750555127859116, -0.045426998287439346, 0.02899995632469654, 0.00992907676845789, -0.061854038387537, 0.06617818027734756, 0.0048...
12
{"_type": "Module", "_fields": {"body": [{"_type": "ClassDef", "_fields": {"body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "extract_map", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "SQLCompiler", "value": {"_type": "Name", "_fields": {"id": "compiler", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "Dict", "_fields": {"keys": [{"_type": "Constant", "_fields": {"kind": null, "value": "month"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "day"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "year"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "second"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "hour"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "doy"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "minute"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "epoch"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "dow"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "week"}}], "values": [{"_type": "Constant", "_fields": {"kind": null, "value": "%m"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "%d"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "%Y"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "%S"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "%H"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "%j"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "%M"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "%s"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "%w"}}, {"_type": "Constant", "_fields": {"kind": null, "value": "%W"}}]}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "update_copy", "value": {"_type": "Name", "_fields": {"id": "util", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "extract_map", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "fn", "annotation": null, "type_comment": null}}], "kwarg": {"_type": "arg", "_fields": {"arg": "kw", "annotation": null, "type_comment": null}}, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Return", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "CURRENT_TIMESTAMP"}}}}], "name": "visit_now_func", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "func", "annotation": null, "type_comment": null}}], "kwarg": {"_type": "arg", "_fields": {"arg": "kw", "annotation": null, "type_comment": null}}, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Return", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "DATETIME(CURRENT_TIMESTAMP, \"localtime\")"}}}}], "name": "visit_localtimestamp_func", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "expr", "annotation": null, "type_comment": null}}], "kwarg": {"_type": "arg", "_fields": {"arg": "kw", "annotation": null, "type_comment": null}}, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Return", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "1"}}}}], "name": "visit_true", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "expr", "annotation": null, "type_comment": null}}], "kwarg": {"_type": "arg", "_fields": {"arg": "kw", "annotation": null, "type_comment": null}}, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Return", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": "0"}}}}], "name": "visit_false", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "fn", "annotation": null, "type_comment": null}}], "kwarg": {"_type": "arg", "_fields": {"arg": "kw", "annotation": null, "type_comment": null}}, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Return", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "length%s"}}, "right": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "fn", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "function_argspec", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}}}], "name": "visit_char_length_func", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "cast", "annotation": null, "type_comment": null}}], "kwarg": {"_type": "arg", "_fields": {"arg": "kwargs", "annotation": null, "type_comment": null}}, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "If", "_fields": {"body": [{"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "cast", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "visit_cast", "value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "SQLiteCompiler", "ctx": {"_type": "Load", "_fields": {}}}}, {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Name", "_fields": {"id": "super", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": null, "value": {"_type": "Name", "_fields": {"id": "kwargs", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}], "test": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "supports_cast", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "dialect", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "orelse": [{"_type": "Return", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "clause", "value": {"_type": "Name", "_fields": {"id": "cast", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "process", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": null, "value": {"_type": "Name", "_fields": {"id": "kwargs", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}]}}], "name": "visit_cast", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "extract", "annotation": null, "type_comment": null}}], "kwarg": {"_type": "arg", "_fields": {"arg": "kw", "annotation": null, "type_comment": null}}, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Try", "_fields": {"body": [{"_type": "Return", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "CAST(STRFTIME('%s', %s) AS INTEGER)"}}, "right": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "field", "value": {"_type": "Name", "_fields": {"id": "extract", "ctx": {"_type": "Load", "_fields": {}}}}}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "extract_map", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "expr", "value": {"_type": "Name", "_fields": {"id": "extract", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "process", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": null, "value": {"_type": "Name", "_fields": {"id": "kw", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}]}}}}}}], "orelse": [], "handlers": [{"_type": "ExceptHandler", "_fields": {"body": [{"_type": "Raise", "_fields": {"exc": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "%s is not a valid extract argument."}}, "right": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "field", "value": {"_type": "Name", "_fields": {"id": "extract", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "CompileError", "value": {"_type": "Name", "_fields": {"id": "exc", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "cause": null}}], "name": null, "type": {"_type": "Name", "_fields": {"id": "KeyError", "ctx": {"_type": "Load", "_fields": {}}}}}}], "finalbody": []}}], "name": "visit_extract", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "select", "annotation": null, "type_comment": null}}], "kwarg": {"_type": "arg", "_fields": {"arg": "kw", "annotation": null, "type_comment": null}}, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": ""}}, "targets": [{"_type": "Name", "_fields": {"id": "text", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "AugAssign", "_fields": {"op": {"_type": "Add", "_fields": {}}, "value": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "\n LIMIT "}}, "right": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_limit_clause", "value": {"_type": "Name", "_fields": {"id": "select", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "process", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": null, "value": {"_type": "Name", "_fields": {"id": "kw", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}, "target": {"_type": "Name", "_fields": {"id": "text", "ctx": {"_type": "Store", "_fields": {}}}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "IsNot", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_limit_clause", "value": {"_type": "Name", "_fields": {"id": "select", "ctx": {"_type": "Load", "_fields": {}}}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}]}}, "orelse": []}}, {"_type": "If", "_fields": {"body": [{"_type": "If", "_fields": {"body": [{"_type": "AugAssign", "_fields": {"op": {"_type": "Add", "_fields": {}}, "value": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "\n LIMIT "}}, "right": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "UnaryOp", "_fields": {"op": {"_type": "USub", "_fields": {}}, "operand": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "literal", "value": {"_type": "Name", "_fields": {"id": "sql", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "process", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, "target": {"_type": "Name", "_fields": {"id": "text", "ctx": {"_type": "Store", "_fields": {}}}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Is", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_limit_clause", "value": {"_type": "Name", "_fields": {"id": "select", "ctx": {"_type": "Load", "_fields": {}}}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}]}}, "orelse": []}}, {"_type": "AugAssign", "_fields": {"op": {"_type": "Add", "_fields": {}}, "value": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": " OFFSET "}}, "right": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_offset_clause", "value": {"_type": "Name", "_fields": {"id": "select", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "process", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": null, "value": {"_type": "Name", "_fields": {"id": "kw", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}, "target": {"_type": "Name", "_fields": {"id": "text", "ctx": {"_type": "Store", "_fields": {}}}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "IsNot", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_offset_clause", "value": {"_type": "Name", "_fields": {"id": "select", "ctx": {"_type": "Load", "_fields": {}}}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}]}}, "orelse": [{"_type": "AugAssign", "_fields": {"op": {"_type": "Add", "_fields": {}}, "value": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": " OFFSET "}}, "right": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 0}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "literal", "value": {"_type": "Name", "_fields": {"id": "sql", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "process", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": null, "value": {"_type": "Name", "_fields": {"id": "kw", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}, "target": {"_type": "Name", "_fields": {"id": "text", "ctx": {"_type": "Store", "_fields": {}}}}}}]}}, {"_type": "Return", "_fields": {"value": {"_type": "Name", "_fields": {"id": "text", "ctx": {"_type": "Load", "_fields": {}}}}}}], "name": "limit_clause", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "select", "annotation": null, "type_comment": null}}], "kwarg": {"_type": "arg", "_fields": {"arg": "kw", "annotation": null, "type_comment": null}}, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Return", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": ""}}}}], "name": "for_update_clause", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "binary", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "operator", "annotation": null, "type_comment": null}}], "kwarg": {"_type": "arg", "_fields": {"arg": "kw", "annotation": null, "type_comment": null}}, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Return", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "%s IS NOT %s"}}, "right": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "left", "value": {"_type": "Name", "_fields": {"id": "binary", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "process", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "right", "value": {"_type": "Name", "_fields": {"id": "binary", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "process", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}]}}}}}}], "name": "visit_is_distinct_from_binary", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}, {"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "binary", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "operator", "annotation": null, "type_comment": null}}], "kwarg": {"_type": "arg", "_fields": {"arg": "kw", "annotation": null, "type_comment": null}}, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Return", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "%s IS %s"}}, "right": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "left", "value": {"_type": "Name", "_fields": {"id": "binary", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "process", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "right", "value": {"_type": "Name", "_fields": {"id": "binary", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "process", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}]}}}}}}], "name": "visit_isnot_distinct_from_binary", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "name": "SQLiteCompiler", "bases": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "SQLCompiler", "value": {"_type": "Name", "_fields": {"id": "compiler", "ctx": {"_type": "Load", "_fields": {}}}}}}], "keywords": [], "type_params": [], "decorator_list": []}}], "type_ignores": []}}
class SQLiteCompiler(compiler.SQLCompiler): extract_map = util.update_copy( compiler.SQLCompiler.extract_map, { 'month': '%m', 'day': '%d', 'year': '%Y', 'second': '%S', 'hour': '%H', 'doy': '%j', 'minute': '%M', 'epoch': '%s', 'dow': '%w', 'week': '%W', }) def visit_now_func(self, fn, **kw): return "CURRENT_TIMESTAMP" def visit_localtimestamp_func(self, func, **kw): return 'DATETIME(CURRENT_TIMESTAMP, "localtime")' def visit_true(self, expr, **kw): return '1' def visit_false(self, expr, **kw): return '0' def visit_char_length_func(self, fn, **kw): return "length%s" % self.function_argspec(fn) def visit_cast(self, cast, **kwargs): if self.dialect.supports_cast: return super(SQLiteCompiler, self).visit_cast(cast, **kwargs) else: return self.process(cast.clause, **kwargs) def visit_extract(self, extract, **kw): try: return "CAST(STRFTIME('%s', %s) AS INTEGER)" % ( self.extract_map[extract.field], self.process(extract.expr, **kw) ) except KeyError: raise exc.CompileError( "%s is not a valid extract argument." % extract.field) def limit_clause(self, select, **kw): text = "" if select._limit_clause is not None: text += "\n LIMIT " + self.process(select._limit_clause, **kw) if select._offset_clause is not None: if select._limit_clause is None: text += "\n LIMIT " + self.process(sql.literal(-1)) text += " OFFSET " + self.process(select._offset_clause, **kw) else: text += " OFFSET " + self.process(sql.literal(0), **kw) return text def for_update_clause(self, select, **kw): # sqlite has no "FOR UPDATE" AFAICT return '' def visit_is_distinct_from_binary(self, binary, operator, **kw): return "%s IS NOT %s" % (self.process(binary.left), self.process(binary.right)) def visit_isnot_distinct_from_binary(self, binary, operator, **kw): return "%s IS %s" % (self.process(binary.left), self.process(binary.right))
10,998
[ 0.006597783416509628, 0.02053374983370304, -0.04060680419206619, -0.03194138780236244, 0.003106936113908887, 0.018449662253260612, -0.07090286165475845, -0.026149816811084747, -0.002783354138955474, 0.013491726480424404, -0.0019743989687412977, -0.03795233741402626, 0.056774940341711044, -...
10
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "extract", "annotation": null, "type_comment": null}}], "kwarg": {"_type": "arg", "_fields": {"arg": "kw", "annotation": null, "type_comment": null}}, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Try", "_fields": {"body": [{"_type": "Return", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "CAST(STRFTIME('%s', %s) AS INTEGER)"}}, "right": {"_type": "Tuple", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "elts": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "field", "value": {"_type": "Name", "_fields": {"id": "extract", "ctx": {"_type": "Load", "_fields": {}}}}}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "extract_map", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "expr", "value": {"_type": "Name", "_fields": {"id": "extract", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "process", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": null, "value": {"_type": "Name", "_fields": {"id": "kw", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}]}}}}}}], "orelse": [], "handlers": [{"_type": "ExceptHandler", "_fields": {"body": [{"_type": "Raise", "_fields": {"exc": {"_type": "Call", "_fields": {"args": [{"_type": "BinOp", "_fields": {"op": {"_type": "Mod", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "%s is not a valid extract argument."}}, "right": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "field", "value": {"_type": "Name", "_fields": {"id": "extract", "ctx": {"_type": "Load", "_fields": {}}}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "CompileError", "value": {"_type": "Name", "_fields": {"id": "exc", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "cause": null}}], "name": null, "type": {"_type": "Name", "_fields": {"id": "KeyError", "ctx": {"_type": "Load", "_fields": {}}}}}}], "finalbody": []}}], "name": "visit_extract", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def visit_extract(self, extract, **kw): try: return "CAST(STRFTIME('%s', %s) AS INTEGER)" % ( self.extract_map[extract.field], self.process(extract.expr, **kw) ) except KeyError: raise exc.CompileError( "%s is not a valid extract argument." % extract.field)
10,999
[ 0.05006545037031174, 0.022447342053055763, 0.060185059905052185, -0.0003299345844425261, -0.009703509509563446, 0.010408109985291958, -0.009525972418487072, -0.026497405022382736, -0.037349358201026917, 0.05468141287565231, 0.0177204180508852, -0.02587602660059929, -0.024566689506173134, 0...
11
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "select", "annotation": null, "type_comment": null}}], "kwarg": {"_type": "arg", "_fields": {"arg": "kw", "annotation": null, "type_comment": null}}, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Constant", "_fields": {"kind": null, "value": ""}}, "targets": [{"_type": "Name", "_fields": {"id": "text", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "AugAssign", "_fields": {"op": {"_type": "Add", "_fields": {}}, "value": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "\n LIMIT "}}, "right": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_limit_clause", "value": {"_type": "Name", "_fields": {"id": "select", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "process", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": null, "value": {"_type": "Name", "_fields": {"id": "kw", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}, "target": {"_type": "Name", "_fields": {"id": "text", "ctx": {"_type": "Store", "_fields": {}}}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "IsNot", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_limit_clause", "value": {"_type": "Name", "_fields": {"id": "select", "ctx": {"_type": "Load", "_fields": {}}}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}]}}, "orelse": []}}, {"_type": "If", "_fields": {"body": [{"_type": "If", "_fields": {"body": [{"_type": "AugAssign", "_fields": {"op": {"_type": "Add", "_fields": {}}, "value": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": "\n LIMIT "}}, "right": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "UnaryOp", "_fields": {"op": {"_type": "USub", "_fields": {}}, "operand": {"_type": "Constant", "_fields": {"kind": null, "value": 1}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "literal", "value": {"_type": "Name", "_fields": {"id": "sql", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "process", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}}}, "target": {"_type": "Name", "_fields": {"id": "text", "ctx": {"_type": "Store", "_fields": {}}}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "Is", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_limit_clause", "value": {"_type": "Name", "_fields": {"id": "select", "ctx": {"_type": "Load", "_fields": {}}}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}]}}, "orelse": []}}, {"_type": "AugAssign", "_fields": {"op": {"_type": "Add", "_fields": {}}, "value": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": " OFFSET "}}, "right": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_offset_clause", "value": {"_type": "Name", "_fields": {"id": "select", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "process", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": null, "value": {"_type": "Name", "_fields": {"id": "kw", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}, "target": {"_type": "Name", "_fields": {"id": "text", "ctx": {"_type": "Store", "_fields": {}}}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "IsNot", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_offset_clause", "value": {"_type": "Name", "_fields": {"id": "select", "ctx": {"_type": "Load", "_fields": {}}}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}]}}, "orelse": [{"_type": "AugAssign", "_fields": {"op": {"_type": "Add", "_fields": {}}, "value": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": " OFFSET "}}, "right": {"_type": "Call", "_fields": {"args": [{"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": 0}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "literal", "value": {"_type": "Name", "_fields": {"id": "sql", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "process", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": null, "value": {"_type": "Name", "_fields": {"id": "kw", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}}}, "target": {"_type": "Name", "_fields": {"id": "text", "ctx": {"_type": "Store", "_fields": {}}}}}}]}}, {"_type": "Return", "_fields": {"value": {"_type": "Name", "_fields": {"id": "text", "ctx": {"_type": "Load", "_fields": {}}}}}}], "name": "limit_clause", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def limit_clause(self, select, **kw): text = "" if select._limit_clause is not None: text += "\n LIMIT " + self.process(select._limit_clause, **kw) if select._offset_clause is not None: if select._limit_clause is None: text += "\n LIMIT " + self.process(sql.literal(-1)) text += " OFFSET " + self.process(select._offset_clause, **kw) else: text += " OFFSET " + self.process(sql.literal(0), **kw) return text
11,000
[ 0.06540727615356445, 0.014416753314435482, 0.03995760530233383, -0.0373842716217041, -0.01697995699942112, -0.013920322991907597, 0.028083795681595802, -0.04850837215781212, -0.023443687707185745, 0.005638034548610449, -0.02307896316051483, -0.038397397845983505, 0.026665421202778816, 0.00...
12
{"_type": "Module", "_fields": {"body": [{"_type": "FunctionDef", "_fields": {"args": {"_type": "arguments", "_fields": {"args": [{"_type": "arg", "_fields": {"arg": "self", "annotation": null, "type_comment": null}}, {"_type": "arg", "_fields": {"arg": "column", "annotation": null, "type_comment": null}}], "kwarg": {"_type": "arg", "_fields": {"arg": "kwargs", "annotation": null, "type_comment": null}}, "vararg": null, "defaults": [], "kwonlyargs": [], "kw_defaults": [], "posonlyargs": []}}, "body": [{"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "type", "value": {"_type": "Name", "_fields": {"id": "column", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "process", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "type_compiler", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "dialect", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}, "keywords": [{"_type": "keyword", "_fields": {"arg": "type_expression", "value": {"_type": "Name", "_fields": {"id": "column", "ctx": {"_type": "Load", "_fields": {}}}}}}]}}, "targets": [{"_type": "Name", "_fields": {"id": "coltype", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "column", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "format_column", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "preparer", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "keywords": []}}, "right": {"_type": "Constant", "_fields": {"kind": null, "value": " "}}}}, "right": {"_type": "Name", "_fields": {"id": "coltype", "ctx": {"_type": "Load", "_fields": {}}}}}}, "targets": [{"_type": "Name", "_fields": {"id": "colspec", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "Assign", "_fields": {"value": {"_type": "Call", "_fields": {"args": [{"_type": "Name", "_fields": {"id": "column", "ctx": {"_type": "Load", "_fields": {}}}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "get_column_default_string", "value": {"_type": "Name", "_fields": {"id": "self", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "targets": [{"_type": "Name", "_fields": {"id": "default", "ctx": {"_type": "Store", "_fields": {}}}}], "type_comment": null}}, {"_type": "If", "_fields": {"body": [{"_type": "AugAssign", "_fields": {"op": {"_type": "Add", "_fields": {}}, "value": {"_type": "BinOp", "_fields": {"op": {"_type": "Add", "_fields": {}}, "left": {"_type": "Constant", "_fields": {"kind": null, "value": " DEFAULT "}}, "right": {"_type": "Name", "_fields": {"id": "default", "ctx": {"_type": "Load", "_fields": {}}}}}}, "target": {"_type": "Name", "_fields": {"id": "colspec", "ctx": {"_type": "Store", "_fields": {}}}}}}], "test": {"_type": "Compare", "_fields": {"ops": [{"_type": "IsNot", "_fields": {}}], "left": {"_type": "Name", "_fields": {"id": "default", "ctx": {"_type": "Load", "_fields": {}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": null}}]}}, "orelse": []}}, {"_type": "If", "_fields": {"body": [{"_type": "AugAssign", "_fields": {"op": {"_type": "Add", "_fields": {}}, "value": {"_type": "Constant", "_fields": {"kind": null, "value": " NOT NULL"}}, "target": {"_type": "Name", "_fields": {"id": "colspec", "ctx": {"_type": "Store", "_fields": {}}}}}}], "test": {"_type": "UnaryOp", "_fields": {"op": {"_type": "Not", "_fields": {}}, "operand": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "nullable", "value": {"_type": "Name", "_fields": {"id": "column", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, "orelse": []}}, {"_type": "If", "_fields": {"body": [{"_type": "If", "_fields": {"body": [{"_type": "Raise", "_fields": {"exc": {"_type": "Call", "_fields": {"args": [{"_type": "Constant", "_fields": {"kind": null, "value": "SQLite does not support autoincrement for composite primary keys"}}], "func": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "CompileError", "value": {"_type": "Name", "_fields": {"id": "exc", "ctx": {"_type": "Load", "_fields": {}}}}}}, "keywords": []}}, "cause": null}}], "test": {"_type": "BoolOp", "_fields": {"op": {"_type": "And", "_fields": {}}, "values": [{"_type": "Compare", "_fields": {"ops": [{"_type": "Is", "_fields": {}}], "left": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "autoincrement", "value": {"_type": "Name", "_fields": {"id": "column", "ctx": {"_type": "Load", "_fields": {}}}}}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": true}}]}}, {"_type": "Compare", "_fields": {"ops": [{"_type": "NotEq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "columns", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "primary_key", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "table", "value": {"_type": "Name", "_fields": {"id": "column", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}]}}]}}, "orelse": []}}, {"_type": "If", "_fields": {"body": [{"_type": "AugAssign", "_fields": {"op": {"_type": "Add", "_fields": {}}, "value": {"_type": "Constant", "_fields": {"kind": null, "value": " PRIMARY KEY AUTOINCREMENT"}}, "target": {"_type": "Name", "_fields": {"id": "colspec", "ctx": {"_type": "Store", "_fields": {}}}}}}], "test": {"_type": "BoolOp", "_fields": {"op": {"_type": "And", "_fields": {}}, "values": [{"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "autoincrement"}}, "value": {"_type": "Subscript", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "slice": {"_type": "Constant", "_fields": {"kind": null, "value": "sqlite"}}, "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "dialect_options", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "table", "value": {"_type": "Name", "_fields": {"id": "column", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}}}, {"_type": "Compare", "_fields": {"ops": [{"_type": "Eq", "_fields": {}}], "left": {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "columns", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "primary_key", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "table", "value": {"_type": "Name", "_fields": {"id": "column", "ctx": {"_type": "Load", "_fields": {}}}}}}}}}}], "func": {"_type": "Name", "_fields": {"id": "len", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, "comparators": [{"_type": "Constant", "_fields": {"kind": null, "value": 1}}]}}, {"_type": "Call", "_fields": {"args": [{"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "_type_affinity", "value": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "type", "value": {"_type": "Name", "_fields": {"id": "column", "ctx": {"_type": "Load", "_fields": {}}}}}}}}, {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "Integer", "value": {"_type": "Name", "_fields": {"id": "sqltypes", "ctx": {"_type": "Load", "_fields": {}}}}}}], "func": {"_type": "Name", "_fields": {"id": "issubclass", "ctx": {"_type": "Load", "_fields": {}}}}, "keywords": []}}, {"_type": "UnaryOp", "_fields": {"op": {"_type": "Not", "_fields": {}}, "operand": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "foreign_keys", "value": {"_type": "Name", "_fields": {"id": "column", "ctx": {"_type": "Load", "_fields": {}}}}}}}}]}}, "orelse": []}}], "test": {"_type": "Attribute", "_fields": {"ctx": {"_type": "Load", "_fields": {}}, "attr": "primary_key", "value": {"_type": "Name", "_fields": {"id": "column", "ctx": {"_type": "Load", "_fields": {}}}}}}, "orelse": []}}, {"_type": "Return", "_fields": {"value": {"_type": "Name", "_fields": {"id": "colspec", "ctx": {"_type": "Load", "_fields": {}}}}}}], "name": "get_column_specification", "returns": null, "type_params": [], "type_comment": null, "decorator_list": []}}], "type_ignores": []}}
def get_column_specification(self, column, **kwargs): coltype = self.dialect.type_compiler.process( column.type, type_expression=column) colspec = self.preparer.format_column(column) + " " + coltype default = self.get_column_default_string(column) if default is not None: colspec += " DEFAULT " + default if not column.nullable: colspec += " NOT NULL" if column.primary_key: if ( column.autoincrement is True and len(column.table.primary_key.columns) != 1 ): raise exc.CompileError( "SQLite does not support autoincrement for " "composite primary keys") if (column.table.dialect_options['sqlite']['autoincrement'] and len(column.table.primary_key.columns) == 1 and issubclass(column.type._type_affinity, sqltypes.Integer) and not column.foreign_keys): colspec += " PRIMARY KEY AUTOINCREMENT" return colspec