Oracle
Provide the Sage-backed daemon: its protocol entry point and the exact building blocks of its methods.
Importing this package imports SageMath.
answer_request(line)
Answer one JSON request line with one response object, never raising.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
line
|
str
|
A JSON object with |
required |
Returns:
| Type | Description |
|---|---|
JsonObject
|
The response: |
Examples:
>>> answer_request('{"id": 1, "method": "ping"}')['result']['ok']
True
>>> answer_request('{"id": 2, "method": "nosuch"}')['error'].startswith("unknown method 'nosuch'")
True
Source code in src/veriphy/oracle/_protocol.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | |
encode(x, *, advisory=False, depth=0)
Encode a method result exactly as JSON.
Rationals and integers of Sage become "n" or "n/d" strings, polynomials become term lists, and containers are
encoded element by element. Python integers stay integers, since they are structural (exponents, counts).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
object
|
The value to encode. |
required |
advisory
|
bool
|
Whether the result is advisory. Advisory results may carry floats and fall back to |
False
|
depth
|
int
|
The current nesting depth. |
0
|
Returns:
| Type | Description |
|---|---|
JsonValue
|
The JSON value. |
Raises:
| Type | Description |
|---|---|
EncodingError
|
If a certificate result holds a float, an opaque object, or nests too deeply. |
Examples:
>>> from sage.all import QQ
>>> encode({'m': [QQ(-3) / 2, 5]})
{'m': ['-3/2', 5]}
Source code in src/veriphy/oracle/_encoding.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |