def remove(tag, documentid): globals.g.remove( (edocol[documentid], edocol["tagged"], edocol[tag]) ) # remove the tag #Write database globals.writedb() return True
def fromemail(email): email1 = '' email2 = '' email3 = '' phase = 1 for char in email: if phase == 3: if char == '.': assert False, 'email address cannot contain more than 1 dot.' else: email3 = email3 + char if phase == 2: if char == '.': phase = 3 else: email2 = email2 + char if phase == 1: if char == '@': phase = 2 else: email1 = email1 + char # find all properties of user id target = globals.g.query( """ SELECT ?id WHERE { ?id edocol:email1 edocol:%s . ?id edocol:email2 edocol:%s . ?id edocol:email3 edocol:%s .}""" % (email1, email2, email3), initNs=globals.ns).serialize(format='python') globals.writedb() return globals.parse_pyformat_one(target)
def edit(did, name, content): """ pre: nonempty id, time, contributor post: false if contributor notin whitelist a new version of the page, with the updated content/name attached to the document. """ # Initialisation # create a new version try: oldname = globals.g.query( """ SELECT ?name WHERE {edodoc:?did edodoc:name ?name .}""", initNs=globals.ns, initBindings={"?did": did}, ) # Get original name except: oldname = "" if oldname != name: # Add a new name, if appliable globals.g.set((edodoc[str(did)], edodoc["name"], Literal(name))) globals.g.set((edodoc[str(did)], edodoc["content"], Literal(content))) # Add the content # Write database globals.writedb() return did
def fromemail(email): email1 = '' email2 = '' email3 = '' phase = 1 for char in email: if phase == 3: if char == '.': assert False, 'email address cannot contain more than 1 dot.' else: email3 = email3 + char if phase == 2: if char == '.': phase = 3 else: email2 = email2 + char if phase == 1: if char == '@': phase = 2 else: email1 = email1 + char # find all properties of user id target = globals.g.query(""" SELECT ?id WHERE { ?id edocol:email1 edocol:%s . ?id edocol:email2 edocol:%s . ?id edocol:email3 edocol:%s .}""" % (email1, email2, email3), initNs=globals.ns).serialize(format='python') globals.writedb() return globals.parse_pyformat_one(target)
def edit(did, name, content): """ pre: nonempty id, time, contributor post: false if contributor notin whitelist a new version of the page, with the updated content/name attached to the document. """ #Initialisation # create a new version try: oldname = globals.g.query(""" SELECT ?name WHERE {edodoc:?did edodoc:name ?name .}""", initNs=globals.ns, initBindings={'?did': did}) # Get original name except: oldname = "" if (oldname != name): # Add a new name, if appliable globals.g.set((edodoc[str(did)], edodoc['name'], Literal(name))) globals.g.set((edodoc[str(did)], edodoc['content'], Literal(content))) # Add the content #Write database globals.writedb() return did
def deletepropertyvalue(id, property): for row in globals.g.objects(edocol[id], edocol[property]): globals.g.remove( (edocol[id], edocol[property], row) ) #Write database globals.writedb() return True
def deletepropertyvalue(id, property): for row in globals.g.objects(edocol[id], edocol[property]): globals.g.remove((edocol[id], edocol[property], row)) #Write database globals.writedb() return True
def tag(tag, documentid): assert re.match("^[a-zA-Z]+$", tag), 'invalid tag: tag does not consist of only letters' globals.g.add( (edocol[documentid], edocol["tagged"], edocol[tag]) ) # tag the document #Write database globals.writedb() return True
def fromproperty(property, value): # find all properties of user id target = globals.g.query( """ SELECT ?id WHERE { ?id edocol:%s edocol:%s .}""" % (property, value), initNs=globals.ns).serialize(format='python') globals.writedb() return globals.parse_pyformat_one(target)
def fromproperty(property, value): # find all properties of user id target = globals.g.query(""" SELECT ?id WHERE { ?id edocol:%s edocol:%s .}""" % (property, value), initNs=globals.ns).serialize(format='python') globals.writedb() return globals.parse_pyformat_one(target)
def follow(id, tag): assert not (get(tag) == []), 'no such tag' # add new user globals.g.add( (edocol[id], edocol["followstag"], edocol[tag]) ) # follow the tag #Write database globals.writedb() return True
def add(tag): assert re.match("^[a-zA-Z]+$", tag), 'invalid tag: tag does not consist of only letters' assert get(tag) == [], 'tag already exists' globals.g.add( (edocol[tag], edocol["type"], edocol['tag']) ) # add the tag #Write database globals.writedb() return tag
def follow(follower_id, followed_id): assert (not (followed_id in getpropertyvalue(follower_id, 'follows'))), 'already following that user' assert (not follower_id == followed_id), 'what? you cannot follow yourself! that is crazy!' assert globals.g.predicate_objects(followed_id)<>[], 'the user which you are trying to follow does not exist' globals.g.add((edocol[follower_id], edocol["follows"], edocol[followed_id])) #Write database globals.writedb() return True
def deletespecific(id, property, value): for entry in getpropertyvalue(id, property): if value in entry: assert True, 'no such value to delete' globals.g.remove((edocol[id], edocol[property], edocol[value])) #Write database globals.writedb() return True
def deletespecific(id, property, value): for entry in getpropertyvalue(id, property): if value in entry: assert True,'no such value to delete' globals.g.remove( (edocol[id], edocol[property], edocol[value]) ) #Write database globals.writedb() return True
def getpropertyvalue(id, property): assert (globals.g.predicate_objects(id) <> []), 'User does not exist or does not have that property' if property == 'email': results = [] emailnlist = ['email1', 'email2', 'email3'] for p in emailnlist: results = results + globals.g.query( """ SELECT ?id ?p ?value WHERE {edocol:%s edocol:%s ?value . ?id ?p ?value .}""" % (id, p), initNs=globals.ns).serialize('python') output = [] for row in results: if (row[0] == edocol[id]) and (row[1] == edocol['email1']): output = output + [row] break for row in results: if (row[0] == edocol[id]) and (row[1] == edocol['email2']): output = output + [row] break for row in results: if (row[0] == edocol[id]) and (row[1] == edocol['email3']): output = output + [row] break print output output = globals.parse_pyformat_many(output) print output output = output[0][2] + '@' + output[1][2] + '.' + output[2][2] #Write database globals.writedb() return output else: # find all info on property of user id results = globals.g.query(""" SELECT ?id ?p ?value WHERE {edocol:%s edocol:%s ?value . ?id ?p ?value .}""" % (id, property), initNs=globals.ns).serialize('python') output = [] for row in results: if (row[0] == edocol[id]) and (row[1] == edocol[property]): output = output + [row] #Write database globals.writedb() return globals.parse_pyformat_many(globals.individual(output))
def addpropertyvalue(id, property, value): assert (not (value in getpropertyvalue(id, property))), 'already has that value for that property' assert not (property == 'email'), 'a user can have only one email address at a time. use "set_user_property_value" to change it' assert ((not (property == email1)) and (not (property == email2)) and (not (property == email3))), 'cannot set email# properties directly' globals.g.add( (edocol[id], edocol[property], edocol[value]) ) #Write database globals.writedb() return True
def delete(did): """ pre: identifier van een page post: de page word verwijdert """ ################### ## H4xx0rz ##################$ # delete type target = globals.g.query( """ SELECT ?v WHERE { edodoc:%s edodoc:type ?v .}""" % (did,), initNs=globals.ns, ).serialize("python") print target globals.g.remove((edodoc[str(did)], edodoc["type"], target[0])) # delete type target = globals.g.query( """ SELECT ?v WHERE { edodoc:%s edodoc:owner ?v .}""" % (did,), initNs=globals.ns, ).serialize("python") globals.g.remove((edodoc[str(did)], edodoc["owner"], target[0])) # delete type target = globals.g.query( """ SELECT ?v WHERE { edodoc:%s edodoc:name ?v .}""" % (did,), initNs=globals.ns, ).serialize("python") globals.g.remove((edodoc[str(did)], edodoc["name"], target[0])) # delete type target = globals.g.query( """ SELECT ?v WHERE { edodoc:%s edodoc:content ?v .}""" % (did,), initNs=globals.ns, ).serialize("python") globals.g.remove((edodoc[str(did)], edodoc["content"], target[0])) # Write database globals.writedb() return True
def getpropertyvalue(id, property): assert ( globals.g.predicate_objects(id) <> [] ), 'User does not exist or does not have that property' if property == 'email': results = [] emailnlist = ['email1', 'email2', 'email3'] for p in emailnlist: results = results + globals.g.query(""" SELECT ?id ?p ?value WHERE {edocol:%s edocol:%s ?value . ?id ?p ?value .}""" % (id, p), initNs=globals.ns).serialize('python') output = [] for row in results: if (row[0] == edocol[id]) and (row[1] == edocol['email1']): output = output + [row] break for row in results: if (row[0] == edocol[id]) and (row[1] == edocol['email2']): output = output + [row] break for row in results: if (row[0] == edocol[id]) and (row[1] == edocol['email3']): output = output + [row] break print output output = globals.parse_pyformat_many(output) print output output = output[0][2] + '@' + output[1][2] + '.' + output[2][2] #Write database globals.writedb() return output else: # find all info on property of user id results = globals.g.query(""" SELECT ?id ?p ?value WHERE {edocol:%s edocol:%s ?value . ?id ?p ?value .}""" % (id, property), initNs=globals.ns).serialize('python') output = [] for row in results: if (row[0] == edocol[id]) and (row[1] == edocol[property]): output = output + [row] #Write database globals.writedb() return globals.parse_pyformat_many(globals.individual(output))
def follow(follower_id, followed_id): assert (not (followed_id in getpropertyvalue( follower_id, 'follows'))), 'already following that user' assert (not follower_id == followed_id), 'what? you cannot follow yourself! that is crazy!' assert globals.g.predicate_objects( followed_id ) <> [], 'the user which you are trying to follow does not exist' globals.g.add( (edocol[follower_id], edocol["follows"], edocol[followed_id])) #Write database globals.writedb() return True
def getallinfo(id): # find all properties of user id targets = globals.g.query(""" SELECT ?id ?p ?v WHERE { edocol:%s ?p ?v . ?id ?p ?v .}""" % id, initNs=globals.ns).serialize(format='python') results = [] for row in targets: if row[0] == edocol[id]: results = results + [row] #Write database globals.writedb() return globals.parse_pyformat_many(globals.individual(results))
def delete(id): # find all properties of user id targets = globals.g.query(""" SELECT ?id ?p ?v WHERE { edocol:%s ?p ?v . ?id ?p ?v .}""" % id, initNs=globals.ns).serialize('python') # deletes all references from user (including all data) while leaving references to the id intact. for row in targets: if row[0] == edocol[id]: globals.g.remove(row) #Write database globals.writedb() return globals.parse_pyformat_many(globals.individual(targets))
def delete(id): # find all properties of user id targets = globals.g.query( """ SELECT ?id ?p ?v WHERE { edocol:%s ?p ?v . ?id ?p ?v .}""" % id, initNs=globals.ns).serialize('python') # deletes all references from user (including all data) while leaving references to the id intact. for row in targets: if row[0] == edocol[id]: globals.g.remove(row) #Write database globals.writedb() return globals.parse_pyformat_many(globals.individual(targets))
def addpropertyvalue(id, property, value): assert (not (value in getpropertyvalue( id, property))), 'already has that value for that property' assert not ( property == 'email' ), 'a user can have only one email address at a time. use "set_user_property_value" to change it' assert ( (not (property == email1)) and (not (property == email2)) and (not (property == email3))), 'cannot set email# properties directly' globals.g.add((edocol[id], edocol[property], edocol[value])) #Write database globals.writedb() return True
def getallinfo(id): # find all properties of user id targets = globals.g.query( """ SELECT ?id ?p ?v WHERE { edocol:%s ?p ?v . ?id ?p ?v .}""" % id, initNs=globals.ns).serialize(format='python') results = [] for row in targets: if row[0] == edocol[id]: results = results + [row] #Write database globals.writedb() return globals.parse_pyformat_many(globals.individual(results))
def new(name, password, email): # add new user id = newuserid() email1 = '' email2 = '' email3 = '' phase = 1 for char in email: if phase == 3: if char == '.': assert False, 'email address cannot contain more than 1 dot.' else: email3 = email3 + char if phase == 2: if char == '.': phase = 3 else: email2 = email2 + char if phase == 1: if char == '@': phase = 2 else: email1 = email1 + char assert (fromemail(email) == []), 'email address already in use' globals.g.add( (edocol[id], edocol["type"], edocol["person"])) # add the person globals.g.add((edocol[id], edocol["name"], edocol[name])) # add the name globals.g.add((edocol[id], edocol["email1"], edocol[email1])) # add the email address globals.g.add((edocol[id], edocol["email2"], edocol[email2])) # add the email address globals.g.add((edocol[id], edocol["email3"], edocol[email3])) # add the email address globals.g.add( (edocol[id], edocol["password"], edocol[password])) # add the password #Write database globals.writedb() return id
def new(pid, name, content): """ pre: id, unique time post: a new page id is added to g. The user is added as owner and to the whitelist and a first version of the document is created. """ #Initialisation did = globals.newdid() # Create initial nodes globals.g.add((edodoc[str(did)], edodoc['type'], Literal("document"))) # Setting owner, reverse owner and globals.g.add((edodoc[str(did)], edodoc['owner'], edocol[str(pid)])) # ownership # Assign values globals.g.add((edodoc[str(did)], edodoc['name'], Literal(name) )) # assign name globals.g.add((edodoc[str(did)], edodoc['content'], Literal(content))) # assign empty content #Write database globals.writedb() return did
def new(pid, name, content): """ pre: id, unique time post: a new page id is added to g. The user is added as owner and to the whitelist and a first version of the document is created. """ # Initialisation did = globals.newdid() # Create initial nodes globals.g.add((edodoc[str(did)], edodoc["type"], Literal("document"))) # Setting owner, reverse owner and globals.g.add((edodoc[str(did)], edodoc["owner"], edocol[str(pid)])) # ownership # Assign values globals.g.add((edodoc[str(did)], edodoc["name"], Literal(name))) # assign name globals.g.add((edodoc[str(did)], edodoc["content"], Literal(content))) # assign empty content # Write database globals.writedb() return did
def delete(did): """ pre: identifier van een page post: de page word verwijdert """ ################### ## H4xx0rz ##################$ # delete type target = globals.g.query( """ SELECT ?v WHERE { edodoc:%s edodoc:type ?v .}""" % (did, ), initNs=globals.ns).serialize('python') print target globals.g.remove((edodoc[str(did)], edodoc['type'], target[0])) # delete type target = globals.g.query( """ SELECT ?v WHERE { edodoc:%s edodoc:owner ?v .}""" % (did, ), initNs=globals.ns).serialize('python') globals.g.remove((edodoc[str(did)], edodoc['owner'], target[0])) # delete type target = globals.g.query( """ SELECT ?v WHERE { edodoc:%s edodoc:name ?v .}""" % (did, ), initNs=globals.ns).serialize('python') globals.g.remove((edodoc[str(did)], edodoc['name'], target[0])) # delete type target = globals.g.query( """ SELECT ?v WHERE { edodoc:%s edodoc:content ?v .}""" % (did, ), initNs=globals.ns).serialize('python') globals.g.remove((edodoc[str(did)], edodoc['content'], target[0])) #Write database globals.writedb() return True
def setpropertyvalue(id, property, value): assert (not (value in getpropertyvalue( id, property))), 'already has that value for that property' if property == 'email': email1 = '' email2 = '' email3 = '' phase = 1 for char in value: if phase == 3: if char == '.': assert False, 'email address cannot contain more than 1 dot.' else: email3 = email3 + char if phase == 2: if char == '.': phase = 3 else: email2 = email2 + char if phase == 1: if char == '@': phase = 2 else: email1 = email1 + char assert ((not (property == email1)) and (not (property == email2)) and (not (property == email3))), 'cannot set email# properties directly' globals.g.set((edocol[id], edocol['email1'], edocol[email1])) globals.g.set((edocol[id], edocol['email2'], edocol[email2])) globals.g.set((edocol[id], edocol['email3'], edocol[email3])) else: globals.g.set((edocol[id], edocol[property], edocol[value])) #Write database globals.writedb() return True
def setpropertyvalue(id, property, value): assert (not (value in getpropertyvalue(id, property))), 'already has that value for that property' if property == 'email': email1 = '' email2 = '' email3 = '' phase = 1 for char in value: if phase == 3: if char == '.': assert False, 'email address cannot contain more than 1 dot.' else: email3 = email3 + char if phase == 2: if char == '.': phase = 3 else: email2 = email2 + char if phase == 1: if char == '@': phase = 2 else: email1 = email1 + char assert ((not (property == email1)) and (not (property == email2)) and (not (property == email3))), 'cannot set email# properties directly' globals.g.set( (edocol[id], edocol['email1'], edocol[email1]) ) globals.g.set( (edocol[id], edocol['email2'], edocol[email2]) ) globals.g.set( (edocol[id], edocol['email3'], edocol[email3]) ) else: globals.g.set( (edocol[id], edocol[property], edocol[value]) ) #Write database globals.writedb() return True
def new(name, password, email): # add new user id = newuserid() email1 = '' email2 = '' email3 = '' phase = 1 for char in email: if phase == 3: if char == '.': assert False, 'email address cannot contain more than 1 dot.' else: email3 = email3 + char if phase == 2: if char == '.': phase = 3 else: email2 = email2 + char if phase == 1: if char == '@': phase = 2 else: email1 = email1 + char assert (fromemail(email) == []), 'email address already in use' globals.g.add( (edocol[id], edocol["type"], edocol["person"]) ) # add the person globals.g.add( (edocol[id], edocol["name"], edocol[name]) ) # add the name globals.g.add( (edocol[id], edocol["email1"], edocol[email1]) ) # add the email address globals.g.add( (edocol[id], edocol["email2"], edocol[email2]) ) # add the email address globals.g.add( (edocol[id], edocol["email3"], edocol[email3]) ) # add the email address globals.g.add( (edocol[id], edocol["password"], edocol[password]) ) # add the password #Write database globals.writedb() return id
def get(tag): # find all triples about tag targets = globals.g.query( """ SELECT ?s ?p ?v WHERE { edocol:%s ?p ?v . ?s ?p ?v .}""" % tag, initNs=globals.ns).serialize('python') targets = targets + globals.g.query( """ SELECT ?s ?p ?v WHERE { ?s ?p edocol:%s . ?s ?p ?v .}""" % tag, initNs=globals.ns).serialize('python') # get everything results = [] for row in targets: if (row[0] == edocol[tag]) or (row[2] == edocol[tag]): results = results + [row] #Write database globals.writedb() return globals.parse_pyformat_many(globals.individual(results))
def delete(tag): # find all triples about tag targets = globals.g.query( """ SELECT ?s ?p ?v WHERE { edocol:%s ?p ?v . ?s ?p ?v .}""" % tag, initNs=globals.ns).serialize('python') targets = targets + globals.g.query( """ SELECT ?s ?p ?v WHERE { ?s ?p edocol:%s . ?s ?p ?v .}""" % tag, initNs=globals.ns).serialize('python') # delete everything for row in targets: if (row[0] == edocol[tag]) or (row[2] == edocol[tag]): globals.g.remove(row) print row #Write database globals.writedb() return globals.parse_pyformat_many(globals.individual(targets))
def exitdb(self): globals.writedb()