def get(self, span_or_address): "Print content for virtual positions at address or in range. " if not hasattr(span_or_address, 'start'): addr = span_or_address ccnt = addr.depth() if ccnt >= 5: # Retrieve one or more vpos for vstr in Entry raise Exception("Vpos unhandled: %s" % ccnt) elif ccnt == 4: # Retrieve full vdata for given vstream of Entry node, vtype = addr.split() assert vtype.isroot, vtype # Retrieve Entry vstream entry = api.get(node) # LOCAL ## XXX: db import.. move to API #from google.appengine.ext import db #logging.info([vtype, entry.content]) #vstr = db.get(entry.content[vtype[0]-1]) #start = span_or_address ##offset = xu88.Offset( ## start.split()[0].subcomponent(entry.leafs+1).digits) ## FIXME: ugly: #offset = xu88.Offset((len(start)-1) * '0.' + # str(entry.leafs)) #span = xu88.Span(start, offset) ##print span, `span`, str(span) ##print span.start ##print span.end() vdata = entry.fetch_content(vtype[0]) # Identify vstream span = entry.get_content_span() self.response.headers["Content-Location"] = '' s = StringIO() span.write(s) self.response.headers["Content-ID"] = s.getvalue() self.response.headers["Content-Location"] = '/content/%s' %\ s.getvalue().replace('.0.', '/') return vdata.data elif ccnt == 3: # redirect to a list of all vstr for Entry # Retrieve all of vstr in Entry start = addr node = api.get(start) # Get Entry #print node offset = xu88.Offset((len(addr)-2) * '0.' + str(node.leafs)) span = xu88.Span(addr, offset) #print span else: raise "RouteError: /content/%s" % addr else: span = span_or_address return api.deref(span)
def get(self, t_addr): "Get the Node at address node(/channel(/entry)). " tcnt = t_addr.depth() if tcnt > 3: raise RouteError("Node view cannot render virtual address: %s. " % t_addr) v = api.get(t_addr) return v
def open(self, docid): doc = api.get(docid) assert isinstance(doc, Entry) self.session[docid] = doc return doc
def exists(self, docid): try: doc = api.get(docid) except NotFound, e: return False
def get(self, span_or_address): """Print nodes at address or range. """ if hasattr(span_or_address, 'start'): return '\r\n'.join(map(str, api.list_nodes(span_or_address))) else: return str(api.get(span_or_address))