'Test whether self.path corresponds to a CGI script.
Returns True and updates the cgi_info attribute to the tuple
(dir, rest) if self.path requires running a CGI script.
Returns False otherwise.
If any exception is raised, the caller should assume that
self.path was rejected as invalid and act accordingly.
The default implementation tests whether the normalized url
path begins with one of the strings in self.cgi_directories
(and the next character is a \'/\' or the end of the string).'

def is_cgi(self):

    collapsed_path = _url_collapse_path(urllib.parse.unquote(self.path))
    dir_sep = collapsed_path.find('/', 1)
    (head, tail) = (collapsed_path[:dir_sep], collapsed_path[(dir_sep + 1):])
    if (head in self.cgi_directories):
        self.cgi_info = (head, tail)
        return True
    return False
