def get(self): supported_mtypes = ['application/atomsvc+xml', 'application/xml', 'text/html'] if 'Accept' in self.request.headers: accept_hdr = self.request.headers['Accept'] else: accept_hdr = '*/*' best_mtype = mimeparse.best_match(supported_mtypes, accept_hdr) if best_mtype == 'text/html': view = HtmlView("home.html", {}) else: baseurl = self._get_baseurl() view = AtomServiceDocumentView(servicedoc.generate_service_doc(baseurl)) view = EtagView(view) self.response.headers['Content-Type'] = view.get_content_type() view.render(self.response.out) self.response.headers['Etag'] = "\"%s\"" % (view.get_etag(),)
def iter_match(self, mimerange): """ Returns a generator that iterates over the collections in the service document that accept the given mimerange. The mimerange can be a specific mimetype - "image/png" - or a range - "image/*". """ if not self.representation: headers, body = self.get() for coll in self._etree.findall(".//" + APP_COLL): accept_type = [t.text for t in coll.findall(APP_MEMBER_TYPE)] if len(accept_type) == 0: accept_type.append("application/atom+xml") coll_type = [t for t in accept_type if mimeparse.best_match([t], mimerange)] if coll_type: context = copy.copy(self.context) context.collection = absolutize(self.context.service, coll.get('href')) yield context