Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7608969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:03:26+00:00 2026-05-31T01:03:26+00:00

I’m trying to make a small testing server for Bugzilla so I can test

  • 0

I’m trying to make a small testing server for Bugzilla so I can test out changes I make before they are deployed to the main Apache based server. I’m most familiar with Python, and I was wanting to make Python’s built-in HTTP server run Bugzilla’s CGI programs.

Unfortunately, Bugzilla has lots more than CGI apps. It has a bunch of css and other data that is served up directly. This means the handler needs to deal with those as well. I would like to set up a WSGI handler that looks at the request URL and appropriately routes the request to either one of the Bugzilla CGI scripts or pulls the data directly from the filesystem.

Is there a better way to accomplish what I want to do? If there isn’t, is there a WSGI app out there already that will set up a CGI environment and call out to a CGI app via Python’s subprocess module?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T01:03:27+00:00Added an answer on May 31, 2026 at 1:03 am

    Here is a solution that works, though it’s rather ugly and kind of slow. It demands a separate CGIApplication object for each CGI script you want to run. So if you have a directory full of them, you will need to instantiate a different CGIApplication object for each one. When you instantiate it, of course, is up to you. You can choose to instantiate new ones for every request, but you will likely save a bit of time if you somehow avoid this.

    import os
    import os.path as _osp
    import re
    import subprocess
    import io
    import email.parser
    
    env_forward = re.compile('^[A-Z][A-Z0-9_]*$')
    header_match = re.compile(b'^(.*?\\n[ \\t\\r]*\\n)(.*)$', re.M | re.S)
    env_whitelist = frozenset(('AUTH_TYPE', 'CONTENT_LENGTH', 'CONTENT_TYPE',
                               'DOCUMENT_ROOT', 'QUERY_STRING', 'PATH_INFO',
                               'PATH_TRANSLATED', 'REMOTE_ADDR', 'REMOTE_PORT',
                               'REMOTE_IDENT', 'REMOTE_USER', 'REQUEST_METHOD',
                               'REQUEST_URI', 'SCRIPT_NAME',
                               'SERVER_ADDR', 'SERVER_ADMIN', 'SERVER_NAME',
                               'SERVER_PORT', 'SERVER_PROTOCOL',
                               'SERVER_SIGNATURE', 'SERVER_SOFTWARE'))
    
    class CGIApplication(object):
        def __init__(self, appfname):
            self._appfname = _osp.abspath(appfname)
    
        def __call__(self, environ, start_respose):
            appenv = {item[0]: item[1] \
                          for item in environ.items() \
                          if ((item[0] in env_whitelist) or
                              item[0].startswith('HTTP_'))}
            appenv['GATEWAY_INTERFACE'] = 'CGI/1.1'
            appenv['PATH'] = '/usr/local/bin:/usr/bin:/bin'
            appenv['SCRIPT_FILENAME'] = self._appfname
            nbytes_for_cgi = appenv.get('CONTENT_LENGTH', '')
            nbytes_for_cgi = (int(nbytes_for_cgi) if nbytes_for_cgi != '' else 0)
    
            args = [self._appfname]
            query = environ.get('QUERY_STRING', None)
            query = query.replace('+', ' ')
            if '=' not in query:
                args.append(query)
            proc = subprocess.Popen(args,
                                    stdin=subprocess.PIPE,
                                    stdout=subprocess.PIPE,
                                    stderr=subprocess.PIPE,
                                    env = appenv,
                                    cwd = _osp.dirname(self._appfname))
            bytes_read = 0
            data_for_cgi = io.BytesIO()
            while bytes_read < nbytes_for_cgi:
                data = environ['wsgi.input'].read(nbytes_for_cgi - bytes_read)
                bytes_read += len(data)
                data_for_cgi.write(data)
                data = None
            data_for_cgi = data_for_cgi.getvalue()
            output, errdata = proc.communicate(data_for_cgi)
            data_for_cgi = None
            proc.stdin.close()
            proc.stdout.close()
            proc.stderr.close()
            try:
                errdata = errdata.decode('utf-8')
            except UnicodeDecodeError:
                errdata = errdata.decode('iso8859-1')
            environ['wsgi.errors'].write(errdata)
            errdata = None
            if proc.returncode != 0:
                start_respose('500 Internal Server Error',
                              [('Content-Type', 'text/plain')])
                return (b"CGI application died with non-zero return code.\n",)
            else:
                output_hdr = header_match.match(output)
                output_hdr, output = output_hdr.groups()
                parser = email.parser.HeaderParser()
                headers = parser.parsestr(output_hdr.decode('iso8859-1'))
                status = headers.get_all('Status', ['200 OK'])[-1]
                del headers['Status']
                start_respose(status, list(headers.items()))
                return (output,)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.