示例#1
0
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
示例#2
0
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
示例#4
0
"""This script starts server."""

from app import Server

if __name__ == "__main__":
    s = Server(host='127.0.0.1', port=8000)
    s.run_app()
示例#5
0
def new_server(ip):
    new = Server(serverIp=ip)
    db.session.add(new)
    db.session.commit()
示例#6
0
#!/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()
示例#7
0
from app import Server

app = Server().get_app()
示例#8
0
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()
示例#9
0
#!/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)
示例#10
0
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)
示例#11
0
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)
示例#12
0
文件: run_server.py 项目: hmicn/ast
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()
示例#13
0
from app import Server

server = Server()
application = server.connexion_app.app

if __name__ == "__main__":
    server.run()
示例#14
0
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()