def assert_raises(bad): try: zkpath.normpath("foo/" + bad + "/bar") except ValueError: pass else: assert False, "exception not raised"
def test_normpath_abs(): actual = zkpath.normpath("/foo//bar/") assert actual == "/foo/bar"
def test_normpath(): actual = zkpath.normpath("foo//bar/") assert actual == "foo/bar"
def __init__( self, hosts, session_id=None, session_passwd=None, session_timeout=30.0, auth_data=None, watcher=None, allow_reconnect=True, ): self.hosts, chroot = collect_hosts(hosts) if chroot: self.chroot = zkpath.normpath(chroot) if not zkpath.isabs(self.chroot): raise ValueError("chroot not absolute") else: self.chroot = "" self.session_id = session_id self.session_passwd = session_passwd if session_passwd else str(bytearray([0] * 16)) self.session_timeout = session_timeout self.connect_timeout = session_timeout / len(self.hosts) self.read_timeout = session_timeout * 2.0 / 3.0 self.auth_data = auth_data if auth_data else set([]) self.read_only = False LOGGER.debug("session_id: %s", self.session_id) LOGGER.debug("session_passwd: 0x%s", self.session_passwd.encode("hex")) LOGGER.debug("session_timeout: %s", self.session_timeout) LOGGER.debug("connect_timeout: %s", self.connect_timeout) LOGGER.debug(" len(hosts): %s", len(self.hosts)) LOGGER.debug("read_timeout: %s", self.read_timeout) LOGGER.debug("auth_data: %s", self.auth_data) self.allow_reconnect = allow_reconnect LOGGER.debug("allow_reconnect: %s", self.allow_reconnect) self.last_zxid = 0 self._queue = PeekableQueue() self._pending = Queue() self._events = Queue() self._child_watchers = defaultdict(set) self._data_watchers = defaultdict(set) self._exists_watchers = defaultdict(set) self._default_watcher = watcher or Watcher() self.state = CONNECTING self._state_lock = threading.RLock() self._event_thread_completed = threading.Event() def event_worker(): try: while True: notification = self._events.get() if notification == self: break try: notification() except Exception: LOGGER.exception("Unforeseen error during notification") finally: LOGGER.debug("Event loop completed") self._event_thread_completed.set() self._event_thread = threading.Thread(target=event_worker, name="event-%s" % self.id) self._event_thread.daemon = True self._event_thread.start() self._writer_thread = WriterThread(self) self._writer_thread.setDaemon(True) self._writer_thread.start() self._check_state()
def _norm_root(root): return zkpath.normpath(zkpath.join("/", root))
def _prefix_root(root, path): """ Prepend a root to a path. """ return zkpath.normpath(zkpath.join(_norm_root(root), path.lstrip("/")))