()
| 119 | |
| 120 | |
| 121 | def main(): |
| 122 | args = ARGS.parse_args() |
| 123 | |
| 124 | if ':' in args.host: |
| 125 | args.host, port = args.host.split(':', 1) |
| 126 | args.port = int(port) |
| 127 | |
| 128 | if args.iocp: |
| 129 | from asyncio import windows_events |
| 130 | sys.argv.remove('--iocp') |
| 131 | logging.info('using iocp') |
| 132 | el = windows_events.ProactorEventLoop() |
| 133 | asyncio.set_event_loop(el) |
| 134 | |
| 135 | if args.ssl: |
| 136 | here = os.path.join(os.path.dirname(__file__), 'tests') |
| 137 | |
| 138 | if args.certfile: |
| 139 | certfile = args.certfile or os.path.join(here, 'sample.crt') |
| 140 | keyfile = args.keyfile or os.path.join(here, 'sample.key') |
| 141 | else: |
| 142 | certfile = os.path.join(here, 'sample.crt') |
| 143 | keyfile = os.path.join(here, 'sample.key') |
| 144 | |
| 145 | sslcontext = ssl.SSLContext(ssl.PROTOCOL_SSLv23) |
| 146 | sslcontext.load_cert_chain(certfile, keyfile) |
| 147 | else: |
| 148 | sslcontext = None |
| 149 | |
| 150 | loop = asyncio.get_event_loop() |
| 151 | f = loop.create_server( |
| 152 | lambda: HttpRequestHandler(debug=True, keep_alive=75), |
| 153 | args.host, args.port, |
| 154 | ssl=sslcontext) |
| 155 | svr = loop.run_until_complete(f) |
| 156 | socks = svr.sockets |
| 157 | print('serving on', socks[0].getsockname()) |
| 158 | try: |
| 159 | loop.run_forever() |
| 160 | except KeyboardInterrupt: |
| 161 | pass |
| 162 | |
| 163 | |
| 164 | if __name__ == '__main__': |
no test coverage detected