当前位置: 首页>>代码示例>>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;未经允许,请勿转载。