Move documentation to texinfo, add makefiles, rename Cert to Attestation (python)
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
.PHONY: all
|
||||
|
||||
all:
|
||||
python setup.py sdist
|
||||
test:
|
||||
bash run_tests.sh
|
||||
|
||||
@@ -1 +1 @@
|
||||
from .cert import Cert
|
||||
from .cert import Attestation
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -13,7 +13,7 @@ class CIC(enum.Enum):
|
||||
voucherTransfer = URIRef('https://defalsify.org/rdf-eth/0.1/voucherTransfer')
|
||||
|
||||
|
||||
class Cert:
|
||||
class Attestation:
|
||||
|
||||
def __init__(self):
|
||||
self.g = Graph()
|
||||
|
||||
2
python/cic_schema/error.py
Normal file
2
python/cic_schema/error.py
Normal file
@@ -0,0 +1,2 @@
|
||||
class InvalidCertificationError(Exception):
|
||||
pass
|
||||
64
python/cic_schema/nft.py
Normal file
64
python/cic_schema/nft.py
Normal file
@@ -0,0 +1,64 @@
|
||||
# standard imports
|
||||
import os
|
||||
import json
|
||||
from urllib.request import urlopen
|
||||
#import binascii.error
|
||||
|
||||
# external imports
|
||||
from jsonschema import validate as json_validate
|
||||
|
||||
# local imports
|
||||
from .error import InvalidCertificationError
|
||||
|
||||
|
||||
script_dir = os.path.realpath(os.path.dirname(__file__))
|
||||
data_dir = os.path.join(script_dir, 'data')
|
||||
__f = open(os.path.join(data_dir, 'cic.json'), 'r')
|
||||
schema = __f.read()
|
||||
__f.close()
|
||||
|
||||
|
||||
class NFT:
|
||||
|
||||
def __init__(self):
|
||||
self.name = None
|
||||
self.description = None
|
||||
self.image = None
|
||||
self.attachments = []
|
||||
self.attributes = {}
|
||||
self.certifications = []
|
||||
|
||||
|
||||
@classmethod
|
||||
def from_path(cls, path):
|
||||
f = open(path, 'r')
|
||||
o = json.load(f)
|
||||
f.close()
|
||||
json_validate(schema, o)
|
||||
c = cls()
|
||||
c.name = o['name']
|
||||
c.description = o['description']
|
||||
c.image = o['image']
|
||||
c.attributes = o['attributes']
|
||||
c.attachments = o['attachments']
|
||||
c.certifications = o['certifications']
|
||||
|
||||
|
||||
def __decode_certification(self):
|
||||
for v in self.certiciations:
|
||||
try:
|
||||
r = self.__try_data_uri(v)
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
def __try_data_uri(self, data):
|
||||
r = None
|
||||
try:
|
||||
r = urllib.request.urlopen(data)
|
||||
#except binascii.error:
|
||||
# raise InvalidCertificationError()
|
||||
except Exception:
|
||||
raise InvalidCertificationError()
|
||||
#return None
|
||||
return r
|
||||
14
python/run_tests.sh
Normal file
14
python/run_tests.sh
Normal file
@@ -0,0 +1,14 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -a
|
||||
set -e
|
||||
set -x
|
||||
default_pythonpath=$PYTHONPATH:.
|
||||
export PYTHONPATH=${default_pythonpath:-.}
|
||||
>&2 echo using pythonpath $PYTHONPATH
|
||||
for f in `ls tests/*.py`; do
|
||||
python $f
|
||||
done
|
||||
set +x
|
||||
set +e
|
||||
set +a
|
||||
@@ -9,7 +9,7 @@ from rdflib import Graph
|
||||
#from hypothesis import given, strategies
|
||||
|
||||
# local imports
|
||||
from cic_schema import Cert
|
||||
from cic_schema import Attestation
|
||||
|
||||
test_dir = os.path.realpath(os.path.dirname(__file__))
|
||||
testdata_dir = os.path.join(test_dir, 'testdata')
|
||||
@@ -20,9 +20,9 @@ class TestNft(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
#fp = os.path.join(testdata_dir, 'test_voucher.rdf')
|
||||
#self.graph_voucher = Cert.from_path(fp)
|
||||
#self.graph_voucher = Attestation.from_path(fp)
|
||||
fp = os.path.join(testdata_dir, 'test_tx2.rdf')
|
||||
self.graph_tx = Cert.from_path(fp)
|
||||
self.graph_tx = Attestation.from_path(fp)
|
||||
|
||||
|
||||
def test_simplest(self):
|
||||
|
||||
Reference in New Issue
Block a user