def delete_node(self, nodeid): self._request('DELETE', format_node_path(self._prefix, nodeid)) result = self._conn.getresponse() if result.status != httplib.OK: raise connlib.ConnectionError() self._title_cache.remove(nodeid)
def update_node(self, nodeid, attr): body_content = plist.dumps(attr).encode("utf8") self._request('POST', format_node_path(self._prefix, nodeid), body_content) result = self._conn.getresponse() if result.status != httplib.OK: raise connlib.ConnectionError() self._title_cache.update_attr(attr)
def update_node(self, nodeid, attr): body_content = self.dumps_data(attr).encode("utf8") self._request('PUT', format_node_path(self._prefix, nodeid), body_content) result = self._conn.getresponse() if result.status == httplib.NOT_FOUND: raise connlib.UnknownNode() elif result.status != httplib.OK: raise connlib.ConnectionError() self._title_cache.update_attr(attr)
def read_node(self, nodeid): self._request('GET', format_node_path(self._prefix, nodeid)) result = self._conn.getresponse() if result.status == httplib.OK: try: attr = self.load_data(result) self._title_cache.update_attr(attr) return attr except Exception, e: raise connlib.ConnectionError( "unexpected error '%s'" % str(e), e)
def create_node(self, nodeid, attr): body_content = self.dumps_data(attr).encode("utf8") self._request('POST', format_node_path(self._prefix, nodeid), body_content) result = self._conn.getresponse() if result.status == httplib.FORBIDDEN: raise connlib.NodeExists() elif result.status != httplib.OK: raise connlib.ConnectionError("unexpected error") self._title_cache.update_attr(attr)
def index_raw(self, query): # POST /?index # query plist encoded body_content = self.dumps_data(query).encode("utf8") self._request( 'POST', format_node_path(self._notebook_prefix) + "?index", body_content) result = self._conn.getresponse() if result.status == httplib.OK: try: return self.load_data(result) except Exception, e: raise connlib.ConnectionError( "unexpected response '%s'" % str(e), e)
def get_rootid(self): """Returns nodeid of notebook root node""" # GET / self._request('GET', format_node_path(self._prefix)) result = self._conn.getresponse() if result.status == httplib.NOT_FOUND: raise connlib.UnknownNode() if result.status != httplib.OK: raise connlib.ConnectionError() # Currently only the first rootid is returned. data = self.load_data(result) rootid = data['rootids'][0] return rootid
def list_dir(self, nodeid, filename="/"): """ List data files in node """ # GET nodeid/dir/ if not filename.endswith("/"): filename += "/" self._request('GET', format_node_path(self._prefix, nodeid, filename)) result = self._conn.getresponse() if result.status == httplib.OK: try: return plist.load(result) except Exception as e: raise connlib.ConnectionError( "unexpected response '%s'" % str(e), e) else: raise connlib.FileError("cannot list node")
def list_dir(self, nodeid, filename="/"): """ List data files in node """ # Cannot list files. if not filename.endswith("/"): raise connlib.FileError() # GET nodeid/dir/ self._request( 'GET', format_node_path(self._prefix, nodeid, filename)) result = self._conn.getresponse() if result.status == httplib.OK: try: if self._version == 1: return self.load_data(result) else: data = self.load_data(result) return data['files'] except Exception, e: raise connlib.ConnectionError( "unexpected response '%s'" % str(e), e)