當前位置: 首頁>>代碼示例>>Python>>正文


Python WSGIServer.handle_request方法代碼示例

本文整理匯總了Python中flup.server.fcgi.WSGIServer.handle_request方法的典型用法代碼示例。如果您正苦於以下問題:Python WSGIServer.handle_request方法的具體用法?Python WSGIServer.handle_request怎麽用?Python WSGIServer.handle_request使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在flup.server.fcgi.WSGIServer的用法示例。


在下文中一共展示了WSGIServer.handle_request方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: STANDALONE

# 需要導入模塊: from flup.server.fcgi import WSGIServer [as 別名]
# 或者: from flup.server.fcgi.WSGIServer import handle_request [as 別名]
	# == STANDALONE (Retro WSGI server)
	#
	elif method == STANDALONE:
		server_address     = (
			address or app.config("address") or DEFAULT_ADDRESS,
			int(port or app.config("port") or DEFAULT_PORT)
		)
		stack.fromRetro = True
		stack.app          = lambda: app
		server = wsgi.WSGIServer(server_address, stack)
		wsgi.onError(onError)
		socket = server.socket.getsockname()
		print "Retro embedded server listening on %s:%s" % ( socket[0], socket[1])
		try:
			while runCondition():
				server.handle_request()
		except KeyboardInterrupt:
			print "done"
	elif method == WSGI:
		# When using standalone WSGI, we make sure to wrap RendezVous objects
		# that might be returned by the handlers, and make sure we wait for
		# them -- we could use a callback version instead for specific web
		# servers.
		def retro_rendezvous_wrapper( environ, start_response, request=None):
			results = stack(environ, start_response, request)
			for result in results:
				if isinstance(result, RendezVous):
					result.wait()
					continue
				yield result
		return retro_rendezvous_wrapper
開發者ID:vdt,項目名稱:retro,代碼行數:33,代碼來源:__init__.py

示例2: run

# 需要導入模塊: from flup.server.fcgi import WSGIServer [as 別名]
# 或者: from flup.server.fcgi.WSGIServer import handle_request [as 別名]

#.........這裏部分代碼省略.........

		host   = config.get("host")
		port   = config.get("port")
		try:
			import reporter as logging
		except:
			import logging
		def application(environ, startResponse):
			# Gevent needs a wrapper
			if "retro.app" not in environ: environ["retro.app"] = stack.app()
			return environ["retro.app"](environ, startResponse)
		def logged_application(environ, startResponse):
			logging.info("{0} {1}".format(environ["REQUEST_METHOD"], environ["PATH_INFO"]))
			if "retro.app" not in environ: environ["retro.app"] = stack.app()
			return environ["retro.app"](environ, startResponse)
		if method == "GEVENT":
			try:
				from gevent import wsgi
			except ImportError:
				raise ImportError("gevent is required to run `gevent` method")
			# NOTE: This starts using gevent's WSGI server (faster!)
			wsgi.WSGIServer((host,port), application, spawn=None).serve_forever()
		elif method == BJOERN:
			try:
				import bjoern
			except ImportError:
				raise ImportError("bjoern is required to run `bjoern` method")
			bjoern.run(logged_application, host, port)
		elif method == ROCKET:
			try:
				import rocket
			except ImportError:
				raise ImportError("rocket is required to run `rocket` method")
			rocket.Rocket((host, int(port)), "wsgi", {"wsgi_app":application}).start()
		elif method == WSGI:
			# When using standalone WSGI, we make sure to wrap RendezVous objects
			# that might be returned by the handlers, and make sure we wait for
			# them -- we could use a callback version instead for specific web
			# servers.
			def retro_rendezvous_wrapper( environ, start_response, request=None):
				results = stack(environ, start_response, request)
				for result in results:
					if isinstance(result, RendezVous):
						result.wait()
						continue
					yield result
			retro_rendezvous_wrapper.stack = stack
			return retro_rendezvous_wrapper
	# == STANDALONE (WSGIREF)
	#
	# elif method == STANDALONE_WSGIREF:
	# 	server_address     = (
	# 		address or app.config("address") or DEFAULT_ADDRESS,
	# 		port or app.config("port") or DEFAULT_PORT
	# 	)
	# 	server = WSGIServer(server_address, WSGIRequestHandler)
	# 	server.set_app(stack)
	# 	socket = server.socket.getsockname()
	# 	print "WSGIREF server listening on %s:%s" % ( socket[0], socket[1])
	# 	try:
	# 		while runCondition: server.handle_request()
	# 	except KeyboardInterrupt:
	# 		print "done"
	#
	# == STANDALONE (Retro WSGI server)
	#
	elif method in (STANDALONE, AIO):
		try:
			import reporter as logging
		except:
			import logging
		server_address     = (
			address or app.config("address") or DEFAULT_ADDRESS,
			int(port or app.config("port") or DEFAULT_PORT)
		)
		stack.fromRetro = True
		stack.app       = lambda: app
		if method == STANDALONE and not asynchronous:
			import retro.wsgi
			try:
				server   = retro.wsgi.WSGIServer(server_address, stack)
				retro.wsgi.onError(onError)
				socket = server.socket.getsockname()
				print ("Retro embedded server listening on %s:%s" % ( socket[0], socket[1]))
			except Exception as e:
				logging.error("Retro: Cannot bind to {0}:{1}, error: {2}".format(server_address[0], server_address[1], e))
				return -1
			# TODO: Support runCondition
			try:
				while runCondition():
					server.handle_request()
			except KeyboardInterrupt:
				print ("done")
		else:
			import retro.aio
			import asyncio
			retro.aio.run(app, server_address[0], server_address[1])
			# TODO: Support runCondition
	else:
		raise Exception("Unknown retro setup method:" + method)
開發者ID:sebastien,項目名稱:retro,代碼行數:104,代碼來源:__init__.py


注:本文中的flup.server.fcgi.WSGIServer.handle_request方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。