zookeeper-contrib/zookeeper-contrib-huebrowser/zkui/src/zkui/rest.py [164:229]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    def exists(self, path):
        """ Do a znode exists """
        try:
            self.get(path)
            return True
        except ZooKeeper.NotFound:
            return False

    def _do_get(self, uri):
        """ Send a GET request and convert errors to exceptions """
        try:
            req = urllib2.urlopen(uri)
            resp = simplejson.load(req)

            if 'Error' in resp:
               raise ZooKeeper.Error(resp['Error'])

            return resp
        except urllib2.HTTPError, e:
            if e.code == 404:
                raise ZooKeeper.NotFound(uri)
            raise

    def _do_post(self, uri, data=None):
        """ Send a POST request and convert errors to exceptions """
        try:
            req = urllib2.Request(uri, {})
            req.add_header('Content-Type', 'application/octet-stream')
            if data is not None:
                req.add_data(data)

            resp = simplejson.load(urllib2.urlopen(req))
            if 'Error' in resp:
                raise ZooKeeper.Error(resp['Error'])
            return resp

        except urllib2.HTTPError, e:
            if e.code == 201:
                return True
            elif e.code == 409:
                raise ZooKeeper.ZNodeExists(uri)
            elif e.code == 401:
                raise ZooKeeper.InvalidSession(uri)
            raise

    def _do_delete(self, uri):
        """ Send a DELETE request """
        req = RequestWithMethod(uri)
        req.set_method('DELETE')
        req.add_header('Content-Type', 'application/octet-stream')
        return urllib2.urlopen(req).read()

    def _do_put(self, uri, data):
        """ Send a PUT request """
        try:
            req = RequestWithMethod(uri)
            req.set_method('PUT')
            req.add_header('Content-Type', 'application/octet-stream')
            if data is not None:
                req.add_data(data)

            return urllib2.urlopen(req).read()
        except urllib2.HTTPError, e:
            if e.code == 412: # precondition failed
                raise ZooKeeper.WrongVersion(uri)
            raise
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



zookeeper-contrib/zookeeper-contrib-rest/src/python/zkrest.py [152:217]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    def exists(self, path):
        """ Do a znode exists """
        try:
            self.get(path)
            return True
        except ZooKeeper.NotFound:
            return False

    def _do_get(self, uri):
        """ Send a GET request and convert errors to exceptions """
        try:
            req = urllib2.urlopen(uri)
            resp = simplejson.load(req)

            if 'Error' in resp:
               raise ZooKeeper.Error(resp['Error'])

            return resp
        except urllib2.HTTPError, e:
            if e.code == 404:
                raise ZooKeeper.NotFound(uri)
            raise

    def _do_post(self, uri, data=None):
        """ Send a POST request and convert errors to exceptions """
        try:
            req = urllib2.Request(uri, {})
            req.add_header('Content-Type', 'application/octet-stream')
            if data is not None:
                req.add_data(data)

            resp = simplejson.load(urllib2.urlopen(req))
            if 'Error' in resp:
                raise ZooKeeper.Error(resp['Error'])
            return resp

        except urllib2.HTTPError, e:
            if e.code == 201:
                return True
            elif e.code == 409:
                raise ZooKeeper.ZNodeExists(uri)
            elif e.code == 401:
                raise ZooKeeper.InvalidSession(uri)
            raise

    def _do_delete(self, uri):
        """ Send a DELETE request """
        req = RequestWithMethod(uri)
        req.set_method('DELETE')
        req.add_header('Content-Type', 'application/octet-stream')
        return urllib2.urlopen(req).read()

    def _do_put(self, uri, data):
        """ Send a PUT request """
        try:
            req = RequestWithMethod(uri)
            req.set_method('PUT')
            req.add_header('Content-Type', 'application/octet-stream')
            if data is not None:
                req.add_data(data)

            return urllib2.urlopen(req).read()
        except urllib2.HTTPError, e:
            if e.code == 412: # precondition failed
                raise ZooKeeper.WrongVersion(uri)
            raise
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



