~ubuntu-branches/ubuntu/trusty/swift/trusty-updates

« back to all changes in this revision

Viewing changes to swift/common/wsgi.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, James Page, Chuck Short
  • Date: 2013-08-13 10:37:13 UTC
  • mfrom: (1.2.21)
  • Revision ID: package-import@ubuntu.com-20130813103713-1ctbx4zifyljs2aq
Tags: 1.9.1-0ubuntu1
[ James Page ]
* d/control: Update VCS fields for new branch locations.

[ Chuck Short ]
* New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import signal
21
21
import time
22
22
import mimetools
 
23
from gettext import gettext as _
23
24
from itertools import chain
24
25
from StringIO import StringIO
25
26
 
34
35
from swift.common.swob import Request
35
36
from swift.common.utils import capture_stdio, disable_fallocate, \
36
37
    drop_privileges, get_logger, NullLogger, config_true_value, \
37
 
    validate_configuration, get_hub
 
38
    validate_configuration, get_hub, config_auto_int_value
 
39
 
 
40
try:
 
41
    import multiprocessing
 
42
    CPU_COUNT = multiprocessing.cpu_count() or 1
 
43
except (ImportError, NotImplementedError):
 
44
    CPU_COUNT = 1
38
45
 
39
46
 
40
47
class NamedConfigLoader(loadwsgi.ConfigLoader):
165
172
    if hasattr(socket, 'TCP_KEEPIDLE'):
166
173
        sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPIDLE, 600)
167
174
    if warn_ssl:
168
 
        ssl_warning_message = 'WARNING: SSL should only be enabled for ' \
169
 
                              'testing purposes. Use external SSL ' \
170
 
                              'termination for a production deployment.'
 
175
        ssl_warning_message = _('WARNING: SSL should only be enabled for '
 
176
                                'testing purposes. Use external SSL '
 
177
                                'termination for a production deployment.')
171
178
        get_logger(conf).warning(ssl_warning_message)
172
 
        print _(ssl_warning_message)
 
179
        print(ssl_warning_message)
173
180
    return sock
174
181
 
175
182
 
224
231
    pool.waitall()
225
232
 
226
233
 
227
 
# TODO: pull more pieces of this to test more
 
234
#TODO(clayg): pull more pieces of this to test more
228
235
def run_wsgi(conf_path, app_section, *args, **kwargs):
229
236
    """
230
237
    Runs the server using the specified number of workers.
255
262
    # redirect errors to logger and close stdio
256
263
    capture_stdio(logger)
257
264
 
258
 
    worker_count = int(conf.get('workers', '1'))
 
265
    worker_count = config_auto_int_value(conf.get('workers'), CPU_COUNT)
 
266
 
259
267
    # Useful for profiling [no forks].
260
268
    if worker_count == 0:
261
269
        run_server(conf, logger, sock)
432
440
    :returns: Fresh swob.Request object.
433
441
    """
434
442
    query_string = None
 
443
    path = path or ''
435
444
    if path and '?' in path:
436
445
        path, query_string = path.split('?', 1)
437
446
    newenv = make_pre_authed_env(env, method, path=unquote(path), agent=agent,