@tornado.gen.coroutine
    def handle(self):
        self.log.debug('Handling message "%s": %s', self.cmdobj.cmd, str(self.cmdobj)[:64])

        if self.app.shuttingdown:
            raise Exception('The server is shutting down.')

        cmdname = self.cmdobj.cmd
        connid = self.connid
        twwcid = self.twwcid

        if connid == 0:
            # A message not from any player!
            if twwcid == 0:
                # Internal message, from tworld itself.
                stream = None
            else:
                # This is from tweb, not relayed from a player.
                # (This is the rare case where we use twwcid; we have no
                # other path back.)
                stream = self.app.webconns.get(twwcid)

            try:
                if twwcid and not stream:
                    raise ErrorMessageException('Server message from completely unrecognized stream.')
                
                cmd = self.app.all_commands.get(cmdname, None)
                if not cmd:
                    raise ErrorMessageException('Unknown server command: "%s"' % (cmdname,))
            
                if not cmd.isserver:
                    raise ErrorMessageException('Command must be invoked by a player: "%s"' % (cmdname,))

                if not cmd.noneedmongo and not self.app.mongodb:
                    # Guess the database access is not going to work.
                    raise ErrorMessageException('Tworld has lost contact with the database.')

                if cmd.doeswrite:
                    # May cause display changes.
                    self.set_writable()
                
                res = yield cmd.func(self.app, self, self.cmdobj, stream)
                if res is not None:
                    self.log.info('Command "%s" result: %s', cmdname, res)
                
            except ErrorMessageException as ex:
                self.log.warning('Error message running "%s": %s', cmdname, str(ex))
            except MessageException as ex:
                # MessageException is usually not worth logging, but for
                # a server command, there's nobody else listening.
                self.log.info('Message running "%s": %s', cmdname, str(ex))

            # End of connid==0 case.
            return 

        conn = self.app.playconns.get(connid)

        # Command from a player (via conn). A MessageException here passes
        # an error back to the player.

        try:
            cmd = self.app.all_commands.get(cmdname, None)
            if not cmd:
                raise ErrorMessageException('Unknown player command: "%s"' % (cmdname,))

            # Check various limitations on the command.

            if cmd.isserver:
                raise ErrorMessageException('Command may not be invoked by a player: "%s"' % (cmdname,))

            if cmd.restrict == 'admin':
                player = yield motor.Op(self.app.mongodb.players.find_one,
                                        {'_id':conn.uid},
                                        {'admin':1})
                if not (player and player.get('admin', False)):
                    raise ErrorMessageException('Command may only be invoked by an administrator: "%s"' % (cmdname,))

            if cmd.restrict == 'creator':
                # Player must be the creator of the world he is in.
                ### And it must be an unstable version.
                # (Or an admin, anywhere.)
                player = yield motor.Op(self.app.mongodb.players.find_one,
                                        {'_id':conn.uid},
                                        {'admin':1, 'build':1})
                if not player:
                    raise ErrorMessageException('Player not found!')
                if (player.get('admin', False)):
                    # Admins always have creator rights.
                    pass
                elif (not player.get('build', False)):
                    raise ErrorMessageException('Command requires build permission: "%s"' % (cmdname,))
                else:
                    playstate = yield motor.Op(self.app.mongodb.playstate.find_one,
                                               {'_id':conn.uid},
                                               {'iid':1})
                    instance = yield motor.Op(self.app.mongodb.instances.find_one,
                                              {'_id':playstate['iid']})
                    world = yield motor.Op(self.app.mongodb.worlds.find_one,
                                           {'_id':instance['wid']})
                    if world.get('creator', None) != conn.uid:
                        raise ErrorMessageException('Command may only be invoked by this world\'s creator: "%s"' % (cmdname,))

            if not conn:
                # Newly-established connection. Only 'playeropen' will be
                # accepted. (Another twwcid case; we'll have to sneak the
                # stream in through the command object.)
                # (It's also possible that the connection closed since we
                # queued this, in which case we still reject.)
                if not cmd.preconnection:
                    raise ErrorMessageException('Tworld has not yet registered this connection.')
                assert cmd.name=='playeropen', 'Command not playeropen should have already been rejected'
                stream = self.app.webconns.get(twwcid)
                if not stream:
                    raise ErrorMessageException('Message from completely unrecognized stream')
                self.cmdobj._connid = connid
                self.cmdobj._stream = stream

            if not cmd.noneedmongo and not self.app.mongodb:
                # Guess the database access is not going to work.
                raise ErrorMessageException('Tworld has lost contact with the database.')

            if cmd.doeswrite:
                # May cause display changes.
                self.set_writable()
                
            res = yield cmd.func(self.app, self, self.cmdobj, conn)
            if res is not None:
                self.log.info('Command "%s" result: %s', cmdname, res)

        except ErrorMessageException as ex:
            # An ErrorMessageException is worth logging and sending back
            # to the player, but not splatting out a stack trace.
            self.log.warning('Error message running "%s": %s', cmdname, str(ex))
            try:
                # This is slightly hairy, because various error paths can
                # arrive here with no conn or no connid.
                if conn:
                    conn.write({'cmd':'error', 'text':str(ex)})
                else:
                    # connid may be zero or nonzero, really
                    stream = self.app.webconns.get(twwcid)
                    stream.write(wcproto.message(connid, {'cmd':'error', 'text':str(ex)}))
            except Exception as ex:
                pass

        except MessageException as ex:
            # A MessageException is not worth logging.
            try:
                # This is slightly hairy, because various error paths can
                # arrive here with no conn or no connid.
                if conn:
                    conn.write({'cmd':'message', 'text':str(ex)})
                else:
                    # connid may be zero or nonzero, really
                    stream = self.app.webconns.get(twwcid)
                    stream.write(wcproto.message(connid, {'cmd':'message', 'text':str(ex)}))
            except Exception as ex:
                pass
Test the remove_slab() method.
dataset/ETHPy150Open erkyrath/tworld/lib/two/task.py/Task.handle--crossover with--dataset/ETHPy150Open MapQuest/mapquest-osm-server/src/python/tests/test_lrucache.py/test_remove