# Path: viper/backend/bottle.py
# class ServerAdapter(object):
#     quiet = False
#     def __init__(self, host='127.0.0.1', port=8080, **options):
#         self.options = options
#         self.host = host
#         self.port = int(port)
# 
#     def run(self, handler): # pragma: no cover
#         pass
# 
#     def __repr__(self):
#         args = ', '.join(['%s=%s'%(k,repr(v)) for k, v in self.options.items()])
#         return "%s(%s)" % (self.__class__.__name__, args)
# 
# def run(self, **kwargs):
#     ''' Calls :func:`run` with the same parameters. '''
#     run(self, **kwargs)
# 
# Path: viper/backend/http.py
# def get_view_path():
# def init(debug=True):
# def hello():
# def home():
# def server_static(filename):
# def req_tunnel_open():
# def req_tunnel_close():
# def req_tunnel_status():
# def req_policy():
# def req_policy_enable():
# def req_policy_setting():
# def req_policy_disable():


import sys
import os
import logging
import select
import traceback
import win32serviceutil
import win32service
import win32event
        import servicemanager
from threading import Thread, Event
from viper.backend.bottle import ServerAdapter, run as bottle_run
from viper.backend import http
        from wsgiref.simple_server import make_server, WSGIRequestHandler
            from viper import reactor
__bottle_app__ = http.__app__

# bind to loopback only
__host__ = '127.0.0.1'
__port__ = '8088'

## ###########################################################################
class WSGIRefHandleOneServer(ServerAdapter):
    def run(self, handler):
        handler_class = WSGIRequestHandler
        if self.quiet:
            class QuietHandler(WSGIRequestHandler):
                def log_request(*args, **kw): pass
            handler_class = QuietHandler
        srv = make_server(self.host, self.port, handler, handler_class=handler_class)
        logging.info("Bound to {0}:{1}".format(__host__ or '0.0.0.0', __port__))
        srv_wait = srv.fileno()
        # The default  .serve_forever() call blocks waiting for requests.
        # This causes the side effect of only shutting down the service if a
        # request is handled.
        #
        # To fix this, we use the one-request-at-a-time ".handle_request"
        # method.  Instead of sitting polling, we use select to sleep for a
        # second and still be able to handle the request.
        while self.options['notifyEvent'].isSet():
            ready = select.select([srv_wait], [], [], 1)
            if srv_wait in ready[0]:
                srv.handle_request()
            continue


# Path: viper/backend/bottle.py
# class ServerAdapter(object):
#     quiet = False
#     def __init__(self, host='127.0.0.1', port=8080, **options):
#         self.options = options
#         self.host = host
#         self.port = int(port)
# 
#     def run(self, handler): # pragma: no cover
#         pass
# 
#     def __repr__(self):
#         args = ', '.join(['%s=%s'%(k,repr(v)) for k, v in self.options.items()])
#         return "%s(%s)" % (self.__class__.__name__, args)
# 
# def run(self, **kwargs):
#     ''' Calls :func:`run` with the same parameters. '''
#     run(self, **kwargs)
# 
# Path: viper/backend/http.py
# def get_view_path():
# def init(debug=True):
# def hello():
# def home():
# def server_static(filename):
# def req_tunnel_open():
# def req_tunnel_close():
# def req_tunnel_status():
# def req_policy():
# def req_policy_enable():
# def req_policy_setting():
# def req_policy_disable():


# Path: ovpnmon.py
import sys
import os
import logging
import select
import traceback
import win32serviceutil
import win32service
import win32event
        import servicemanager
from threading import Thread, Event
from viper.backend.bottle import ServerAdapter, run as bottle_run
from viper.backend import http
        from wsgiref.simple_server import make_server, WSGIRequestHandler
            from viper import reactor

__bottle_app__ = http.__app__

# bind to loopback only
__host__ = '127.0.0.1'
__port__ = '8088'

## ###########################################################################
class WSGIRefHandleOneServer(ServerAdapter):
    def run(self, handler):
        handler_class = WSGIRequestHandler
        if self.quiet:
            class QuietHandler(WSGIRequestHandler):
                def log_request(*args, **kw): pass
            handler_class = QuietHandler
        srv = make_server(self.host, self.port, handler, handler_class=handler_class)
        logging.info("Bound to {0}:{1}".format(__host__ or '0.0.0.0', __port__))
        srv_wait = srv.fileno()
        # The default  .serve_forever() call blocks waiting for requests.
        # This causes the side effect of only shutting down the service if a
        # request is handled.
        #
        # To fix this, we use the one-request-at-a-time ".handle_request"
        # method.  Instead of sitting polling, we use select to sleep for a
        # second and still be able to handle the request.
        while self.options['notifyEvent'].isSet():
            ready = select.select([srv_wait], [], [], 1)
            if srv_wait in ready[0]:
                srv.handle_request()
            continue


class BottleWsgiServer(Thread):