#!/usr/bin/python
"""Eep RDF API: Template Thingy EARL Test"""

import eep, query, infer, template

def test(): 
   store = eep.parse("""
_:j15842 <http://www.w3.org/2001/03/earl/1.0#email> <mailto:bob@example.org> .
_:j15842 <http://www.w3.org/2001/03/earl/1.0#name> "Bob B. Bobbington" .
_:j15845 <http://www.w3.org/2001/03/earl/1.0#reprOf> <http://example.org/net/bob/> .
_:j15845 <http://www.w3.org/2001/03/earl/1.0#date> "2001-05-07" .
_:j15845 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2001/03/earl/1.0#WebContent> .
_:j15844 <http://www.w3.org/1999/02/22-rdf-syntax-ns#subject> _:j15845 .
_:j15844 <http://www.w3.org/1999/02/22-rdf-syntax-ns#predicate> <http://www.w3.org/2001/03/earl/1.0#passes> .
_:j15848 <http://www.w3.org/2000/01/rdf-schema#label> "WCAG Single A Compliance Test" .
_:j15848 <http://www.w3.org/2001/03/earl/1.0#suite> <http://www.w3.org/TR/WCAG10/> .
_:j15848 <http://www.w3.org/2001/03/earl/1.0#level> <http://www.w3.org/TR/WCAG10/#wc-priority-1> .
_:j15848 <http://www.w3.org/2000/01/rdf-schema#comment> "All Priority 1 checkpoints => WCAG Single-A compliance" .
_:j15848 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2001/03/earl/1.0#TestCase> .
_:j15844 <http://www.w3.org/1999/02/22-rdf-syntax-ns#object> _:j15848 .
_:j15844 <http://www.w3.org/2001/03/earl/1.0#testMode> <http://www.w3.org/2001/03/earl/1.0#Manual> .
_:j15842 <http://www.w3.org/2001/03/earl/1.0#asserts> _:j15844 .
_:j15842 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2001/03/earl/1.0#Assertor> .
""")

   q = """
_:Person <http://www.w3.org/2001/03/earl/1.0#email> ?email .
_:Person <http://www.w3.org/2001/03/earl/1.0#name> ?name .
_:Person <http://www.w3.org/2001/03/earl/1.0#asserts> _:Assertion .
_:Assertion <http://www.w3.org/1999/02/22-rdf-syntax-ns#subject> _:TS .
_:Assertion <http://www.w3.org/1999/02/22-rdf-syntax-ns#predicate> ?validity .
_:Assertion <http://www.w3.org/1999/02/22-rdf-syntax-ns#object> _:TC .
_:TS <http://www.w3.org/2001/03/earl/1.0#reprOf> ?repr .
_:TS <http://www.w3.org/2001/03/earl/1.0#date> ?date .
_:TC <http://www.w3.org/2000/01/rdf-schema#label> ?label .
_:TC <http://www.w3.org/2000/01/rdf-schema#comment> ?comment .
""".strip()

   t = """
<p>Assertor: <a href="(?email)">(?name)</a>; asserts...</p>
<ul>
<li>(?repr) on (?date)</li>
<li><a href="(?validity)">(?validity)</a></li>
<li>(?label) [(?comment)]</li>
</ul>
""".strip()

   r = template.rule(q, t)
   print template.format("""
<html xmlns="http://www.w3.org/1999/xhtml" 
   xml:lang="en" >
<head>
<title>EARL Output</title>
</head>
<body>
<h1>EARL Stuff</h1>
""".lstrip(), 
template.filter(r, store), 
"""
</body>
</html>
""".rstrip())

if __name__=="__main__": 
   test()
