Example #1
0
    def __init__(self, raw):
        """
		Create a command representation by parsing a raw received message.
		Use functionality from Message, then create a Hostmask from the prefix.

		@param raw The full message in string form.
		"""

        # Ignore the CRLF
        parts = raw[:-2].split()

        pre = None
        if Message.has_prefix(raw):
            # Create a hostmask from the prefix, ignoring the ':' at the start
            pre = Hostmask.from_raw(parts[0][1:])
            del parts[0]

        if len(parts) == 0:
            raise ValueError('message has no command')

        cmd = parts[0]
        # Every 'part' after the command is an argument
        arg = ' '.join(parts[1:])

        Message.__init__(self, pre, cmd, Message.parse_arguments(arg))
Example #2
0
    def __init__(self, raw):
        """
		Create a command representation by parsing a raw received message.
		Similar to Command, but prefix is a string, and command is an int.

		@param raw The full message in string form.
		"""

        # Ignoret the CRLF
        parts = raw[:-2].split()

        pre = None
        if Message.has_prefix(raw):
            # A reply source is just the server name
            pre = parts[0][1:]
            del parts[0]

        if len(parts) == 0:
            raise ValueError('message has no command')

        # A reply command is just a 3-digit code
        cmd = int(parts[0])
        arg = ' '.join(parts[1:])

        Message.__init__(self, pre, cmd, Message.parse_arguments(arg))