def normalize_path(self, path): """Construct a canonical representation of a Store path. A canonical Store path is very simple: it is either the root (/), a bundle (/name), a package (/name), or a class in a package (/package/class). Any other extensions are reducible to this by the simple mechanism of cutting off any prefixing bits. """ if path == None or path == "/": # Root return "/" parts = path.split("/") if parts[0] == "": parts[0:1] = [] last = parts[-1] if PackageNode.with_name(self, last) != None or PackageNode.with_name(self, last) != None: # Bundle/Package or Bundle/Bundle ... all but the last element are unnecessary. return "/" + last else: # Package/Class ... normalize Class by stripping any Root.Smalltalk prefix. if last.startswith("Root.Smalltalk."): last = last[len("Root.Smalltalk.") :] if len(parts) >= 2: return "/" + parts[-2] + "/" + last else: return "/" + last
def get_node(self, path, rev=None): """Return a StoreNode subclass appropriate to handle the resource at path and rev.""" # Case 1: Root if not path or path == "/": return self.root parts = path.split("/") if parts[0] == "": parts = parts[1:] # Workaround to deal with us wanting to use None revisions # in places where unicode() is used if rev == "None": rev = None if len(parts) == 1: # Case 2: /BundleName bundle = BundleNode.with_name(self, parts[0], rev) if bundle != None: return bundle # Case 3: /PackageName package = PackageNode.with_name(self, parts[0], rev) if package != None: return package else: # Case 4: /PackageName/Fully.Qualified.ClassName package = PackageNode.with_name(self, parts[-2], rev) if package != None: subnode = package.subnode_named(parts[-1]) if subnode != None: return subnode raise NoSuchNode(path, rev)