cubicweb/wsgi/wz.py
author Denis Laxalde <denis.laxalde@logilab.fr>
Fri, 05 Apr 2019 17:58:19 +0200
changeset 12567 26744ad37953
parent 12001 89611a994572
permissions -rw-r--r--
Drop python2 support This mostly consists in removing the dependency on "six" and updating the code to use only Python3 idioms. Notice that we previously used TemporaryDirectory from cubicweb.devtools.testlib for compatibility with Python2. We now directly import it from tempfile.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9288
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
     1
# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
     2
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
     3
#
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
     4
# This file is part of CubicWeb.
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
     5
#
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
     6
# CubicWeb is free software: you can redistribute it and/or modify it under the
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
     7
# terms of the GNU Lesser General Public License as published by the Free
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
     8
# Software Foundation, either version 2.1 of the License, or (at your option)
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
     9
# any later version.
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    10
#
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    11
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    13
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    14
# details.
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    15
#
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    16
# You should have received a copy of the GNU Lesser General Public License along
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    18
"""dummy wsgi server for CubicWeb web instances"""
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    19
11767
432f87a63057 flake8 and all
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11057
diff changeset
    20
9288
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    21
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    22
import socket
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    23
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    24
from cubicweb.wsgi.handler import CubicWebWSGIApplication
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    25
from cubicweb import ConfigurationError
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    26
from werkzeug.serving import run_simple
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    27
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    28
from logging import getLogger
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    29
LOGGER = getLogger('cubicweb')
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    30
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    31
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    32
def run(config):
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    33
    config.check_writeable_uid_directory(config.appdatahome)
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    34
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    35
    port = config['port'] or 8080
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    36
    interface = config['interface']
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    37
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    38
    app = CubicWebWSGIApplication(config)
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    39
    repo = app.appli.repo
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    40
    try:
10105
a1e8816029af [wsgi] add message about the active interface
Alain Leufroy <alain@leufroy.fr>
parents: 9288
diff changeset
    41
        LOGGER.info('starting http server on %s', config['base-url'])
9288
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    42
        run_simple(interface, port, app,
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    43
                   threaded=True,
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    44
                   use_debugger=True,
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    45
                   processes=1) # more processes yield weird errors
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    46
    finally:
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    47
        repo.shutdown()