Initial React project
This commit is contained in:
59
node_modules/flatted/python/flatted.py
generated
vendored
59
node_modules/flatted/python/flatted.py
generated
vendored
@@ -25,20 +25,13 @@ class _String:
|
||||
def __init__(self, value):
|
||||
self.value = value
|
||||
|
||||
|
||||
def _array_keys(value):
|
||||
keys = []
|
||||
i = 0
|
||||
for _ in value:
|
||||
keys.append(i)
|
||||
i += 1
|
||||
return keys
|
||||
for i in range(len(value)):
|
||||
yield i
|
||||
|
||||
def _object_keys(value):
|
||||
keys = []
|
||||
for key in value:
|
||||
keys.append(key)
|
||||
return keys
|
||||
yield key
|
||||
|
||||
def _is_array(value):
|
||||
return isinstance(value, (list, tuple))
|
||||
@@ -56,24 +49,6 @@ def _index(known, input, value):
|
||||
known.value.append(index)
|
||||
return index
|
||||
|
||||
def _loop(keys, input, known, output):
|
||||
for key in keys:
|
||||
value = output[key]
|
||||
if isinstance(value, _String):
|
||||
_ref(key, input[int(value.value)], input, known, output)
|
||||
|
||||
return output
|
||||
|
||||
def _ref(key, value, input, known, output):
|
||||
if _is_array(value) and value not in known:
|
||||
known.append(value)
|
||||
value = _loop(_array_keys(value), input, known, value)
|
||||
elif _is_object(value) and value not in known:
|
||||
known.append(value)
|
||||
value = _loop(_object_keys(value), input, known, value)
|
||||
|
||||
output[key] = value
|
||||
|
||||
def _relate(known, input, value):
|
||||
if _is_string(value) or _is_array(value) or _is_object(value):
|
||||
try:
|
||||
@@ -83,6 +58,22 @@ def _relate(known, input, value):
|
||||
|
||||
return value
|
||||
|
||||
def _resolver(input, lazy, parsed):
|
||||
def resolver(output):
|
||||
keys = _array_keys(output) if _is_array(output) else _object_keys(output) if _is_object(output) else []
|
||||
for key in keys:
|
||||
value = output[key]
|
||||
if isinstance(value, _String):
|
||||
tmp = input[int(value.value)]
|
||||
output[key] = tmp
|
||||
if (_is_array(tmp) or _is_object(tmp)) and tmp not in parsed:
|
||||
parsed.append(tmp)
|
||||
lazy.append([output, key])
|
||||
|
||||
return output
|
||||
|
||||
return resolver
|
||||
|
||||
def _transform(known, input, value):
|
||||
if _is_array(value):
|
||||
output = []
|
||||
@@ -128,12 +119,16 @@ def parse(value, *args, **kwargs):
|
||||
input.append(value)
|
||||
|
||||
value = input[0]
|
||||
lazy = []
|
||||
revive = _resolver(input, lazy, [value])
|
||||
|
||||
if _is_array(value):
|
||||
return _loop(_array_keys(value), input, [value], value)
|
||||
value = revive(value)
|
||||
|
||||
if _is_object(value):
|
||||
return _loop(_object_keys(value), input, [value], value)
|
||||
i = 0
|
||||
while i < len(lazy):
|
||||
o, k = lazy[i]
|
||||
i += 1
|
||||
o[k] = revive(o[k])
|
||||
|
||||
return value
|
||||
|
||||
|
||||
Reference in New Issue
Block a user