Exemple #1
0
class Response:
	def __init__(self, code=200, content=EmptyContent(), **kwargs):
		self.code = code
		self.content = content
		self.heads = Heads(**kwargs)
		self.heads.content_type = self.content.ctype
		self.heads.content_length = self.content._clen

	def get_forwsgi(self):
		return ("%d %s" % (self.code,RESPONSES.get(self.code, ["Unknown"])[0]), \
				self.heads._getlist(),self.content.get())
Exemple #2
0
	def refresh(self, xenviron):
		"""prepare the application to run

		* Extend this method, if you require custom preparation
		"""
		self.args = xenviron.args
		self.kwargs = xenviron.kwargs
		self.session = xenviron.session
		self.cookies = xenviron.cookies
		self.fields = xenviron.fields

		self.code = 200
		self.heads = Heads()
Exemple #3
0
class Application:
	def __init__(self, xenviron):
		self.options = xenviron.options
		self.content = TextContent(_(u"application default"))

		self.refresh(xenviron)
		self.static()

	def refresh(self, xenviron):
		"""prepare the application to run

		* Extend this method, if you require custom preparation
		"""
		self.args = xenviron.args
		self.kwargs = xenviron.kwargs
		self.session = xenviron.session
		self.cookies = xenviron.cookies
		self.fields = xenviron.fields

		self.code = 200
		self.heads = Heads()

	def static(self):
		"""prepare static content

		* Override this method to prepare content that will be prepared once
		"""
		pass

	def run(self):
		"""execute the application

		* Override this method for dynamic/semi-dynamic content
		* You should supply self.content here with your content,
		* Optionally you may supply self.rcode and/or
		self.rheads
		"""
		pass

	def get(self):
		xenviron = Struct()  # FUTURE
		xenviron.cookies = self.cookies
		xenviron.session = self.session
		return (xenviron,Response(self.code, self.content, **self.heads._getdict()))

	def redirect(self, location):
		self.code = 307
		self.heads.location = location
		self.content = EmptyContent()
Exemple #4
0
	def __init__(self, code=200, content=EmptyContent(), **kwargs):
		self.code = code
		self.content = content
		self.heads = Heads(**kwargs)
		self.heads.content_type = self.content.ctype
		self.heads.content_length = self.content._clen