def get_resource_inst(self, path, environ): """Return HgResource object for path. See DAVProvider.get_resource_inst() """ self._count_get_resource_inst += 1 # HG expects the resource paths without leading '/' localHgPath = path.strip("/") rev = None cmd, rest = util.pop_path(path) if cmd == "": return VirtualCollection( path, environ, "root", ["edit", "released", "archive"] ) elif cmd == "edit": localHgPath = rest.strip("/") rev = None elif cmd == "released": localHgPath = rest.strip("/") rev = "tip" elif cmd == "archive": if rest == "/": # Browse /archive: return a list of revision folders: loglist = self._get_log(limit=10) members = [compat.to_native(m["local_id"]) for m in loglist] return VirtualCollection(path, environ, "Revisions", members) revid, rest = util.pop_path(rest) try: int(revid) except Exception: # Tried to access /archive/anyname return None # Access /archive/19 rev = revid localHgPath = rest.strip("/") else: return None # read mercurial repo into request cache cache = self._get_repo_info(environ, rev) if localHgPath in cache["filedict"]: # It is a version controlled file return HgResource(path, False, environ, rev, localHgPath) if localHgPath in cache["dirinfos"] or localHgPath == "": # It is an existing folder return HgResource(path, True, environ, rev, localHgPath) return None
def get_resource_inst(self, path, environ): """Return HgResource object for path. See DAVProvider.get_resource_inst() """ self._count_get_resource_inst += 1 # HG expects the resource paths without leading '/' localHgPath = path.strip("/") rev = None cmd, rest = util.pop_path(path) if cmd == "": return VirtualCollection( path, environ, "root", ["edit", "released", "archive"] ) elif cmd == "edit": localHgPath = rest.strip("/") rev = None elif cmd == "released": localHgPath = rest.strip("/") rev = "tip" elif cmd == "archive": if rest == "/": # Browse /archive: return a list of revision folders: loglist = self._get_log(limit=10) members = [compat.to_native(l["local_id"]) for l in loglist] return VirtualCollection(path, environ, "Revisions", members) revid, rest = util.pop_path(rest) try: int(revid) except Exception: # Tried to access /archive/anyname return None # Access /archive/19 rev = revid localHgPath = rest.strip("/") else: return None # read mercurial repo into request cache cache = self._get_repo_info(environ, rev) if localHgPath in cache["filedict"]: # It is a version controlled file return HgResource(path, False, environ, rev, localHgPath) if localHgPath in cache["dirinfos"] or localHgPath == "": # It is an existing folder return HgResource(path, True, environ, rev, localHgPath) return None
def handle_move(self, dest_path): """Handle a MOVE request natively.""" destType, destHgPath = util.pop_path(dest_path) destHgPath = destHgPath.strip("/") ui = self.provider.ui repo = self.provider.repo _logger.info("handle_copy %s -> %s" % (self.localHgPath, destHgPath)) if self.rev is None and destType == "edit": # MOVE /edit/a/b to /edit/c/d: turn into 'hg rename -f a/b c/d' commands.rename(ui, repo, self.localHgPath, destHgPath, force=True) elif self.rev is None and destType == "released": # MOVE /edit/a/b to /released/c/d # This is interpreted as 'hg commit a/b' (ignoring the dest. path) self._commit("WsgiDAV commit (MOVE %s -> %s)" % (self.path, dest_path)) else: raise DAVError(HTTP_FORBIDDEN) # Return True: request was handled return True
def handle_move(self, dest_path): """Handle a MOVE request natively. """ destType, destHgPath = util.pop_path(dest_path) destHgPath = destHgPath.strip("/") ui = self.provider.ui repo = self.provider.repo _logger.info("handle_copy %s -> %s" % (self.localHgPath, destHgPath)) if self.rev is None and destType == "edit": # MOVE /edit/a/b to /edit/c/d: turn into 'hg rename -f a/b c/d' commands.rename(ui, repo, self.localHgPath, destHgPath, force=True) elif self.rev is None and destType == "released": # MOVE /edit/a/b to /released/c/d # This is interpreted as 'hg commit a/b' (ignoring the dest. path) self._commit("WsgiDAV commit (MOVE %s -> %s)" % (self.path, dest_path)) else: raise DAVError(HTTP_FORBIDDEN) # Return True: request was handled return True
def testBasics(self): """Test basic tool functions.""" assert join_uri("/a/b", "c") == "/a/b/c" assert join_uri("/a/b/", "c") == "/a/b/c" assert join_uri("/a/b", "c", "d") == "/a/b/c/d" assert join_uri("a/b", "c", "d") == "a/b/c/d" assert join_uri("/", "c") == "/c" assert join_uri("", "c") == "/c" assert not is_child_uri("/a/b", "/a/") assert not is_child_uri("/a/b", "/a/b") assert not is_child_uri("/a/b", "/a/b/") assert not is_child_uri("/a/b", "/a/bc") assert not is_child_uri("/a/b", "/a/bc/") assert is_child_uri("/a/b", "/a/b/c") assert is_child_uri("/a/b", "/a/b/c") assert not is_equal_or_child_uri("/a/b", "/a/") assert is_equal_or_child_uri("/a/b", "/a/b") assert is_equal_or_child_uri("/a/b", "/a/b/") assert not is_equal_or_child_uri("/a/b", "/a/bc") assert not is_equal_or_child_uri("/a/b", "/a/bc/") assert is_equal_or_child_uri("/a/b", "/a/b/c") assert is_equal_or_child_uri("/a/b", "/a/b/c") assert lstripstr("/dav/a/b", "/dav") == "/a/b" assert lstripstr("/dav/a/b", "/DAV") == "/dav/a/b" assert lstripstr("/dav/a/b", "/DAV", True) == "/a/b" assert pop_path("/a/b/c") == ("a", "/b/c") assert pop_path("/a/b/") == ("a", "/b/") assert pop_path("/a/") == ("a", "/") assert pop_path("/a") == ("a", "/") assert pop_path("/") == ("", "") assert pop_path("") == ("", "") self.assertEqual(shift_path("", "/a/b/c"), ("a", "/a", "/b/c")) self.assertEqual(shift_path("/a", "/b/c"), ("b", "/a/b", "/c")) self.assertEqual(shift_path("/a/b", "/c"), ("c", "/a/b/c", "")) self.assertEqual(shift_path("/a/b/c", "/"), ("", "/a/b/c", "")) self.assertEqual(shift_path("/a/b/c", ""), ("", "/a/b/c", ""))
def testBasics(self): """Test basic tool functions.""" assert join_uri("/a/b", "c") == "/a/b/c" assert join_uri("/a/b/", "c") == "/a/b/c" assert join_uri("/a/b", "c", "d") == "/a/b/c/d" assert join_uri("a/b", "c", "d") == "a/b/c/d" assert join_uri("/", "c") == "/c" assert join_uri("", "c") == "/c" assert not is_child_uri("/a/b", "/a/") assert not is_child_uri("/a/b", "/a/b") assert not is_child_uri("/a/b", "/a/b/") assert not is_child_uri("/a/b", "/a/bc") assert not is_child_uri("/a/b", "/a/bc/") assert is_child_uri("/a/b", "/a/b/c") assert is_child_uri("/a/b", "/a/b/c") assert not is_equal_or_child_uri("/a/b", "/a/") assert is_equal_or_child_uri("/a/b", "/a/b") assert is_equal_or_child_uri("/a/b", "/a/b/") assert not is_equal_or_child_uri("/a/b", "/a/bc") assert not is_equal_or_child_uri("/a/b", "/a/bc/") assert is_equal_or_child_uri("/a/b", "/a/b/c") assert is_equal_or_child_uri("/a/b", "/a/b/c") assert lstripstr("/dav/a/b", "/dav") == "/a/b" assert lstripstr("/dav/a/b", "/DAV") == "/dav/a/b" assert lstripstr("/dav/a/b", "/DAV", True) == "/a/b" assert pop_path("/a/b/c") == ("a", "/b/c") assert pop_path("/a/b/") == ("a", "/b/") assert pop_path("/a/") == ("a", "/") assert pop_path("/a") == ("a", "/") assert pop_path("/") == ("", "") assert pop_path("") == ("", "") self.assertEqual(shift_path("", "/a/b/c"), ("a", "/a", "/b/c")) self.assertEqual(shift_path("/a", "/b/c"), ("b", "/a/b", "/c")) self.assertEqual(shift_path("/a/b", "/c"), ("c", "/a/b/c", "")) self.assertEqual(shift_path("/a/b/c", "/"), ("", "/a/b/c", "")) self.assertEqual(shift_path("/a/b/c", ""), ("", "/a/b/c", ""))