Exemplo n.º 1
0
 def validate(self, uri_fingerprint, require_hex_fpr=1):
     """validate the format of the document"""
     
     FOAF = Namespace("http://xmlns.com/foaf/0.1/")
     TRUST = Namespace("http://www.konfidi.org/ns/trust/1.2#")
     WOT = Namespace("http://xmlns.com/wot/0.1/")
     RDF = Namespace("http://www.w3.org/2000/01/rdf-schema#")
     store = TripleStore()
 
     # TODO: verify all <truster>s have fingerprints
     # and that they're all the same
     try:
         store.parse(StringInputSource(self.content))
     except SAXParseException:
         raise FOAFServerError, "invalid XML: " + str(sys.exc_info()[1])
     
     fingerprint = last_fingerprint = None
     for (relationship, truster) in store.subject_objects(TRUST["truster"]):
         for (key) in store.objects(truster, WOT["hasKey"]):
             fingerprint = store.objects(key, WOT["fingerprint"]).next()
             if last_fingerprint:
                 if fingerprint != last_fingerprint:
                     raise FOAFServerError, "All wot:fingerprint's from trust:truster's PubKeys must be the same.  Found '%s' and '%s'" % (fingerprint, last_fingerprint)
             last_fingerprint = fingerprint
     
     # per http://xmlns.com/wot/0.1/, we really shouldn't replace these
     fingerprint = fingerprint.replace(" ", "")
     fingerprint = fingerprint.replace(":", "")
     if require_hex_fpr and not(ishex(fingerprint)):
         raise FOAFServerError, "Invalid fingerprint format; must be hex"
     
     if uri_fingerprint and uri_fingerprint != fingerprint:
         raise FOAFServerError, "URI fingerprint doesn't match FOAF fingerprint"
         
     return fingerprint
Exemplo n.º 2
0
	def load(self, source):	
		print "Update Listener: parsing input: %s" % source
		# this is the main object we're concerned with
		trust = TripleStore()
		trust.load(source)	
		# new version
		count = 0
		for (relationship, truster) in trust.subject_objects(self.TRUST["truster"]):
			# clean up the fingerprints
			source_fingerprint = trust.objects(truster, self.WOT["fingerprint"]).next()
			sink_fingerprint = trust.objects(trust.objects(relationship, self.TRUST["trusted"]).next(), self.WOT["fingerprint"]).next()
			# turn these off for now, for our test cases.  figure a better solution later
			source_fingerprint = re.sub(r'[^0-9A-Z]', r'', source_fingerprint.upper())
			sink_fingerprint = re.sub(r'[^0-9A-Z]', r'', sink_fingerprint.upper())
			source = self.server.getPerson(source_fingerprint)
			sink = self.server.getPerson(sink_fingerprint)
			for item in trust.objects(relationship, self.TRUST["about"]):
				topic = trust.objects(item, self.TRUST["topic"]).next().split("#")[1]
				rating = float(trust.objects(item, self.TRUST["rating"]).next())
				if rating >= 0.0 and rating <= 1.0:
					source.addTrustLink(sink.getFingerprint(), topic, rating)
					count += 1
		return "Added %d trust links." % count
Exemplo n.º 3
0
"""
read XMP xml files

"""
# see http://www.xml.com/lpt/a/1107
# see also raptor-utls
# rapper -o ntriples http://planetrdf.com/guide/rss.rdf
# rapper -o ntriples ../tests/fixture/xmp/sample_xmp.rdf
from rdflib.TripleStore import TripleStore
from rdflib.Namespace import Namespace

ns_dc = Namespace("http://purl.org/dc/elements/1.1/")
ns_pr = Namespace("http://prismstandard.org/1.0#")
store = TripleStore()
store.load("../tests/fixture/xmp/sample_xmp.rdf")

# print dir(store)

quit()
# For all triples that have prism:publicationTime as their predicate,
for s, o in store.subject_objects(ns_pr["publicationTime"]):
    # if the triples' object is greater than the cutoff date,
    if o > cutOffDate:
        # print the date, author name, and title.
        print o,
        for object in store.objects(s, ns_dc["creator"]):
            print object + ": ",
        for object in store.objects(s, ns_dc["title"]):
            print object