MCPcopy
hub / github.com/httpie/cli / parse_root

Function parse_root

httpie/cli/nested_json/parse.py:70–104  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

68
69 # noinspection PyShadowingNames
70 def parse_root():
71 tokens = []
72 if not can_advance():
73 return Path(
74 kind=PathAction.KEY,
75 accessor=EMPTY_STRING,
76 is_root=True
77 )
78 # (literal | index_path | append_path)?
79 token = expect(*LITERAL_TOKENS, TokenKind.LEFT_BRACKET)
80 tokens.append(token)
81 if token.kind in LITERAL_TOKENS:
82 action = PathAction.KEY
83 value = str(token.value)
84 elif token.kind is TokenKind.LEFT_BRACKET:
85 token = expect(TokenKind.NUMBER, TokenKind.RIGHT_BRACKET)
86 tokens.append(token)
87 if token.kind is TokenKind.NUMBER:
88 action = PathAction.INDEX
89 value = token.value
90 tokens.append(expect(TokenKind.RIGHT_BRACKET))
91 elif token.kind is TokenKind.RIGHT_BRACKET:
92 action = PathAction.APPEND
93 value = None
94 else:
95 assert_cant_happen()
96 else:
97 assert_cant_happen()
98 # noinspection PyUnboundLocalVariable
99 return Path(
100 kind=action,
101 accessor=value,
102 tokens=tokens,
103 is_root=True
104 )
105
106 yield parse_root()
107

Callers 1

parseFunction · 0.85

Calls 4

can_advanceFunction · 0.85
PathClass · 0.85
expectFunction · 0.85
assert_cant_happenFunction · 0.85

Tested by

no test coverage detected