"Fossies" - the Fresh Open Source Software Archive

Member "snapcraft-3.6/tests/fake_servers/base.py" (14 Jun 2019, 1480 Bytes) of package /linux/misc/snapcraft-3.6.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 # -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
    2 #
    3 # Copyright (C) 2016, 2017 Canonical Ltd
    4 #
    5 # This program is free software: you can redistribute it and/or modify
    6 # it under the terms of the GNU General Public License version 3 as
    7 # published by the Free Software Foundation.
    8 #
    9 # This program is distributed in the hope that it will be useful,
   10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
   11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   12 # GNU General Public License for more details.
   13 #
   14 # You should have received a copy of the GNU General Public License
   15 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
   16 
   17 
   18 from pyramid import config
   19 
   20 # LP: #1733579
   21 from wsgiref import simple_server  # type: ignore
   22 
   23 
   24 class BaseFakeServer:
   25     def __init__(self, server_address):
   26         super().__init__()
   27         self.server_address = server_address
   28         configurator = config.Configurator()
   29         self.configure(configurator)
   30         app = configurator.make_wsgi_app()
   31         self.server = simple_server.make_server(
   32             self.server_address[0], self.server_address[1], app
   33         )
   34         self.server_port = self.server.server_port
   35         self.socket = self.server.socket
   36 
   37     def configure(self, configurator):
   38         # To be defined in subclasses.
   39         raise NotImplementedError()
   40 
   41     def serve_forever(self):
   42         self.server.serve_forever()
   43 
   44     def shutdown(self):
   45         self.server.shutdown()