~ubuntu-branches/debian/jessie/cherrypy3/jessie

« back to all changes in this revision

Viewing changes to cherrypy/_cpmodpy.py

  • Committer: Package Import Robot
  • Author(s): Gustavo Noronha Silva, JCF Ploemen, Stéphane Graber, Gustavo Noronha
  • Date: 2012-01-06 10:13:27 UTC
  • mfrom: (1.1.4) (7.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20120106101327-smxnhguqs14ubl7e
Tags: 3.2.2-1
[ JCF Ploemen ]
* New upstream release (Closes: #571196).
* Bumped Standards-Version to 3.8.4 (no changes needed).
* Removing patch 02: no longer needed, incorporated upstream.
* Updating patch 00 to match release.
* Install cherryd man page via debian/manpages.
* debian/copyright:
  + Added notice for cherrypy/lib/httpauth.py.
  + Fixed years.
* debian/watch:
  + Don't hit on the -py3 release by blocking '-' from the version.
  + Mangle upstream version, inserting a tilde for beta/rc.

[ Stéphane Graber <stgraber@ubuntu.com> ]
 * Convert from python-support to dh_python2 (#654375)
  - debian/pyversions: Removed (no longer needed)
  - debian/rules
   + Replace call to dh_pysupport by dh_python2
   + Add --with=python2 to all dh calls
  - debian/control
   + Drop build-depends on python-support
   + Bump build-depends on python-all to >= 2.6.6-3~
   + Replace XS-Python-Version by X-Python-Version
   + Remove XB-Python-Version from binary package

[ Gustavo Noronha ]
* debian/control, debian/rules, debian/manpages:
 - use help2man to generate a manpage for cherryd at build time, since
  one is no longer shipped along with the source code
* debian/control:
- add python-nose to Build-Depends, since it's used during the
  documentation build for cross-reference generation

Show diffs side-by-side

added added

removed removed

Lines of Context:
56
56
"""
57
57
 
58
58
import logging
59
 
import StringIO
 
59
import sys
60
60
 
61
61
import cherrypy
 
62
from cherrypy._cpcompat import BytesIO, copyitems, ntob
62
63
from cherrypy._cperror import format_exc, bare_error
63
 
from cherrypy.lib import http
64
 
 
 
64
from cherrypy.lib import httputil
65
65
 
66
66
 
67
67
# ------------------------------ Request-handling
71
71
def setup(req):
72
72
    from mod_python import apache
73
73
    
74
 
    # Run any setup function defined by a "PythonOption cherrypy.setup" directive.
 
74
    # Run any setup functions defined by a "PythonOption cherrypy.setup" directive.
75
75
    options = req.get_options()
76
76
    if 'cherrypy.setup' in options:
77
 
        atoms = options['cherrypy.setup'].split('::', 1)
78
 
        if len(atoms) == 1:
79
 
            mod = __import__(atoms[0], globals(), locals())
80
 
        else:
81
 
            modname, fname = atoms
82
 
            mod = __import__(modname, globals(), locals(), [fname])
83
 
            func = getattr(mod, fname)
84
 
            func()
 
77
        for function in options['cherrypy.setup'].split():
 
78
            atoms = function.split('::', 1)
 
79
            if len(atoms) == 1:
 
80
                mod = __import__(atoms[0], globals(), locals())
 
81
            else:
 
82
                modname, fname = atoms
 
83
                mod = __import__(modname, globals(), locals(), [fname])
 
84
                func = getattr(mod, fname)
 
85
                func()
85
86
    
86
87
    cherrypy.config.update({'log.screen': False,
87
88
                            "tools.ignore_headers.on": True,
141
142
        
142
143
        # Obtain a Request object from CherryPy
143
144
        local = req.connection.local_addr
144
 
        local = http.Host(local[0], local[1], req.connection.local_host or "")
 
145
        local = httputil.Host(local[0], local[1], req.connection.local_host or "")
145
146
        remote = req.connection.remote_addr
146
 
        remote = http.Host(remote[0], remote[1], req.connection.remote_host or "")
 
147
        remote = httputil.Host(remote[0], remote[1], req.connection.remote_host or "")
147
148
        
148
149
        scheme = req.parsed_uri[0] or 'http'
149
150
        req.get_basic_auth_pw()
183
184
            path = req.uri
184
185
            qs = req.args or ""
185
186
            reqproto = req.protocol
186
 
            headers = req.headers_in.items()
 
187
            headers = copyitems(req.headers_in)
187
188
            rfile = _ReadOnlyRequest(req)
188
189
            prev = None
189
190
            
202
203
                    try:
203
204
                        request.run(method, path, qs, reqproto, headers, rfile)
204
205
                        break
205
 
                    except cherrypy.InternalRedirect, ir:
 
206
                    except cherrypy.InternalRedirect:
 
207
                        ir = sys.exc_info()[1]
206
208
                        app.release_serving()
207
209
                        prev = request
208
210
                        
220
222
                        method = "GET"
221
223
                        path = ir.path
222
224
                        qs = ir.query_string
223
 
                        rfile = StringIO.StringIO()
 
225
                        rfile = BytesIO()
224
226
                
225
 
                send_response(req, response.status, response.header_list,
 
227
                send_response(req, response.output_status, response.header_list,
226
228
                              response.body, response.stream)
227
229
            finally:
228
230
                app.release_serving()
264
266
 
265
267
import os
266
268
import re
 
269
try:
 
270
    import subprocess
 
271
    def popen(fullcmd):
 
272
        p = subprocess.Popen(fullcmd, shell=True,
 
273
                             stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
 
274
                             close_fds=True)
 
275
        return p.stdout
 
276
except ImportError:
 
277
    def popen(fullcmd):
 
278
        pipein, pipeout = os.popen4(fullcmd)
 
279
        return pipeout
267
280
 
268
281
 
269
282
def read_process(cmd, args=""):
270
 
    pipein, pipeout = os.popen4("%s %s" % (cmd, args))
 
283
    fullcmd = "%s %s" % (cmd, args)
 
284
    pipeout = popen(fullcmd)
271
285
    try:
272
286
        firstline = pipeout.readline()
273
 
        if (re.search(r"(not recognized|No such file|not found)", firstline,
 
287
        if (re.search(ntob("(not recognized|No such file|not found)"), firstline,
274
288
                      re.IGNORECASE)):
275
289
            raise IOError('%s must be on your system path.' % cmd)
276
290
        output = firstline + pipeout.read()