Example #1
0
def respond(message, user):
	""" 
		Step 1: Extracts relevant info from user message 
		Step 2: Evaluate user status
		Step 3: send appropriate response 
	"""

	try:

		status = user.status
		if command.process(user, message):
			return

		if status == "intro":
			intro.process(user, message)

		elif status == "idle":
			idle.process(user, message)

		elif status == "workout":
			workout_log.process(user, message)

		elif status == "feedback":

			feedback.process(user, message)


	#=====[ If error caught, send user an error message and keep in same state ]=====
	except Exception as e:
		print e
		ut.send_response(ERROR_MESSAGE, user_id)
Example #2
0
    def receive_xml(self, length):
        xml_str = self.socket.recv(length)

        if not xml_str == "":
            print('Received from ' + self.username + ':')
            #print(length)
            print(xml_str)
            # TODO: Restore
            """try:
                xml = ET.ElementTree(ET.fromstring(xml_str))
                # Other commands are allowed as the user is logged in
                command.process(self, xml)
            except Exception as e:
                print(e)
                self.disconnect()"""
            xml = ET.ElementTree(ET.fromstring(xml_str))
            command.process(self, xml)
Example #3
0
	def lineReceived(self, data):
		try:
			cmd = json.loads(data)
			if cmd[u'name'] == 'PRELOAD':
				vx.addFontPreload(self.id, cmd['args'][0], cmd['args'][1])
				return
			vx.pushWebSocketEvent(self.id, cmd)
		except ValueError:
			log.msg("Invalid JSON data received:: %s" % data)
			cmd = command.process(data)
			self.processCommand(cmd)
Example #4
0
	def lineReceived(self, data):
		try:
			cmd = json.loads(data)
			if cmd[u'name'] == 'PRELOAD':
				vx.addFontPreload(self.id, cmd['args'][0], cmd['args'][1])
				return
			vx.pushWebSocketEvent(self.id, cmd)
		except ValueError:
			log.msg("Invalid JSON data received:: %s" % data)
			cmd = command.process(data)
			self.processCommand(cmd)
Example #5
0
	def lineReceived(self, data):
		try:
			cmd = json.loads(data)
			if (u'name' in cmd) and (cmd[u'name'] == 'PRELOAD'):
				vx.addFontPreload(self.id, cmd['args'][0], cmd['args'][1])
			elif u'appName' in cmd:
				vx.apps[self.id]['appName'] = cmd['appName'] 
				print 'Registering Application: ' + vx.apps[self.id]['appName']
			else:
				vx.pushWebSocketEvent(self.id, cmd)
		except ValueError:
			logging.info("Invalid JSON data received: " + data)
			cmd = command.process(data)
			self.processCommand(cmd)
		self.read_line()
Example #6
0
    def handle(self):
        sys.stderr.write('%d: -- NEW CONNECTION --\n' % os.getpid())
        msg = None
        try:
            while True:
                try:
                    if self.mode == 'connect':
                        self.url, self.client_caps, self.repos, self.base_url = client.connect(self)

                        if self.client_caps is None or self.repos is None:
                            return

                        self.mode = 'auth'

                    elif self.mode == 'auth':
                        if self.user is None:
                            self.user = auth.perform_auth(self, self.server.users)
                            self.mode = 'announce'
                        else:
                            self.send_msg(gen.success(gen.list(), gen.string('')))
                            self.mode = self.data
                            self.data = None

                        if self.user is None:
                            return

                    elif self.mode == 'announce':
                        self.send_server_id()
                        self.mode = 'command'

                    elif self.mode == 'command':
                        if self.command is None:
                            self.command = command.process(self)
                        else:
                            self.command = self.command.process()

                    elif self.mode == 'editor':
                        editor.process(self)

                    elif self.mode == 'report':
                        report.process(self)

                    else:
                        raise ModeError("unknown mode '%s'" % self.mode)

                except ChangeMode as cm:
                    self.mode = cm.args[0]
                    if len(cm.args) > 1:
                        self.data = cm.args[1]
        except EOF:
            msg = 'EOF'
        except socket.error as e:
            errno, msg = e
        except Exception:
            try:
                self.send_msg(gen.error(235000, traceback.format_exc()))
            except Exception as e1:
                print e1
            raise

        sys.stderr.write('%d: -- CLOSE CONNECTION (%s) --\n' %
                         (os.getpid(), msg))
Example #7
0
    def handle(self):
        sys.stderr.write('%d: -- NEW CONNECTION --\n' % os.getpid())
        msg = None
        try:
            while True:
                try:
                    if self.mode == 'connect':
                        self.url, self.client_caps, self.repos, self.base_url = client.connect(
                            self)

                        if self.client_caps is None or self.repos is None:
                            return

                        self.mode = 'auth'

                    elif self.mode == 'auth':
                        if self.user is None:
                            self.user = auth.perform_auth(
                                self, self.server.users)
                            self.mode = 'announce'
                        else:
                            self.send_msg(
                                gen.success(gen.list(), gen.string('')))
                            self.mode = self.data
                            self.data = None

                        if self.user is None:
                            return

                    elif self.mode == 'announce':
                        self.send_server_id()
                        self.mode = 'command'

                    elif self.mode == 'command':
                        if self.command is None:
                            self.command = command.process(self)
                        else:
                            self.command = self.command.process()

                    elif self.mode == 'editor':
                        editor.process(self)

                    elif self.mode == 'report':
                        report.process(self)

                    else:
                        raise ModeError("unknown mode '%s'" % self.mode)

                except ChangeMode as cm:
                    self.mode = cm.args[0]
                    if len(cm.args) > 1:
                        self.data = cm.args[1]
        except EOF:
            msg = 'EOF'
        except socket.error as e:
            errno, msg = e
        except Exception:
            try:
                self.send_msg(gen.error(235000, traceback.format_exc()))
            except Exception as e1:
                print e1
            raise

        sys.stderr.write('%d: -- CLOSE CONNECTION (%s) --\n' %
                         (os.getpid(), msg))