| 29 | def _q_lookup(r,n): | 24 | def _q_lookup(r,n): |
|---|
| 30 | pass | 25 | pass |
|---|
| 31 | | 26 | |
|---|
| 32 | #def _q_access(request): | 27 | #def _q_access(request): |
|---|
| 33 | # raise UnauthorizedError(realm='Foo Realm') | 28 | # raise UnauthorizedError(realm='Foo Realm') |
|---|
| 34 | | 29 | |
|---|
| 35 | class BBoxUI: | 30 | class BBoxUI: |
|---|
| 36 | def __init__(self): | 31 | def __init__(self): |
|---|
| 37 | self.bbox = BBox('bbox.db') | 32 | self.bbox = BBox('bbox.db') |
|---|
| 38 | | 33 | |
|---|
| 39 | def subscribe(self,r): | 34 | def subscribe(self,r): |
|---|
| 40 | uri = r.get_form_var('uri') | 35 | uri = r.get_form_var('uri') |
|---|
| 41 | self.bbox.subscribe(uri=uri) | 36 | self.bbox.subscribe(uri=uri) |
|---|
| 42 | context = self.bbox.visit(uri) | 37 | context = self.bbox.visit(uri) |
|---|
| 43 | self.bbox.read(uri,context=context) | 38 | self.bbox.read(uri,context=context) |
|---|
| 44 | | 39 | |
|---|
| 45 | def read_subs(self,r): | 40 | def read_subs(self,r): |
|---|
| 46 | self.bbox.read_subscriptions() | 41 | self.bbox.read_subscriptions() |
|---|
| 47 | | 42 | |
|---|
| 48 | def subs(self,r): | 43 | def subs(self,r): |
|---|
| 49 | subs = self.bbox.subscriptions() | 44 | subs = self.bbox.subscriptions() |
|---|
| 50 | xml = self.serialise(subs) | 45 | xml = self.serialise(subs) |
|---|
| 51 | return xml | 46 | return xml |
|---|
| 52 | | 47 | |
|---|
| 53 | def getitems(self,r): | 48 | def getitems(self,r): |
|---|
| 54 | """This is the bloglines-style interface""" | 49 | """This is the bloglines-style interface""" |
|---|
| 55 | """See http://www.bloglines.com/services/api/getitems """ | 50 | """See http://www.bloglines.com/services/api/getitems """ |
|---|
| 56 | | 51 | |
|---|
| 57 | read = r.get_form_var('n') | 52 | read = r.get_form_var('n') |
|---|
| 58 | """ 'n' parameter - 1 marks downloaded items as read, 0 does not.""" | 53 | """ 'n' parameter - 1 marks downloaded items as read, 0 does not.""" |
|---|
| 59 | | 54 | |
|---|
| 60 | date = r.get_form_var('d') | 55 | date = r.get_form_var('d') |
|---|
| 61 | """ 'd' parameter - date to get new entries since. """ | 56 | """ 'd' parameter - date to get new entries since. """ |
|---|
| 62 | | 57 | |
|---|
| 76 | | 73 | |
|---|
| 77 | | 74 | |
|---|
| 78 | """HTTP Status Response | 75 | """HTTP Status Response |
|---|
| 79 | | 76 | |
|---|
| 80 | * 200 - normal | 77 | * 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) | 78 | * 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 | 79 | * 401 - incorrect email address or password |
|---|
| 83 | * 403 - invalid or missing BloglinesSubId | 80 | * 403 - invalid or missing BloglinesSubId |
|---|
| 84 | * 410 - subscription has been deleted | 81 | * 410 - subscription has been deleted |
|---|
| 85 | """ | 82 | """ |
|---|
| 86 | | 83 | |
|---|
| 87 | def serialise(self,objs): | 84 | def serialise(self,objs): |
|---|
| 88 | """Serialises a list of rdf objects, supplied, as RDF/XML.""" | 85 | """Serialises a list of rdf objects, supplied, as RDF/XML.""" |
|---|
| 89 | from rdfobj import dc | 86 | from rdfobj import dc |
|---|
| 90 | dc = rdfobj.dc | 87 | dc = rdfobj.dc |
|---|
| 91 | out = '' | 88 | out = '' |
|---|
| 92 | # proper serialisation | 89 | # proper serialisation |
|---|
| 93 | tmpstore = RDF.MemoryStorage() | 90 | tmpstore = RDF.MemoryStorage() |
|---|
| 94 | tmpmodel = RDF.Model(tmpstore) | 91 | tmpmodel = RDF.Model(tmpstore) |
|---|
| 95 | for o in objs: | 92 | for o in objs: |
|---|
| 96 | statement = RDF.Statement(RDF.Uri(o.uri()),None,None) | 93 | statement = RDF.Statement(RDF.Uri(o.uri()),None,None) |
|---|
| 97 | statements = self.bbox.model.model.find_statements(statement) | 94 | statements = self.bbox.model.model.find_statements(statement) |
|---|
| 98 | for s in statements: | 95 | for s in statements: |
|---|
| 99 | tmpmodel.add_statement(s) | 96 | tmpmodel.add_statement(s) |
|---|
| 100 | ser = RDF.Serializer() | 97 | ser = RDF.Serializer() |
|---|
| 101 | out = ser.serialize_model_to_string(tmpmodel) | 98 | out = ser.serialize_model_to_string(tmpmodel) |
|---|
| 102 | return out | 99 | return out |
|---|
| 103 | | 100 | |
|---|
| 104 | from quixote.errors import AccessError | 101 | from quixote.errors import AccessError |
|---|
| 105 | status_code = 401 | 102 | status_code = 401 |
|---|
| 106 | title = "Unauthorized" | 103 | title = "Unauthorized" |
|---|
| 107 | description = "You are not authorized to access this resource." | 104 | description = "You are not authorized to access this resource." |
|---|
| 108 | | 105 | |
|---|
| 109 | class UnauthorizedError(AccessError): | 106 | class UnauthorizedError(AccessError): |
|---|
| 110 | """The request requires user authentication. | 107 | """The request requires user authentication. |
|---|
| 111 | | 108 | |
|---|
| 112 | This subclass of AccessError sends a 401 instead of a 403, | 109 | This subclass of AccessError sends a 401 instead of a 403, |
|---|
| 113 | hinting that the client should try again with authentication.""" | 110 | hinting that the client should try again with authentication.""" |
|---|
| 114 | | 111 | |
|---|
| 115 | def __init__(self, realm='Protected', public_msg=None, private_msg=None): | 112 | def __init__(self, realm='Protected', public_msg=None, private_msg=None): |
|---|
| 116 | self.realm = realm | 113 | self.realm = realm |
|---|
| 117 | AccessError.__init__(self, public_msg, private_msg) | 114 | AccessError.__init__(self, public_msg, private_msg) |
|---|
| 118 | | 115 | |
|---|
| 119 | def format(self, request): | 116 | def format(self, request): |
|---|
| 120 | request.response.set_header('WWW-Authenticate', 'Basic realm="%s"' % self.realm) | 117 | request.response.set_header('WWW-Authenticate', 'Basic realm="%s"' % self.realm) |
|---|
| 121 | return AccessError.format(self, request) | 118 | return AccessError.format(self, request) |
|---|