~cmiller/ubuntu/quantal/deluge/fix-parameter-move-storage

« back to all changes in this revision

Viewing changes to deluge/ui/webui/lib/webpy022/wsgi.py

  • Committer: Bazaar Package Importer
  • Author(s): Cristian Greco
  • Date: 2009-11-13 02:39:45 UTC
  • mfrom: (4.1.7 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091113023945-te1bybo2912ejzuc
Tags: 1.2.0~rc3-4
* debian/control: bump build-dep on python-setuptools to (>= 0.6c9).
* debian/patches:
  - 25_r5921_fastresume_files.patch
    new, should fix problems with fresh configs;
  - 30_r5931_ipc_lockfile.patch:
    new, should fix an issue where Deluge will fail to start if there is a
    stale ipc lockfile. (Closes: #555849)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
"""
2
 
WSGI Utilities
3
 
(from web.py)
4
 
"""
5
 
 
6
 
import os, sys
7
 
 
8
 
import http
9
 
import webapi as web
10
 
from utils import listget
11
 
from net import validaddr, validip
12
 
import httpserver
13
 
 
14
 
def runfcgi(func, addr=('localhost', 8000)):
15
 
    """Runs a WSGI function as a FastCGI server."""
16
 
    import flup.server.fcgi as flups
17
 
    return flups.WSGIServer(func, multiplexed=True, bindAddress=addr).run()
18
 
 
19
 
def runscgi(func, addr=('localhost', 4000)):
20
 
    """Runs a WSGI function as an SCGI server."""
21
 
    import flup.server.scgi as flups
22
 
    return flups.WSGIServer(func, bindAddress=addr).run()
23
 
 
24
 
def runwsgi(func):
25
 
    """
26
 
    Runs a WSGI-compatible `func` using FCGI, SCGI, or a simple web server,
27
 
    as appropriate based on context and `sys.argv`.
28
 
    """
29
 
 
30
 
    if os.environ.has_key('SERVER_SOFTWARE'): # cgi
31
 
        os.environ['FCGI_FORCE_CGI'] = 'Y'
32
 
 
33
 
    if (os.environ.has_key('PHP_FCGI_CHILDREN') #lighttpd fastcgi
34
 
      or os.environ.has_key('SERVER_SOFTWARE')):
35
 
        return runfcgi(func, None)
36
 
 
37
 
    if 'fcgi' in sys.argv or 'fastcgi' in sys.argv:
38
 
        args = sys.argv[1:]
39
 
        if 'fastcgi' in args: args.remove('fastcgi')
40
 
        elif 'fcgi' in args: args.remove('fcgi')
41
 
        if args:
42
 
            return runfcgi(func, validaddr(args[0]))
43
 
        else:
44
 
            return runfcgi(func, None)
45
 
 
46
 
    if 'scgi' in sys.argv:
47
 
        args = sys.argv[1:]
48
 
        args.remove('scgi')
49
 
        if args:
50
 
            return runscgi(func, validaddr(args[0]))
51
 
        else:
52
 
            return runscgi(func)
53
 
 
54
 
    return httpserver.runsimple(func, validip(listget(sys.argv, 1, '')))