コード例 #1
0
ファイル: __init__.py プロジェクト: Thynix/beets
    def run(self):
        """Send a greeting to the client and begin processing commands
        as they arrive.
        """
        yield self.send(HELLO)

        clist = None  # Initially, no command list is being constructed.
        while True:
            line = (yield self.sock.readline()).strip()
            if not line:
                break
            log.debug(line)

            if clist is not None:
                # Command list already opened.
                if line == CLIST_END:
                    yield bluelet.call(self.do_command(clist))
                    clist = None  # Clear the command list.
                else:
                    clist.append(Command(line))

            elif line == CLIST_BEGIN or line == CLIST_VERBOSE_BEGIN:
                # Begin a command list.
                clist = CommandList([], line == CLIST_VERBOSE_BEGIN)

            else:
                # Ordinary command.
                try:
                    yield bluelet.call(self.do_command(Command(line)))
                except BPDClose:
                    # Command indicates that the conn should close.
                    self.sock.close()
                    return
コード例 #2
0
ファイル: __init__.py プロジェクト: RandomStuffs22/beets
 def do_command(self, command):
     """A coroutine that runs the given command and sends an
     appropriate response."""
     try:
         yield bluelet.call(command.run(self))
     except BPDError as e:
         # Send the error.
         yield self.send(e.response())
     else:
         # Send success code.
         yield self.send(RESP_OK)
コード例 #3
0
ファイル: __init__.py プロジェクト: SJoshBrown/beets
 def do_command(self, command):
     """A coroutine that runs the given command and sends an
     appropriate response."""
     try:
         yield bluelet.call(command.run(self))
     except BPDError as e:
         # Send the error.
         yield self.send(e.response())
     else:
         # Send success code.
         yield self.send(RESP_OK)
コード例 #4
0
    def run(self):
        """Send a greeting to the client and begin processing commands
        as they arrive.
        """
        self.server._log.debug('New client connected')
        yield self.send(HELLO)

        clist = None  # Initially, no command list is being constructed.
        while True:
            line = yield self.sock.readline()
            if not line:
                break
            line = line.strip()
            if not line:
                break
            line = line.decode('utf8')  # MPD protocol uses UTF-8.
            message = line.replace(u'\n', u'\n' + u' ' * 13)
            self.server._log.debug(u'client: {}', message)

            if clist is not None:
                # Command list already opened.
                if line == CLIST_END:
                    yield bluelet.call(self.do_command(clist))
                    clist = None  # Clear the command list.
                else:
                    clist.append(Command(line))

            elif line == CLIST_BEGIN or line == CLIST_VERBOSE_BEGIN:
                # Begin a command list.
                clist = CommandList([], line == CLIST_VERBOSE_BEGIN)

            else:
                # Ordinary command.
                try:
                    yield bluelet.call(self.do_command(Command(line)))
                except BPDClose:
                    # Command indicates that the conn should close.
                    self.sock.close()
                    return
コード例 #5
0
ファイル: __init__.py プロジェクト: RandomStuffs22/beets
    def run(self, conn):
        """Coroutine executing all the commands in this list.
        """
        for i, command in enumerate(self):
            try:
                yield bluelet.call(command.run(conn))
            except BPDError as e:
                # If the command failed, stop executing.
                e.index = i  # Give the error the correct index.
                raise e

            # Otherwise, possibly send the output delimeter if we're in a
            # verbose ("OK") command list.
            if self.verbose:
                yield conn.send(RESP_CLIST_VERBOSE)
コード例 #6
0
ファイル: __init__.py プロジェクト: RandomStuffs22/beets
    def run(self):
        """Send a greeting to the client and begin processing commands
        as they arrive.
        """
        yield self.send(HELLO)

        clist = None  # Initially, no command list is being constructed.
        while True:
            line = yield self.sock.readline()
            if not line:
                break
            line = line.strip()
            if not line:
                break
            log.debug(line)

            if clist is not None:
                # Command list already opened.
                if line == CLIST_END:
                    yield bluelet.call(self.do_command(clist))
                    clist = None  # Clear the command list.
                else:
                    clist.append(Command(line))

            elif line == CLIST_BEGIN or line == CLIST_VERBOSE_BEGIN:
                # Begin a command list.
                clist = CommandList([], line == CLIST_VERBOSE_BEGIN)

            else:
                # Ordinary command.
                try:
                    yield bluelet.call(self.do_command(Command(line)))
                except BPDClose:
                    # Command indicates that the conn should close.
                    self.sock.close()
                    return
コード例 #7
0
ファイル: __init__.py プロジェクト: SJoshBrown/beets
    def run(self, conn):
        """Coroutine executing all the commands in this list.
        """
        for i, command in enumerate(self):
            try:
                yield bluelet.call(command.run(conn))
            except BPDError as e:
                # If the command failed, stop executing.
                e.index = i  # Give the error the correct index.
                raise e

            # Otherwise, possibly send the output delimeter if we're in a
            # verbose ("OK") command list.
            if self.verbose:
                yield conn.send(RESP_CLIST_VERBOSE)