forked from vEnhance/von
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.py
More file actions
38 lines (30 loc) · 1001 Bytes
/
api.py
File metadata and controls
38 lines (30 loc) · 1001 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# For importing von externally
from . import model
# For Pickle...
import sys
sys.modules['model'] = model
index = model.VonIndex().store # get the underlying dict
def has(source):
"""Checks whether a given source exists in database"""
return source in index
def has_solution(source):
"""Checks whether a given source exists in database AND has a solution"""
if not has(source): return False
entry = index[source]
return len(entry.full.bodies) > 1
def get_index(source):
"""Returns the index entry for a given source"""
entry = index[source]
return entry
def get(source):
"""Returns the full data for a given source"""
entry = get_index(source)
return entry.full
def get_statement(source):
"""Returns just the problem statement for a given source"""
return get(source).bodies[0]
def get_solution(source):
"""Returns just the solution for a given source (asserts existence)"""
bodies = get(source).bodies
assert len(bodies) > 1, "%s has no solution" % source
return bodies[1]