parameters: (args=None)
docstring: You can call this function from your own program, but please note that
      this function has some side-effects that might affect your program. For
      example, util.wrap_popen3_for_win use in this method replaces implementation
      of os.popen3.
docstring_summary: You can call this function from your own program, but please note that
      this function has some side-effects that might affect your program. For
      example, util.wrap_popen3_for_win use in this method replaces implementation
      of os.popen3.
docstring_tokens: You can call this function from your own program but please note that this function has some side - effects that might affect your program . For example util . wrap_popen3_for_win use in this method replaces implementation of os . popen3 .
function: def _main(args=None):
      """You can call this function from your own program, but please note that
      this function has some side-effects that might affect your program. For
      example, util.wrap_popen3_for_win use in this method replaces implementation
      of os.popen3.
      """
  
      options, args = _parse_args_and_config(args=args)
  
      os.chdir(options.document_root)
  
      _configure_logging(options)
  
      if options.allow_draft75:
          logging.warning('--allow_draft75 option is obsolete.')
  
      if options.strict:
          logging.warning('--strict option is obsolete.')
  
      # TODO(tyoshino): Clean up initialization of CGI related values. Move some
      # of code here to WebSocketRequestHandler class if it's better.
      options.cgi_directories = []
      options.is_executable_method = None
      if options.cgi_paths:
          options.cgi_directories = options.cgi_paths.split(',')
          if sys.platform in ('cygwin', 'win32'):
              cygwin_path = None
              # For Win32 Python, it is expected that CYGWIN_PATH
              # is set to a directory of cygwin binaries.
              # For example, websocket_server.py in Chromium sets CYGWIN_PATH to
              # full path of third_party/cygwin/bin.
              if 'CYGWIN_PATH' in os.environ:
                  cygwin_path = os.environ['CYGWIN_PATH']
              util.wrap_popen3_for_win(cygwin_path)
  
              def __check_script(scriptpath):
                  return util.get_script_interp(scriptpath, cygwin_path)
  
              options.is_executable_method = __check_script
  
      if options.use_tls:
          if options.tls_module is None:
              if _import_ssl():
                  options.tls_module = _TLS_BY_STANDARD_MODULE
                  logging.debug('Using ssl module')
              elif _import_pyopenssl():
                  options.tls_module = _TLS_BY_PYOPENSSL
                  logging.debug('Using pyOpenSSL module')
              else:
                  logging.critical(
                          'TLS support requires ssl or pyOpenSSL module.')
                  sys.exit(1)
          elif options.tls_module == _TLS_BY_STANDARD_MODULE:
              if not _import_ssl():
                  logging.critical('ssl module is not available')
                  sys.exit(1)
          elif options.tls_module == _TLS_BY_PYOPENSSL:
              if not _import_pyopenssl():
                  logging.critical('pyOpenSSL module is not available')
                  sys.exit(1)
          else:
              logging.critical('Invalid --tls-module option: %r',
                               options.tls_module)
              sys.exit(1)
  
          if not options.private_key or not options.certificate:
              logging.critical(
                      'To use TLS, specify private_key and certificate.')
              sys.exit(1)
  
          if (options.tls_client_cert_optional and
              not options.tls_client_auth):
              logging.critical('Client authentication must be enabled to '
                               'specify tls_client_cert_optional')
              sys.exit(1)
      else:
          if options.tls_module is not None:
              logging.critical('Use --tls-module option only together with '
                               '--use-tls option.')
              sys.exit(1)
  
          if options.tls_client_auth:
              logging.critical('TLS must be enabled for client authentication.')
              sys.exit(1)
  
          if options.tls_client_cert_optional:
              logging.critical('TLS must be enabled for client authentication.')
              sys.exit(1)
  
      if not options.scan_dir:
          options.scan_dir = options.websock_handlers
  
      if options.use_basic_auth:
          options.basic_auth_credential = 'Basic ' + base64.b64encode(
              options.basic_auth_credential)
  
      try:
          if options.thread_monitor_interval_in_sec > 0:
              # Run a thread monitor to show the status of server threads for
              # debugging.
              ThreadMonitor(options.thread_monitor_interval_in_sec).start()
  
          server = WebSocketServer(options)
          server.serve_forever()
      except Exception, e:
          logging.critical('mod_pywebsocket: %s' % e)
          logging.critical('mod_pywebsocket: %s' % util.get_stack_trace())
          sys.exit(1)
