Changeset 47

Show
Ignore:
Timestamp:
05/31/05 19:30:33 (4 years ago)
Author:
zool
Message:

basic ui hookup working, thinking about queries.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • bbox/bbox/config.py

    Revision 13 Revision 47
    1boot='file:/home/jo/consumotronic/bbox/boot.rdf' 1boot='file:/home/wirelesslondon/lib/consumotronic/bbox/boot.rdf' 
    2store = '/home/jo/bbox/store/' 2store = '/home/wirelesslondon/store/' 
    3db = 'bbox' 3db = 'bbox' 
  • bbox/bbox/ui/__init__.py

    Revision 39 Revision 47
    1from Cheetah.Template import Template 1from Cheetah.Template import Template 
    2from bbox import BBox 2from bbox import BBox 
    3#from spatialStore import Store 3#from spatialStore import Store 
    4import quixote 4import quixote 
    5import os  5import os  
    6import RDF 6import RDF 
      7import rdfobj 
    7 8 
    8_q_exports = ['_q_index','subs','_q_lookup'] 9_q_exports = ['_q_index','subs','_q_lookup'] 
    9 10 
    10def _q_index(r): 11def _q_index(r): 
    11    return 'bbox' 12    return 'bbox' 
    12 13 
    13def subs(r): 14def subs(r): 
    14    """List current subscriptions.""" 15    """List current subscriptions.""" 
    15    bb = BBoxUI() 16    bb = BBoxUI() 
    16    return bb.subs(r) 17    return bb.subs(r) 
    17 18 
    18def read_subs(r): 19def read_subs(r): 
    19    """Trigger a read of updates to subscriptions, if found.""" 20    """Trigger a read of updates to subscriptions, if found.""" 
    20    bb = BBoxUI() 21    bb = BBoxUI() 
    21    return bb.read_subs(r) 22    return bb.read_subs(r) 
    22 23 
    23def getitems(r): 24def getitems(r): 
    24    """Provides a bloglines-API style interface.""" 25    """Provides a bloglines-API style interface.""" 
    25    bb = BBoxUI() 26    bb = BBoxUI() 
    26    return bb.getitems(r) 27    return bb.getitems(r) 
    27     28     
    28def _q_lookup(r,n): 29def _q_lookup(r,n): 
    29    pass 30    pass 
    30 31 
    31def _q_access(request): 32#def _q_access(request): 
    32    raise UnauthorizedError(realm='Foo Realm') 33#    raise UnauthorizedError(realm='Foo Realm') 
    33 34 
    34class BBoxUI: 35class BBoxUI: 
    35    def __init__(self): 36    def __init__(self): 
    36        self.bbox = BBox('bbox.db') 37        self.bbox = BBox('bbox.db') 
    37 38 
    38    def subscribe(self,r): 39    def subscribe(self,r): 
    39        uri = r.get_form_var('uri') 40        uri = r.get_form_var('uri') 
    40        self.bbox.subscribe(uri=uri) 41        self.bbox.subscribe(uri=uri) 
    41        context = self.bbox.visit(uri) 42        context = self.bbox.visit(uri) 
    42        self.bbox.read(uri,context=context) 43        self.bbox.read(uri,context=context) 
    43 44 
    44    def read_subs(self,r): 45    def read_subs(self,r): 
    45        self.bbox.read_subscriptions() 46        self.bbox.read_subscriptions() 
    46 47 
    47    def subs(self,r): 48    def subs(self,r): 
    48        subs = self.bbox.subscriptions() 49        subs = self.bbox.subscriptions() 
    49        xml = self.serialise(subs) 50        xml = self.serialise(subs) 
    50        return xml 51        return xml 
    51 52 
    52    def getitems(self,r): 53    def getitems(self,r): 
    53        """This is the bloglines-style interface""" 54        """This is the bloglines-style interface""" 
    54        """See http://www.bloglines.com/services/api/getitems """     55        """See http://www.bloglines.com/services/api/getitems """     
    55         56         
    56        read = r.get_form_var('n') 57        read = r.get_form_var('n') 
    57        """ 'n' parameter - 1 marks downloaded items as read, 0 does not.""" 58        """ 'n' parameter - 1 marks downloaded items as read, 0 does not.""" 
    58 59 
    59        date = r.get_form_var('d') 60        date = r.get_form_var('d') 
    60        """ 'd' parameter - date to get new entries since. """ 61        """ 'd' parameter - date to get new entries since. """ 
    61 62 
    62        sub = r.get_form_var('s') 63        sub = r.get_form_var('s') 
      64         
    63        """ 'subid'. we will accept an integer id which is a unique key in the node table, but this parameter is optional instead of compulsory; you can otherwise supply a URI-encoded url...""" 65        """ 'subid'. we will accept an integer id which is a unique key in the node table, but this parameter is optional instead of compulsory; you can otherwise supply a URI-encoded url...""" 
      66         
    64        uri = r.get_form_var('uri') 67        uri = r.get_form_var('uri') 
    65        if uri is None: uri = r.get_form_var('u') 68        if uri is None: uri = r.get_form_var('u') 
    66# Cleverness? we should be able to tell whether the context for this quiery have changed atall since your last request or last request which overloapped it... 69         
    67          70          
    68        # should we implement subscriptions here and have a root user, or just assume everything of type Feed is soemthing that we are subscribed to?   
    69        # probably yhe former though it's a mild PITA   
    70   
    71        b_user = self.bbox.root_user() 71        b_user = self.bbox.root_user() 
    72        self.bbox.user(b_user) 72        self.bbox.user(b_user) 
    73 73 
    74        # this now looks for ocntents of self.user() 74        # this now looks for ocntents of self.user() 
    75        self.bbox.read_subscriptions() 75        self.bbox.read_subscriptions() 
    76 76 
    77 77 
    78    """HTTP Status Response 78    """HTTP Status Response 
    79 79 
    80    * 200 - normal 80    * 200 - normal 
    81    * 304 - the request produced no entries (either there were no unread entries, or no entries after the given date, depending on the parameters passed in) 81    * 304 - the request produced no entries (either there were no unread entries, or no entries after the given date, depending on the parameters passed in) 
    82    * 401 - incorrect email address or password 82    * 401 - incorrect email address or password 
    83    * 403 - invalid or missing BloglinesSubId 83    * 403 - invalid or missing BloglinesSubId 
    84    * 410 - subscription has been deleted 84    * 410 - subscription has been deleted 
    85    """ 85    """ 
    86 86 
    87    def serialise(self,objs): 87    def serialise(self,objs): 
    88        """Serialises a list of rdf objects, supplied, as RDF/XML."""  88        """Serialises a list of rdf objects, supplied, as RDF/XML."""  
    89        from rdfobj import dc 89        from rdfobj import dc 
    90        dc = rdfobj.dc 90        dc = rdfobj.dc 
    91        out = '' 91        out = '' 
    92        for o in objs:   
    93            out = out+str(o)+"\n"   
    94            for k in o.__dict__.keys():   
    95                out = out+str(k)+str(getattr(o,k))   
    96                if o.dc_subject is not None:   
    97                    out = out+str(dc.subject)   
    98   
    99        return out   
    100        # proper serialisation 92        # proper serialisation 
    101        tmpstore = RDF.MemoryStorage() 93        tmpstore = RDF.MemoryStorage() 
    102        tmpmodel = RDF.Model(tmpstore) 94        tmpmodel = RDF.Model(tmpstore) 
    103        for o in objs: 95        for o in objs: 
    104            statement = RDF.Statement(RDF.Uri(o.uri()),None,None) 96            statement = RDF.Statement(RDF.Uri(o.uri()),None,None) 
    105            statements = self.bbox.model.model.find_statements(statement) 97            statements = self.bbox.model.model.find_statements(statement) 
    106            for s in statements: 98            for s in statements: 
    107                tmpmodel.add_statement(s) 99                tmpmodel.add_statement(s) 
    108        ser = RDF.Serializer() 100        ser = RDF.Serializer() 
    109        out = ser.serialize_model_to_string(tmpmodel) 101        out = ser.serialize_model_to_string(tmpmodel) 
    110        return out 102        return out 
    111 103 
    112from quixote.errors import AccessError 104from quixote.errors import AccessError 
    113status_code = 401 105status_code = 401 
    114title = "Unauthorized" 106title = "Unauthorized" 
    115description = "You are not authorized to access this resource." 107description = "You are not authorized to access this resource." 
    116 108 
    117class UnauthorizedError(AccessError): 109class UnauthorizedError(AccessError): 
    118    """The request requires user authentication. 110    """The request requires user authentication. 
    119   111   
    120    This subclass of AccessError sends a 401 instead of a 403, 112    This subclass of AccessError sends a 401 instead of a 403, 
    121    hinting that the client should try again with authentication.""" 113    hinting that the client should try again with authentication.""" 
    122 114 
    123    def __init__(self, realm='Protected', public_msg=None, private_msg=None): 115    def __init__(self, realm='Protected', public_msg=None, private_msg=None): 
    124        self.realm = realm 116        self.realm = realm 
    125        AccessError.__init__(self, public_msg, private_msg) 117        AccessError.__init__(self, public_msg, private_msg) 
    126 118 
    127    def format(self, request): 119    def format(self, request): 
    128        request.response.set_header('WWW-Authenticate', 'Basic realm="%s"' % self.realm) 120        request.response.set_header('WWW-Authenticate', 'Basic realm="%s"' % self.realm) 
    129        return AccessError.format(self, request) 121        return AccessError.format(self, request)