def target_node(self): if self._target_node is not None: return self._target_node env_name = self.environment_identifier() if not env_name: conf.log.warning("Failed reading identifier") raise NodeError('Target node was invalid: env_name not found') project = Project.get(env_name=env_name) # env_name might be different from project.env_name! base_url = project.get_dav_url(relative=True) path_info = normalized_base_url(self.req.uri) project_id = project.id download_config = FilesDownloadConfig(project.env_name, base_url=base_url) if not path_info.startswith(download_config.base_url): raise NodeError('Target node was invalid: uri %s does not start with %s', path_info, base_url) self._download_config = download_config try: node_factory = MappedFileNode(project_id, download_config.base_path, download_config.base_url, download_config.downloads_dir) self._target_node = MappedFileNode.from_request_path_info(path_info, node_factory) except Exception as e: conf.log.warning("Not node %s", str(e)) raise NodeError('Target node was invalid: %s', str(e)) return self._target_node
def destination_node(self): if self._destination_node is not None: return self._destination_node # If req is a sub-request, req.main is the main request. destination = self._get_header('Destination') if destination: # Parse path from url try: encoded_destination = normalized_base_url(destination) destination = urllib.unquote(encoded_destination).decode('UTF-8') self._destination_node = MappedFileNode.from_request_path_info(destination, self.target_node) except Exception as e: raise NodeError('Destination node was invalid: %s'%str(e)) return self._destination_node
def __init__(self, env_name, base_url=None): """ :param env_name: valid environment name aka identifier (not validated) :param base_url: the base url, like '/files' """ self._downloads_dir = None self.env_name = env_name files_conf = FilesConfiguration() self.base_path = filesystem.get_normalized_base_path( filesystem.safe_path(files_conf.sys_dav_root, self.env_name)) if base_url is not None: self.base_url = normalized_base_url(base_url) else: self.base_url = None if not files_conf.downloads_dir_customizable: self._downloads_dir_fetched = True self._default = files_conf.default_downloads_directory self._downloads_dir = self._default else: self._downloads_dir = None self._downloads_dir_fetched = False self._default = None self.mc = conf.getMemcachedInstance()
def __init__(self, env_name, base_url=None): """ :param env_name: valid environment name aka identifier (not validated) :param base_url: the base url, like '/files' """ self._downloads_dir = None self.env_name = env_name files_conf = FilesConfiguration() self.base_path = filesystem.get_normalized_base_path( filesystem.safe_path(files_conf.sys_dav_root, self.env_name)) if base_url is not None: self.base_url = normalized_base_url(base_url) else: self.base_url = None if not files_conf.downloads_dir_customizable: self._downloads_dir_fetched = True self._default = files_conf.default_downloads_directory self._downloads_dir = self._default else: self._downloads_dir = None self._downloads_dir_fetched = False self._default = None self.mc = conf.getMemcachedInstance()