| 7 | | 8 | |
|---|
| 8 | _q_exports = ['_q_index','subs','_q_lookup'] | 9 | _q_exports = ['_q_index','subs','_q_lookup'] |
|---|
| 9 | | 10 | |
|---|
| 10 | def _q_index(r): | 11 | def _q_index(r): |
|---|
| 11 | return 'bbox' | 12 | return 'bbox' |
|---|
| 12 | | 13 | |
|---|
| 13 | def subs(r): | 14 | def 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 | |
|---|
| 18 | def read_subs(r): | 19 | def 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 | |
|---|
| 23 | def getitems(r): | 24 | def 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 | |
|---|
| 28 | def _q_lookup(r,n): | 29 | def _q_lookup(r,n): |
|---|
| 29 | pass | 30 | pass |
|---|
| 30 | | 31 | |
|---|
| 33 | | 34 | |
|---|
| 34 | class BBoxUI: | 35 | class 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') |
|---|
| 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 = '' |
|---|
| 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 | |
|---|
| 112 | from quixote.errors import AccessError | 104 | from quixote.errors import AccessError |
|---|
| 113 | status_code = 401 | 105 | status_code = 401 |
|---|
| 114 | title = "Unauthorized" | 106 | title = "Unauthorized" |
|---|
| 115 | description = "You are not authorized to access this resource." | 107 | description = "You are not authorized to access this resource." |
|---|
| 116 | | 108 | |
|---|
| 117 | class UnauthorizedError(AccessError): | 109 | class 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) |
|---|