MCPcopy
hub / github.com/tinode/chat / getVar

Function getVar

tn-cli/commands.py:50–74  ·  view source on GitHub ↗
(path)

Source from the content-addressed store, hash-verified

48# Read a value in the server response using dot notation, i.e.
49# $user.params.token or $meta.sub[1].user
50def getVar(path):
51 if not path.startswith("$"):
52 return path
53
54 parts = path.split('.')
55 if parts[0] not in tn_globals.Variables:
56 return None
57 var = tn_globals.Variables[parts[0]]
58 if len(parts) > 1:
59 parts = parts[1:]
60 for p in parts:
61 x = None
62 m = RE_INDEX.match(p)
63 if m:
64 p = m.group(1)
65 if m.group(2).isdigit():
66 x = int(m.group(2))
67 else:
68 x = m.group(2)
69 var = getattr(var, p)
70 if x or x == 0:
71 var = var[x]
72 if isinstance(var, bytes):
73 var = var.decode('utf-8')
74 return var
75
76
77# Dereference values, i.e. cmd.val == $usr => cmd.val == <actual value of usr>

Callers 2

derefValsFunction · 0.85
serialize_cmdFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…