def server_fixture(server_address_fixture, server_port_fixture): """Server instance fixture. :return (<class 'app.Server'>): Server instance object. """ host = server_address_fixture port = server_port_fixture with Server(host=host, port=port) as server_socket: return server_socket
def main(): try: path = "config/config.yaml" with open(path, 'r') as f: config = yaml.load(f) logging.basicConfig( level=config["log"]["level"], format=config["log"]["format"], ) srv = Server(config) srv.start() except Exception as e: traceback.print_exc() return 1 else: return 0
def client(): s = Server() with s.connexion_app.app.test_client() as c: yield c
"""This script starts server.""" from app import Server if __name__ == "__main__": s = Server(host='127.0.0.1', port=8000) s.run_app()
def new_server(ip): new = Server(serverIp=ip) db.session.add(new) db.session.commit()
#!/usr/bin/env python3 import os import sys _project_dir = os.path.join(os.path.dirname(__file__), os.pardir) sys.path.insert(0, _project_dir) from app import Server, RequestHandler, config sys.path.pop(0) from motor.motor_asyncio import AsyncIOMotorClient if __name__ == '__main__': db_client = AsyncIOMotorClient(config['DB_HOST'], config['DB_PORT']) handler = RequestHandler(db_client) server = Server(handler) server.serve()
from app import Server app = Server().get_app()
args = parser.parse_args() if args.migrate: create_tables() exit(0) logging.basicConfig( level=logging.DEBUG, format="%(asctime)s - %(levelname)s - %(module)s - %(message)s", handlers=[ handlers.TimedRotatingFileHandler("app.main.log", when='D', interval=1, encoding='utf-8'), logging.StreamHandler() ]) default_config = {'host': 'localhost', 'port': 8000, 'buffersize': 1024} if args.config: with open(args.config) as file: file_config = yaml.load(file, Loader=yaml.Loader) default_config.update(file_config) with Server(default_config.get('host'), default_config.get('port'), default_config.get('buffersize'), handle_default_request) as my_server: my_server.start() my_server.processing()
#!/usr/bin/env python import os import sys # current_path = os.path.dirname(os.path.abspath(__file__)) # source_path = os.path.join(current_path, "../../") # sys.path.append(os.path.join(source_path, "difang/src/")) # sys.path.append(os.path.dirname(os.path.abspath(__file__))) sys.path.append(os.path.abspath('.')) if __name__ == '__main__': from app.core.default_encoding import init_encoding init_encoding() from app import Server from webapp import webapp print "run on 0.0.0.0:5000" Server().run(webapp, host="0.0.0.0", port=5000, reload=True)
def test_invalid_is_response_valid(invalid_request_fixture): """Test that method returns False when valid request passed.""" assert not Server.is_request_valid(invalid_request_fixture)
def test_valid_is_request_valid(valid_request_fixture): """Test that method returns True when valid request passed.""" assert Server.is_request_valid(valid_request_fixture)
from app import AsterixReceiver from app import PacketHandler from app import FrameBuilder from app import NetworkBroadcaster from app import Server from app.helpers import ConfigRetriever if __name__ == '__main__': # setting up receiver incoming_broadcast_config = ConfigRetriever.get_incoming_broadcast_config() receiver = AsterixReceiver(incoming_broadcast_config['address'], incoming_broadcast_config['port']) # setting up broadcaster outgoing_broadcast_config = ConfigRetriever.get_outgoing_broadcast_config() source_mac = ConfigRetriever.get_mac_address( outgoing_broadcast_config['source_if']) broadcaster = NetworkBroadcaster(outgoing_broadcast_config['source_if'], outgoing_broadcast_config['target_mac'], source_mac, outgoing_broadcast_config['port']) # setting up handler frame_builder = FrameBuilder() handler = PacketHandler(broadcaster, frame_builder) # setting up server server = Server(receiver, handler) server.serve()
from app import Server server = Server() application = server.connexion_app.app if __name__ == "__main__": server.run()
if args.config: with open(args.config) as file: file_config = yaml.load(file, Loader=yaml.Loader) for k, v in file_config.items(): args.__setattr__(k, v) logging.basicConfig( level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s', handlers=[ logging.FileHandler(BASE_DIR + '/logs/' + datetime.today().strftime("%Y%m%d") + '_server_main.log'), logging.StreamHandler() ]) if args.migrate: module_name_list = [f'{item}.models' for item in INSTALLED_MODULES] module_path_list = (os.path.join(BASE_DIR, item, 'models.py') for item in INSTALLED_MODULES) for index, path in enumerate(module_path_list): if os.path.exists(path): __import__(module_name_list[index]) Base.metadata.create_all(engine) else: app = Server(args=args, handler=handle_default_request) app.bind() app.run()