Esempio n. 1
0
	def handle_request(self, req):
		if req.path() == "/comet/meta":
			msg = json.loads(req.read_body())
			if msg["type"] == "login":
				client.login(req, msg)
			elif msg["type"] == "chat":
				chat.broadcast(req, msg)	
			else:
				# push it into the right queue
				raise Exception("not yet implemented")

		elif req.path().startswith("/comet/client/"):
			client.handle(req)
		else:
			req.response(401)
			req.write("")
Esempio n. 2
0
def dispatch(env, start_response):
	path = env['PATH_INFO']

	if path == "/comet/meta":
		start_response('200 OK', [('Content-Type', 'text/plain')])
		body = env['wsgi.input'].read()
		msg = json.loads(body)
		if msg["type"] == "login":
			return [client.login(msg)]
		elif msg["type"] == "chat":
			chat.broadcast(msg)
		elif msg["type"] == "universe":
			msg["user"] = client.resolve(msg["uid"])
			del msg["uid"]
			chan.basic_publish(mq.msg(msg), exchange="ex", routing_key="universe")
		else:
			# push it into the right queue
			raise Exception("not yet implemented")

		return [""]	
	elif path.startswith("/comet/client/"):
		start_response('200 OK', [('Content-Type', 'text/plain')])
		return [client.handle(env)]
	else:
		return ["401"]
#test client save video to redis

from mypackage.redisController import redisController
from mypackage import globalconstant as gvar
from client import handle

videoname = "yolotest.mp4"

import os
inpath = os.getcwd() + "/"

#request
print(handle(videoname))

#test
#save redis
temp = redisController(gvar.REDIS_HOST, gvar.REDIS_PORT)
with open("{}{}".format(inpath, videoname), "r+b") as src:
    videoBytes = src.read()
temp.saveVideo(videoname, videoBytes)
print("save %s to redis" % (videoname))