Niklas R
Niklas R

Reputation: 16890

Full fledged local CGI Server

I want to set up a local CGI Server that treats any any *.py file as a cgi-script and executes it. But using CGIHTTPServer.CGIHTTPRequestHandler does only execute files contained in the cgi_directories attribute.

How can I achieve that any Python script is executed as cgi-script ?

Upvotes: 0

Views: 521

Answers (2)

cgohlke
cgohlke

Reputation: 9437

Try replace the CGIHTTPServer.CGIHTTPRequestHandler.is_cgi function at your own risk:

import CGIHTTPServer

def is_cgi(self):
    if self.path.endswith('.py'):
        self.cgi_info = CGIHTTPServer._url_collapse_path_split(self.path)
        return True
    return False

CGIHTTPServer.CGIHTTPRequestHandler.is_cgi = is_cgi

Upvotes: 1

jcollado
jcollado

Reputation: 40414

Looking at the documentation I think that you're probably looking for this:

cgi_directories

This defaults to ['/cgi-bin', '/htbin'] and describes directories to treat as containing CGI scripts.

Hence, setting cgi_directories to whatever you need, you will be able to serve the scripts in a directory that doesn't match any of the previous names.

Alternatively, I'd say you can also at a link to the script in one of the expected directories to add access to that script.

Upvotes: 0

Related Questions