Update processor.py
Browse files- processor.py +23 -13
processor.py
CHANGED
|
@@ -183,31 +183,41 @@ class DatasetCommandCenter:
|
|
| 183 |
"""
|
| 184 |
Retrieves value. PRIORITY: Direct Key Access (Fastest).
|
| 185 |
"""
|
| 186 |
-
if not path:
|
| 187 |
-
|
| 188 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 189 |
try:
|
| 190 |
-
#
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
except:
|
| 194 |
pass
|
| 195 |
-
|
| 196 |
-
# 2.
|
| 197 |
keys = path.split('.')
|
| 198 |
current = obj
|
| 199 |
|
| 200 |
for i, key in enumerate(keys):
|
|
|
|
|
|
|
|
|
|
| 201 |
try:
|
| 202 |
# Array/List index access support (e.g. solutions.0.code)
|
| 203 |
if isinstance(current, list) and key.isdigit():
|
| 204 |
current = current[int(key)]
|
| 205 |
else:
|
|
|
|
| 206 |
current = current[key]
|
| 207 |
-
except:
|
| 208 |
-
return None
|
| 209 |
|
| 210 |
-
# Lazy Parsing: Only parse string if we
|
| 211 |
is_last_key = (i == len(keys) - 1)
|
| 212 |
if not is_last_key and isinstance(current, str):
|
| 213 |
s = current.strip()
|
|
@@ -215,7 +225,7 @@ class DatasetCommandCenter:
|
|
| 215 |
try:
|
| 216 |
current = json.loads(s)
|
| 217 |
except:
|
| 218 |
-
return None
|
| 219 |
|
| 220 |
return current
|
| 221 |
|
|
|
|
| 183 |
"""
|
| 184 |
Retrieves value. PRIORITY: Direct Key Access (Fastest).
|
| 185 |
"""
|
| 186 |
+
if not path:
|
| 187 |
+
return obj
|
| 188 |
+
|
| 189 |
+
# Handle None/empty path edge cases
|
| 190 |
+
if path is None or path == '':
|
| 191 |
+
return obj
|
| 192 |
+
|
| 193 |
+
# 1. Try Direct Access First (handles simple column names)
|
| 194 |
+
# This works for dict, UserDict, LazyRow due to duck-typing
|
| 195 |
try:
|
| 196 |
+
# For simple paths (no dots), this is all we need
|
| 197 |
+
if '.' not in path:
|
| 198 |
+
return obj[path]
|
| 199 |
+
except (KeyError, TypeError, AttributeError):
|
| 200 |
pass
|
| 201 |
+
|
| 202 |
+
# 2. If direct access failed OR path contains dots, try dot notation
|
| 203 |
keys = path.split('.')
|
| 204 |
current = obj
|
| 205 |
|
| 206 |
for i, key in enumerate(keys):
|
| 207 |
+
if current is None:
|
| 208 |
+
return None
|
| 209 |
+
|
| 210 |
try:
|
| 211 |
# Array/List index access support (e.g. solutions.0.code)
|
| 212 |
if isinstance(current, list) and key.isdigit():
|
| 213 |
current = current[int(key)]
|
| 214 |
else:
|
| 215 |
+
# Try dictionary-style access
|
| 216 |
current = current[key]
|
| 217 |
+
except (KeyError, TypeError, IndexError, AttributeError):
|
| 218 |
+
return None
|
| 219 |
|
| 220 |
+
# Lazy Parsing: Only parse JSON string if we need to go deeper
|
| 221 |
is_last_key = (i == len(keys) - 1)
|
| 222 |
if not is_last_key and isinstance(current, str):
|
| 223 |
s = current.strip()
|
|
|
|
| 225 |
try:
|
| 226 |
current = json.loads(s)
|
| 227 |
except:
|
| 228 |
+
return None
|
| 229 |
|
| 230 |
return current
|
| 231 |
|