Ejemplo n.º 1
0
	def get_page_relname(self, page, relpath):
		# Already absolute?
		if relpath[0] == '/':
			return self.get_page_dubious(relpath[1:])
		
		# Try to canonicalize the name relative to the current
		# directory. canonpath handles '..', and returns None
		# if the result attempts to back out of the root dir.
		# If that happens, we laugh and reject this thing
		# (we know it is even WORSE as an absolute path!)
		newname = utils.canonpath(page.curdir().path, relpath)
		if newname is None:
			return None

		# If the new name exists, we definetly want it.
		npage = self.get_page_dubious(newname)
		if npage and npage.exists():
			return npage

		# If it doesn't exist as a relative path, we might
		# as well call it an absolute path unless it has
		# crappy bits.
		npage = self.get_page_dubious(relpath)
		if not npage:
			# Crappy bits may be '..', so try the new name.
			return self.get_page_dubious(newname)
		else:
			return npage
Ejemplo n.º 2
0
	def get_page_paths(self, paths, relpath):
		if not paths or relpath[0] == '/':
			return None
		for p in paths:
			newname = utils.canonpath(p, relpath)
			if newname is None:
				continue
			npage = self.get_page_dubious(newname)
			if npage and npage.exists():
				return npage
		return None