Esempio n. 1
1
 def translate_path(self, path_):
     """
      Now accepts local fitting paths automatically
     E.g. "/path/to/www-dir/foo.png" is valid if that folder exists.
     Now it won't change the path to "/path/to/www-dir/foo.png/path/to/www-dir/foo.png", like it did before.
     :param path: path for the webserver.
     :return:
     """
     if path.exists(path_):
         return path_
     if py3:
         super(BetterHTTPRequestHandler, self).translate_path(path_)
     else:
         SimpleHTTPRequestHandler.translate_path(self, path_)
     return path_
Esempio n. 2
0
 def translate_path(self, path):
     if os.path.exists(path):
         return path
     if py3:
         super(MyHTTPRequestHandler, self).translate_path(path)
     else:
         SimpleHTTPRequestHandler.translate_path(self, path)
     #half = int(len(path)/2)
     #if path.startswith("/") and len(path) % 2 == 0 and path[half:] == path[:half]:
     #	return path[half:]
     return path
Esempio n. 3
0
	def translate_path(self, path):
		if os.path.exists(path):
			return path
		if py3:
			super(MyHTTPRequestHandler, self).translate_path(path)
		else:
			SimpleHTTPRequestHandler.translate_path(self, path)
		#half = int(len(path)/2)
		#if path.startswith("/") and len(path) % 2 == 0 and path[half:] == path[:half]:
		#	return path[half:]
		return path
Esempio n. 4
0
 def translate_path(self, path):
     lv = self._get_viewer()
     if not os.path.exists(path):
         #print(' - not found in cwd')
         if path[0] == '/': path = path[1:]
         path = os.path.join(lv.htmlpath, path)
         if os.path.exists(path) and os.path.isfile(path):
             #print(' - found in htmlpath')
             return path
         else:
             #print(' - not found in htmlpath')
             return SimpleHTTPRequestHandler.translate_path(self, self.path)
     else:
         return SimpleHTTPRequestHandler.translate_path(self, path)
Esempio n. 5
0
 def translate_path(self, path_):
     """
      Now accepts local fitting paths automatically
     E.g. "/path/to/www-dir/foo.png" is valid if that folder exists.
     Now it won't change the path to "/path/to/www-dir/foo.png/path/to/www-dir/foo.png", like it did before.
     :param path: path for the webserver.
     :return:
     """
     if path.exists(path_):
         return path_
     if py3:
         super(BetterHTTPRequestHandler, self).translate_path(path_)
     else:
         SimpleHTTPRequestHandler.translate_path(self, path_)
     return path_
Esempio n. 6
0
    def translate_path(self, path):
        '''
        translates 'path' (the path-part of an uri) to a file-system based
        path. 

        we assume self.server.folder to be the standard chroot-folder. if
        the user tries to access /packages, the self.server.packages folder
        is used as the chroot

        '''

        chroot = self.server.chroot
        if path.find('/packages/') == 0:
            chroot = self.server.packages
            _, path = path.split('/packages/', 1)

        if not os.path.isabs(chroot):
            chroot = os.path.abspath(chroot)

        result = SimpleHTTPRequestHandler.translate_path(self, path)
        _, result = result.split(os.getcwd(), 1)
        if len(result) > 0 and result[0] == '/':
            result = result[1:]

        result = os.path.join(chroot, result)
        return result
Esempio n. 7
0
    def translate_path(self, path):
        """
        translates 'path' (the path-part of an uri) to a file-system based
        path. 

        we assume self.server.folder to be the standard chroot-folder. if
        the user tries to access /packages, the self.server.packages folder
        is used as the chroot

        """

        chroot = self.server.chroot
        if path.find("/packages/") == 0:
            chroot = self.server.packages
            _, path = path.split("/packages/", 1)

        if not os.path.isabs(chroot):
            chroot = os.path.abspath(chroot)

        result = SimpleHTTPRequestHandler.translate_path(self, path)
        _, result = result.split(os.getcwd(), 1)
        if len(result) > 0 and result[0] == "/":
            result = result[1:]

        result = os.path.join(chroot, result)
        return result
Esempio n. 8
0
    def translate_path(self, path):
        """Serve the pages directory instead of the current directory."""

        pages_dir = os.path.relpath(
            os.path.join(os.path.dirname(__file__), '..', '..', 'html_pages'))

        return SimpleHTTPRequestHandler.translate_path(
            self, '/' + pages_dir + path)
Esempio n. 9
0
    def translate_path(self, path):
        """Serve the pages directory instead of the current directory."""

        pages_dir = os.path.relpath(
            os.path.join(os.path.dirname(__file__), 'html_pages'))

        return SimpleHTTPRequestHandler.translate_path(self,
                                                       '/' + pages_dir + path)
Esempio n. 10
0
    def translate_path(self, path):
        """Change working directory and translate path.

        Returns:
            str: Path to web server resource

        """
        os.chdir(os.path.join(os.path.dirname(__file__), "web"))
        return SimpleHTTPRequestHandler.translate_path(self, path)
Esempio n. 11
0
    def translate_path(self, path):
        """Change working directory and translate path.

        Returns:
            str: Path to web server resource

        """
        os.chdir(os.path.join(os.path.dirname(__file__), "web"))
        return SimpleHTTPRequestHandler.translate_path(self, path)
