Remarks#
Remarks#
Partial reference loading#
Using a fragment in a url
or a ptr
in rconf.load()
, rconf.loads()
or rconf.loadu()
is more efficient than resolving in a following step
when there are irrelevant references elsewhere in the document.
In the following snippet,
you’ll notice there is no attempt to download the invalid URL
in the first rconf.loads()
.
import json
from http.client import InvalidURL
import rconf
doc = """
pypa_build."$ref" = "https://raw.githubusercontent.com/pypa/build/main/pyproject.toml#project.description"
icon."$ref" = "https://git INVALID hub.com/manifest.json#/icons/0"
"""
# No issues
config = rconf.loads(doc, ptr="pypa_build", media_type="toml")
print("This works:", json.dumps(config, indent=4))
# Raises InvalidURL
try:
config = rconf.loads(doc, media_type="toml")
rconf.TOMLPointer.parse("pypa_build").resolve(config)
except InvalidURL as error:
print("As expected:", type(error), error)
results in
This works: "A simple, correct Python build frontend"
As expected: <class 'http.client.InvalidURL'> URL can't contain control characters. 'git INVALID hub.com' (found at least ' ')
Circular references#
Circular references are allowed,
but json.dumps()
and tomli_w.dumps
won’t be able to dump them:
import json
import rconf
doc = """
[table]
strings = ["Hello", "TOML"]
circular."$ref" = "#table"
"""
config = rconf.loads(doc, media_type="toml")
print("This works:", config)
try:
print(json.dumps(config, indent=4))
except ValueError as error:
print("As expected:", type(error), error)
assert config["table"] == config["table"]["circular"]
results in
This works: {'table': {'strings': ['Hello', 'TOML'], 'circular': {...}}}
As expected: <class 'ValueError'> Circular reference detected
Known issues#
JSON Pointer: leading zeros#
This implementation allows for leading zeros in array indices.
Reason: pointer resolution is common for JSON and TOML, and keys only become indices upon resolution.