function_tokens: def _main ( args = None ) : options , args = _parse_args_and_config ( args = args ) os . chdir ( options . document_root ) _configure_logging ( options ) if options . allow_draft75 : logging . warning ( '--allow_draft75 option is obsolete.' ) if options . strict : logging . warning ( '--strict option is obsolete.' ) # TODO(tyoshino): Clean up initialization of CGI related values. Move some # of code here to WebSocketRequestHandler class if it's better. options . cgi_directories = [ ] options . is_executable_method = None if options . cgi_paths : options . cgi_directories = options . cgi_paths . split ( ',' ) if sys . platform in ( 'cygwin' , 'win32' ) : cygwin_path = None # For Win32 Python, it is expected that CYGWIN_PATH # is set to a directory of cygwin binaries. # For example, websocket_server.py in Chromium sets CYGWIN_PATH to # full path of third_party/cygwin/bin. if 'CYGWIN_PATH' in os . environ : cygwin_path = os . environ [ 'CYGWIN_PATH' ] util . wrap_popen3_for_win ( cygwin_path ) def __check_script ( scriptpath ) : return util . get_script_interp ( scriptpath , cygwin_path ) options . is_executable_method = __check_script if options . use_tls : if options . tls_module is None : if _import_ssl ( ) : options . tls_module = _TLS_BY_STANDARD_MODULE logging . debug ( 'Using ssl module' ) elif _import_pyopenssl ( ) : options . tls_module = _TLS_BY_PYOPENSSL logging . debug ( 'Using pyOpenSSL module' ) else : logging . critical ( 'TLS support requires ssl or pyOpenSSL module.' ) sys . exit ( 1 ) elif options . tls_module == _TLS_BY_STANDARD_MODULE : if not _import_ssl ( ) : logging . critical ( 'ssl module is not available' ) sys . exit ( 1 ) elif options . tls_module == _TLS_BY_PYOPENSSL : if not _import_pyopenssl ( ) : logging . critical ( 'pyOpenSSL module is not available' ) sys . exit ( 1 ) else : logging . critical ( 'Invalid --tls-module option: %r' , options . tls_module ) sys . exit ( 1 ) if not options . private_key or not options . certificate : logging . critical ( 'To use TLS, specify private_key and certificate.' ) sys . exit ( 1 ) if ( options . tls_client_cert_optional and not options . tls_client_auth ) : logging . critical ( 'Client authentication must be enabled to ' 'specify tls_client_cert_optional' ) sys . exit ( 1 ) else : if options . tls_module is not None : logging . critical ( 'Use --tls-module option only together with ' '--use-tls option.' ) sys . exit ( 1 ) if options . tls_client_auth : logging . critical ( 'TLS must be enabled for client authentication.' ) sys . exit ( 1 ) if options . tls_client_cert_optional : logging . critical ( 'TLS must be enabled for client authentication.' ) sys . exit ( 1 ) if not options . scan_dir : options . scan_dir = options . websock_handlers if options . use_basic_auth : options . basic_auth_credential = 'Basic ' + base64 . b64encode ( options . basic_auth_credential ) try : if options . thread_monitor_interval_in_sec > 0 : # Run a thread monitor to show the status of server threads for # debugging. ThreadMonitor ( options . thread_monitor_interval_in_sec ) . start ( ) server = WebSocketServer ( options ) server . serve_forever ( ) except Exception , e : logging . critical ( 'mod_pywebsocket: %s' % e ) logging . critical ( 'mod_pywebsocket: %s' % util . get_stack_trace ( ) ) sys . exit ( 1 )