def _NormalizeCaseForPath(self, path, vfs_name): """Handle casing differences for different filesystems.""" # Special handling for case sensitivity of registry keys. # This mimics the behavior of the operating system. if self.supported_pathtype == rdf_paths.PathSpec.PathType.REGISTRY: self.path = self.path.replace("\\", "/") parts = path.split("/") if vfs_name == "File": # If its a file, the last component is a value which is case sensitive. lower_parts = [x.lower() for x in parts[0:-1]] lower_parts.append(parts[-1]) path = utils.Join(*lower_parts) else: path = utils.Join(*[x.lower() for x in parts]) return path
def testRDFURN(self): """Test RDFURN handling.""" # Make a url object str_url = "aff4:/hunts/W:AAAAAAAA/Results" url = rdfvalue.RDFURN(str_url, age=1) self.assertEqual(url.age, 1) self.assertEqual(url.Path(), "/hunts/W:AAAAAAAA/Results") self.assertEqual(str(url), str_url) self.assertEqual(url.scheme, "aff4") # Test the Add() function url = url.Add("some", age=2).Add("path", age=3) self.assertEqual(url.age, 3) self.assertEqual(url.Path(), "/hunts/W:AAAAAAAA/Results/some/path") self.assertEqual(str(url), utils.Join(str_url, "some", "path")) # Test that we can handle urns with a '?' and do not interpret them as # a delimiter between url and parameter list. str_url = "aff4:/C.0000000000000000/fs/os/c/regex.*?]&[+{}--" url = rdfvalue.RDFURN(str_url, age=1) self.assertEqual(url.Path(), str_url[5:]) # Some more special characters... for path in ["aff4:/test/?#asd", "aff4:/test/#asd", "aff4:/test/?#"]: self.assertEqual(path, str(rdfvalue.RDFURN(path)))
def OpenKey(self, key, sub_key): res = "%s/%s" % (key.value, sub_key.replace("\\", "/")) res = res.rstrip("/") parts = res.split("/") for cache_key in [ utils.Join(*[p.lower() for p in parts[:-1]] + parts[-1:]), res.lower() ]: if not cache_key.startswith("/"): cache_key = "/" + cache_key if cache_key in self.cache[self.prefix]: return self.__class__.FakeKeyHandle(cache_key) raise IOError()