def disconnect_from(self, uri):
     for store in [store for store in self.neighbours.stores if store.uri==uri]:
         self.neighbours.remove_store(store)
         self.remove(resource(uri), CONNECTED, None)
         self.add(resource(uri), CONNECTED, NO)
         # Do we want to remember our neighbour?
         if not self.exists(resource(uri), TYPE, NEIGHBOUR):
             self.add(resource(uri), TYPE, NEIGHBOUR)
Exemple #2
0
 def add_statement(self, subject, predicate, object, literal_object=None, anonymous_subject=None, anonymous_object=None):
     s = resource(subject, anonymous_subject)
     p = resource(predicate)
     if literal_object:
         o = literal(object)
     else:
         o = resource(object, anonymous_object)
     self.add(s, p, o)
 def connect_to(self, location, uri=None):
     neighbour = Neighbour()        
     neighbour.load(location, uri or location, 0)
     self.neighbours.add_store(neighbour)
     self.remove(resource(location), TYPE, NEIGHBOUR)
     self.add(resource(location), TYPE, NEIGHBOUR)        
     self.remove(resource(location), CONNECTED, None)
     self.add(resource(location), CONNECTED, YES)        
Exemple #4
0
 def add_sniffed(self, href, label, sniffed_from):
     if not self.ignore(href):
         uri = resource(href)
         label = literal(label)
         if not self.exists(uri, None, None):
             print "ADDED:", href, label
             self.add(uri, LABEL, label)
             self.add(uri, TYPE, SNIFFED)
             timestamp = literal(date_time())
             self.add(uri, SNIFFED_ON, timestamp)
             self.add(uri, SNIFFED_FROM, resource(sniffed_from))
Exemple #5
0
 def inner(self):
     state = self.__states[-1]
     path = state.consumed + state.remaining
     html = self.rednode.neighbourhood.get_first_value(resource(path), INNER_HTML, None)
     if html:
         print "INNER: %s" % path            
         self.response.write(html)            
     self.__states.pop()
Exemple #6
0
 def exact(self):
     state = self.__states[-1]
     path = state.consumed + state.remaining
     html = self.rednode.neighbourhood.get_first_value(resource(path), HTML, None)
     if html:
         print "EXACT: %s" % path            
         self.response.write(html)
         self.__states.pop()
     else:
         state.next = self.alias
Exemple #7
0
 def process_resource(self, text):
     if text == "ANY":
         r = None
     elif text[0] == "<" and text[-1] == ">":
         r = resource(text[1:-1])
     elif text.find(":") != -1:
         prefix, local_name = text.split(":")
         if prefix == "":
             if self.default_uri:
                 r = resource(self.default_uri + local_name)
             else:
                 return -1 # error
         elif prefix in self.prefix_map:
             r = resource(self.prefix_map[prefix] + local_name)
         else:
             return -1 # error
     else:
         return -1 # error
     return r
    def __init__(self, host, username, password):
        self.store = TripleStore()
        M = poplib.POP3(host)
        M.user(username)
        M.pass_(password)
        numMessages = len(M.list()[1])
        self.messages = {}
        for i in range(numMessages):
            uidl = string.split(M.uidl(i+1))[2]
            msg = M.retr(i+1)[1]
            lineFile = LineFile(msg)
            message = rfc822.Message(lineFile)
            bodyStartLine = lineFile.count
            headers = message.dict
            body = string.join(msg[bodyStartLine:], "\n")

            subject = resource(POP_URI + uidl)
            for header in headers.keys():
                predicate = resource(RFC_822_URI + header)
                object = literal(headers[header])
                self.store.add(subject, predicate, object)
            self.store.add(subject, BODY, literal(body))
            self.store.add(subject, TYPE, MESSAGE)
        M.quit()
from xml.parsers.expat import ParserCreate

from redfootlib.xml.handler import HandlerBase
from redfootlib.rdf.objects import resource, literal

from exceptions import SyntaxError, Exception

FACET = resource("http://redfoot.net/04/26/rapp/^facet")
APPLY = resource("http://redfoot.net/04/26/rapp/^apply")
EXEC = resource("http://redfoot.net/04/26/rapp/^exec")