Esempio n. 12
0
 def translate_path(self, path):
     path = SimpleHTTPRequestHandler.translate_path(self, path)
     if os.path.isdir(path):
         for file in iglob(path + "*.html"):
             if os.path.basename(file).startswith("Visualization"):
                 return file
             # for ext in ".html", ".htm", ".txt":
             #     index = path + "/" + base + ext
             #     if os.path.exists(index):
             #         return index
     return path
Esempio n. 13
0
 def translate_path(self, path):
     path = SimpleHTTPRequestHandler.translate_path(self, path)
     print("HTTPServer: requested {}".format(path))
     if not path.startswith(path_id):
         print("HTTPServer: ignoring request for {}".format(path), file=sys.stderr)
         return "/dev/null"
     for src, dest in path_rewrites:
         if path.startswith(src):
             newpath = dest + path[len(src):]
             print("HTTPServer: rewriting {}->{}".format(path, newpath), file=sys.stderr)
             return newpath
     return path
Esempio n. 14
0
 def translate_path(self, path):
     path = SimpleHTTPRequestHandler.translate_path(self, path)
     print("HTTPServer: requested {}".format(path))
     if not path.startswith(path_id):
         print("HTTPServer: ignoring request for {}".format(path))
         return "/dev/null"
     for src, dest in path_rewrites:
         if path.startswith(src):
             newpath = dest + path[len(src):]
             print("HTTPServer: rewriting {}->{}".format(path, newpath))
             return newpath
     return path
Esempio n. 15
0
    def translate_path(self, path):
        fs_path = SimpleHTTPRequestHandler.translate_path(self, path)
        if self.path.endswith('/'):
            for index in "index.html", "index.htm", "index.shtml":
                index = os.path.join(fs_path, index)
                if os.path.exists(index):
                    fs_path = index
                    break

        if (fs_path.endswith('.html') or fs_path.endswith(".shtml")) and os.path.exists(fs_path):
            content = ssi(fs_path, path)
            fs_path = self.create_temp_file(fs_path, content)
        return fs_path
Esempio n. 16
0
    def translate_path(self, path):
        if path == '/favicon.ico':
            # Browsers sometimes ask for this. Send them to the quadplay
            # directory instead
            return quad_filepath + '/console/favicon.ico'

        elif isWindows and server_root_filepath == '':
            # Need the whole path, since the "cwd" is wrong
            return self.path.split('?')[0]
        else:
            # Intentionally use Python 2 super syntax for potential
            # backward compatibility
            result = SimpleHTTPRequestHandler.translate_path(self, path)
            return result
Esempio n. 17
0
    def translate_path(self, path):
        site_path = urlparse(config.site.url).path
        if (len(site_path.strip("/")) > 0 and not path.startswith(site_path)):
            self.error_message_format = self.error_template
            return ""  # Results in a 404

        p = SimpleHTTPRequestHandler.translate_path(self, path)
        if len(site_path.strip("/")) > 0:
            build_path = os.path.join(os.getcwd(),
                                      util.path_join(site_path.strip("/")))
        else:
            build_path = os.getcwd()
        build_path = re.sub(build_path, os.path.join(os.getcwd(), "_site"), p)
        return build_path
Esempio n. 18
0
 def translate_path(self, path):
     if self.path.startswith(external_resource_prefix):
         return external_mesh_dir + path[len(external_resource_prefix):]
     else:
         return SimpleHTTPRequestHandler.translate_path(self, path)
Esempio n. 19
0
 def translate_path(self, path):
     os.chdir(os.path.join(os.path.dirname(__file__), 'web'))
     return SimpleHTTPRequestHandler.translate_path(self, path)
Esempio n. 20
0
 def translate_path(self, path):
     if path.startswith(self.node_dir):
         return self.main_dir + path
     else:
         return SimpleHTTPRequestHandler.translate_path(self, path)
Esempio n. 21
0
 def translate_path(self, path):
     path = SimpleHTTPRequestHandler.translate_path(self, path)
     relpath = os.path.relpath(path, os.getcwd())
     fullpath = os.path.join(self.server.base_path, relpath)
     return fullpath
Esempio n. 22
0
 def translate_path(self, path):
     if path.startswith(self.node_dir):
         return self.main_dir + path
     else:
         return SimpleHTTPRequestHandler.translate_path(self, path)
Esempio n. 23
0
 def translate_path(self, path):
     document_root = self.server.document_root
     path = SimpleHTTPRequestHandler.translate_path(self, path)
     requested_uri = os.path.relpath(path, os.getcwd())
     return os.path.join(document_root, requested_uri)
Esempio n. 24
0
 def translate_path(self, path):
     tpath = SimpleHTTPRequestHandler.translate_path(
         self, out_path + path)
     return tpath
Esempio n. 25
0
 def translate_path(self, path):
     path = SimpleHTTPRequestHandler.translate_path(self, path)
     relpath = os.path.relpath(path, self.server.cwd)
     fullpath = os.path.join(self.server.root_dir, relpath)
     return fullpath