cic-schema/python/cic_schema/cert.py

45 lines
1004 B
Python
Raw Normal View History

2023-03-09 09:30:47 +01:00
# standard imports
import sys
2023-04-30 08:38:42 +02:00
import enum
2023-03-09 09:30:47 +01:00
# external imports
2023-04-30 08:38:42 +02:00
from rdflib import Graph, RDF
from rdflib.term import URIRef
from rdflib.collection import Collection
class CIC(enum.Enum):
voucherContract = URIRef('https://defalsify.org/rdf-eth/0.1/voucherContract')
voucherTransfer = URIRef('https://defalsify.org/rdf-eth/0.1/voucherTransfer')
2023-03-09 09:30:47 +01:00
class Attestation:
2023-03-09 09:30:47 +01:00
2023-04-30 08:38:42 +02:00
def __init__(self):
2023-03-09 09:30:47 +01:00
self.g = Graph()
2023-04-30 08:38:42 +02:00
self.txs = {}
self.typ = None
@classmethod
def from_path(cls, path):
c = cls()
c.g.parse(path, format='turtle')
c.__apply_graph()
return c
2023-03-09 09:30:47 +01:00
2023-04-30 08:38:42 +02:00
def __apply_graph(self):
current_subject = None
for (s, p, o) in self.g:
if s != current_subject:
current_subject = s
if p == RDF.first:
pass
print('{} {} {}'.format(s, p, o))
2023-03-09 09:30:47 +01:00
def export(self, w=sys.stdout):
v = self.g.serialize(format='xml')
w.write(v)