class HTMLHandler(HandlerBase, object):

    def __init__(self, parser):
        HandlerBase.__init__(self, parser, None)
        self.data = ''
        args = "rednode, request, response, processor"
        self.codestr = '''\
def _tmp(%s):
'''  % args

    def child(self, name, atts):
        if name==FACET:
            pass
        elif name==APPLY:
            if self.data:
                self.codestr = self.codestr + '''\
        response.write("""%s""")
''' % self.data
                self.data = ''
            self.codestr = self.codestr + '''\
Exemple #10
0
####
from redfootlib.server.module import App
from redfootlib.rdf.objects import resource, literal
from redfootlib.rdf.const import TYPE, LABEL, COMMENT

HTML = resource("http://redfoot.net/04/26/rapp/html")
OUTER_HTML = resource("http://redfoot.net/04/26/rapp/outer_html")
INNER_HTML = resource("http://redfoot.net/04/26/rapp/inner_html")
ALIAS_TO = resource("http://redfoot.net/04/26/rapp/alias_to")
CHAIN_TO = resource("http://redfoot.net/04/26/rapp/chain_to")

from rdf_app_parser import parse

class Processor(object):
    
    class State(object):
        __slots__ = ('consumed', 'remaining', 'next', 'followed', 'outer')
        def __init__(self, consumed='', remaining='', next=None):
            self.consumed = consumed
            self.remaining = remaining
            self.next = next
            self.followed = []
            self.outer = []
        def __repr__(self):
            return "(%s, %s, %s, %s)" % (self.consumed, self.remaining, self.next, self.followed)
    
    def __init__(self, rednode):
        self.rednode = rednode
        self.__states = []

    def get_state(self):
Exemple #11
0
import poplib, rfc822, string

from redfootlib.rdf.store.triple import TripleStore
from redfootlib.rdf.objects import resource, literal
from redfootlib.rdf.const import TYPE

POP_URI = "http://redfoot.sourceforge.net/2001/08/POP/"
RFC_822_URI = "http://redfoot.sourceforge.net/2001/08/RFC822/"

MESSAGE = resource(POP_URI+"Message")
SUBJECT = resource(RFC_822_URI+"subject")
FROM = resource(RFC_822_URI+"from")
DATE = resource(RFC_822_URI+"date")
BODY = resource(POP_URI+"BODY")

class POP_Connector:

    def __init__(self, host, username, password):
        self.store = TripleStore()
        M = poplib.POP3(host)
        M.user(username)
        M.pass_(password)
        numMessages = len(M.list()[1])
        self.messages = {}
        for i in range(numMessages):
            uidl = string.split(M.uidl(i+1))[2]
            msg = M.retr(i+1)[1]
            lineFile = LineFile(msg)
            message = rfc822.Message(lineFile)
            bodyStartLine = lineFile.count
Exemple #12
0
from redfootlib.rdf.objects import resource

# Useful RDF constants

# SYNTAX
RDFNS = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"

TYPE = resource(RDFNS + "type")
PROPERTY = resource(RDFNS + "Property")
STATEMENT = resource(RDFNS + "Statement")
SUBJECT = resource(RDFNS + "subject")
PREDICATE = resource(RDFNS + "predicate")
OBJECT = resource(RDFNS + "object")

# SCHEMA
RDFSNS = "http://www.w3.org/2000/01/rdf-schema#"

CLASS = resource(RDFSNS + "Class")
RESOURCE = resource(RDFSNS + "Resource")
SUBCLASSOF = resource(RDFSNS + "subClassOf")
LABEL = resource(RDFSNS + "label")
COMMENT = resource(RDFSNS + "comment")
RANGE = resource(RDFSNS + "range")
DOMAIN = resource(RDFSNS + "domain")
LITERAL = resource(RDFSNS + "Literal")
CONTAINER = resource(RDFSNS + "Container")

Exemple #13
0
import sys
from time import sleep, time, gmtime, mktime
from urlparse import urlparse        

from redfootlib.rdf.objects import resource, literal
from redfootlib.rdf.const import TYPE, LABEL, COMMENT
from redfootlib.rdf.query.functors import s

from sniffer_html_parser import SnifferHTMLParser

SNIFFED = resource("http://redfoot.net/2002/04/17/sniff/ed")
SNIFFABLE = resource("http://redfoot.net/2002/04/17/sniff/able")
SNIFFED_FROM = resource("http://redfoot.net/2002/04/17/sniff/source")
# When a link was sniffed into the triple store
SNIFFED_ON = resource("http://redfoot.net/2002/04/17/sniff/date")

# When a resource was last sniffed for links
SNIFF_LAST = resource("http://redfoot.net/2002/04/17/sniff/last")

SNIFF_EVERY = resource("http://redfoot.net/2002/04/17/sniff/every")

SECONDS_IN_DAY = 60*60*24

from date_time import date_time, parse_date_time

class Sniffer(object):
    def __init__(self):
        super(Sniffer, self).__init__()
        self.ignore_list = ["www.google.com"]
                
    def run(self):
from redfootlib.rdf.const import LABEL, TYPE
from redfootlib.rdf.objects import resource, literal

NEIGHBOUR = resource("http://redfoot.sourceforge.net/2001/04/neighbour#Neighbour")
CONNECTED = resource("http://redfoot.sourceforge.net/2001/04/neighbour#Connected")
YES = resource("http://redfoot.sourceforge.net/2000/10/06/builtin#YES")
NO = resource("http://redfoot.sourceforge.net/2000/10/06/builtin#NO")

from redfootlib.rdf.store.triple import TripleStore
from redfootlib.rdf.store.storeio import LoadSave

# TODO: neighbours are readonly and so they should only need Load
class Neighbour(LoadSave, TripleStore): pass

class NeighbourManager(object):

    def load(self, location ,uri, create=0):
        super(NeighbourManager, self).load(location, uri, create)
        # load neighbours that are marked as connected
        self.visit_by_type(self._connect, NEIGHBOUR, CONNECTED, YES)

    def _connect(self, neighbour, p, o):
        self.connect_to(neighbour)

    def connect_to(self, location, uri=None):
        neighbour = Neighbour()        
        neighbour.load(location, uri or location, 0)
        self.neighbours.add_store(neighbour)
        self.remove(resource(location), TYPE, NEIGHBOUR)
        self.add(resource(location), TYPE, NEIGHBOUR)        
        self.remove(resource(location), CONNECTED, None)