Esempio n. 1
0
		def iterate(self=self,request=request):
			context = {}
			# When the fake_start_response gets called, we will update the
			# context dict with the response status and header info, so that we
			# can output it within the aggregate response
			def fake_start_response(status, header,context=context):
				s, r = status.split(" ", 1)
				context['status'] = int(s)
				context['reason'] = r
				context['headers'] = header
			has_responded = False
			dispatcher    = self.app()._dispatcher
			# We iterate on each request embedded within the body of this
			# request
			origin = request.uri()
			for request_string in requests:
				req, headers, body = request_string.split("\r\n", 2)
				method, url = req.split(" ",1)
				# We update the current request object (instead of creating one
				# new)
				if not url or url[0] != "/": url = os.path.dirname(origin) + url
				request._environ[request.REQUEST_METHOD]=method
				request._environ[request.REQUEST_URI]=url
				# FIXME: PATH_INFO should be computed properly
				request._environ[request.PATH_INFO]=url
				request.body(body)
				# If we already generated a response, we add the response
				# spearator
				if has_responded:
					yield response_boundary
				# And now we generate the body of the request
				for res in dispatcher(request.environ(), fake_start_response, request):
					if list(context.items()):
						yield "{'status':%s,'reason':%s,'headers':%s,'body':%s}\n\n" % (
							asJSON(context['status']),
							asJSON(context['reason']),
							asJSON(context['headers']),
							asJSON(res)
						)
						del context['status']
						del context['reason']
						del context['headers']
						assert not list(context.items())
				has_responded = True
Esempio n. 2
0
	def asJS( self, asJSON ):
		return asJSON(str(self))
Esempio n. 3
0
for name,position,start,end,total,guidelines in travel_expenses:
	total = float(total)
	guidelines = float(guidelines or -1)
	department_add_expenses(name, position, "travel", start, total, guidelines)

# And hospitality expenses
for name,position,start,end,total,guidelines in hospitality_expenses:
	total = float(total)
	guidelines = float(guidelines or -1)
	department_add_expenses(name, position, "hospitality", start, total, guidelines)

# =============================================================================
# Data export
# =============================================================================

# We clean up departments with no total
deps = tuple(Department.ALL)
for i in range(0, len(deps)):
	d = deps[i]
	if d.total.all == 0:
		Department.ALL.remove(d)

# We save the expenses in a file
save("var EXPENSES=" + asJSON(Department.ALL),"dataset/expenses-by_dep.json")
save("var POSITIONS=" + asJSON(positions),"dataset/positions.json")
save("var DEPARTMENTS=" + asJSON(departments),"dataset/departments.json")

print Department.INDEX.keys(), len(Department.INDEX.keys())

# EOF