Пример #1
0
             SimpleUploadHandler.do_PUT(self)

if __name__ == '__main__':
    def help_and_exit():
        print('usage server.py port [--access_config file]')
        sys.exit(1)

    if ('--help' in sys.argv) or (len(sys.argv) not in [2,4]):
        help_and_exit()
    port = int(sys.argv[1])
    access_config_file = None
    if len(sys.argv) == 4:
        if sys.argv[2] != "--access_config":
            help_and_exit()
        access_config_file = sys.argv[3]
        if not os.path.exists(access_config_file):
            print("No such file: " + access_config_file)
            help_and_exit()

    if access_config_file == None:
        print('listening on localhost:%d' %(port))
        server = HTTPServer(('localhost', port), SimpleUploadHandler)
    else:
        print('listening on localhost:%d with access restrictions' %(port))
        auth_config = AuthConfig()
        auth_config.load_config(access_config_file)
        server = HTTPServer(('localhost', port), AuthUploadHandler)
        server.auth_config = auth_config

    server.serve_forever()