コード例 #1
0
    def parse_bytes(self, daide_bytes):
        """ Builds the request from DAIDE bytes """
        super(SendMessageRequest, self).parse_bytes(daide_bytes)

        # Parsing
        lead_token, daide_bytes = parse_bytes(SingleToken, daide_bytes)
        assert str(lead_token) == 'SND', 'Expected SND request'

        # Turn
        turn, daide_bytes = parse_bytes(Turn, daide_bytes, on_error='ignore')

        # Powers
        powers = []
        powers_group_bytes, daide_bytes = break_next_group(daide_bytes)
        powers_group_bytes = strip_parentheses(powers_group_bytes)
        while powers_group_bytes:
            power, powers_group_bytes = parse_bytes(Power, powers_group_bytes)
            powers += [power]
        assert powers, 'Expected a group of `power`. Request is malformed'

        # Press message or reply
        message_group_bytes, daide_bytes = break_next_group(daide_bytes)
        message_group_bytes = strip_parentheses(message_group_bytes)
        assert message_group_bytes, 'Expected a `press_message` or a `reply`. Request is malformed'
        assert not daide_bytes, '%s bytes remaining. Request is malformed' % len(daide_bytes)

        # Setting properties
        self.phase = '' if not turn else str(turn)
        self.powers = [str(power) for power in powers]
        self.message_bytes = message_group_bytes
コード例 #2
0
    def parse_bytes(self, daide_bytes):
        """ Builds the request from DAIDE bytes """
        super(IAmRequest, self).parse_bytes(daide_bytes)

        # Parsing
        lead_token, daide_bytes = parse_bytes(SingleToken, daide_bytes)
        assert str(lead_token) == 'IAM', 'Expected IAM request'

        # Power
        power_group_bytes, daide_bytes = break_next_group(daide_bytes)
        power_group_bytes = strip_parentheses(power_group_bytes)
        power, power_group_bytes = parse_bytes(Power, power_group_bytes)
        assert not power_group_bytes, '%s bytes remaining in power group. Request is malformed' % len(
            power_group_bytes)

        # Passcode
        passcode_group_bytes, daide_bytes = break_next_group(daide_bytes)
        passcode_group_bytes = strip_parentheses(passcode_group_bytes)
        passcode, passcode_group_bytes = parse_bytes(SingleToken,
                                                     passcode_group_bytes)
        assert not passcode_group_bytes, '%s bytes remaining in passcode group. Req. error' % len(
            passcode_group_bytes)
        assert not daide_bytes, '%s bytes remaining. Request is malformed' % len(
            daide_bytes)

        # Setting properties
        self.power_name = str(power)
        self.passcode = str(passcode)
コード例 #3
0
    def parse_bytes(self, daide_bytes):
        """ Builds the request from DAIDE bytes """
        super(SyntaxErrorRequest, self).parse_bytes(daide_bytes)

        # Parsing
        lead_token, daide_bytes = parse_bytes(SingleToken, daide_bytes)
        message_bytes, daide_bytes = break_next_group(daide_bytes)
        message_bytes = strip_parentheses(message_bytes)
        assert str(lead_token) == 'HUH', 'Expected HUH request'
        assert not daide_bytes, '%s bytes remaining. Request is malformed' % len(daide_bytes)

        # Setting properties
        self.message_bytes = message_bytes
コード例 #4
0
    def parse_bytes(self, daide_bytes):
        """ Builds the request from DAIDE bytes """
        super(RejectRequest, self).parse_bytes(daide_bytes)

        # Parsing
        lead_token, daide_bytes = parse_bytes(SingleToken, daide_bytes)
        response_bytes, daide_bytes = break_next_group(daide_bytes)
        response_bytes = strip_parentheses(response_bytes)
        assert str(lead_token) == 'REJ', 'Expected REJ request'
        assert not daide_bytes, '%s bytes remaining. Request is malformed' % len(daide_bytes)

        # Setting properties
        self.response_bytes = response_bytes
コード例 #5
0
    def parse_bytes(self, daide_bytes):
        """ Builds the request from DAIDE bytes """
        super(NotRequest, self).parse_bytes(daide_bytes)

        # Parsing
        lead_token, daide_bytes = parse_bytes(SingleToken, daide_bytes)
        request_group_bytes, daide_bytes = break_next_group(daide_bytes)
        assert str(lead_token) == 'NOT', 'Expected NOT request'

        # Request
        request_group_bytes = strip_parentheses(request_group_bytes)
        request = RequestBuilder.from_bytes(request_group_bytes)
        assert not daide_bytes, '%s bytes remaining. Request is malformed' % len(daide_bytes)

        # Setting properties
        self.request = request
コード例 #6
0
    def parse_bytes(self, daide_bytes):
        """ Builds the request from DAIDE bytes """
        super(TimeToDeadlineRequest, self).parse_bytes(daide_bytes)

        # Parsing
        lead_token, daide_bytes = parse_bytes(SingleToken, daide_bytes)
        seconds_group_bytes, daide_bytes = break_next_group(daide_bytes)
        assert str(lead_token) == 'TME', 'Expected TME request'

        # Seconds
        if seconds_group_bytes:
            seconds_group_bytes = strip_parentheses(seconds_group_bytes)
            seconds, daide_bytes = parse_bytes(Number, seconds_group_bytes)
        assert not daide_bytes, '%s bytes remaining. Request is malformed' % len(daide_bytes)

        # Setting properties
        self.seconds = None if not seconds_group_bytes else int(seconds)
コード例 #7
0
    def parse_bytes(self, daide_bytes):
        """ Builds the request from DAIDE bytes """
        super(DrawRequest, self).parse_bytes(daide_bytes)
        powers = []

        # Parsing
        lead_token, daide_bytes = parse_bytes(SingleToken, daide_bytes)
        assert str(lead_token) == 'DRW', 'Expected DRW request'

        # Powers
        powers_group_bytes, daide_bytes = break_next_group(daide_bytes)
        if powers_group_bytes:
            powers_group_bytes = strip_parentheses(powers_group_bytes)
            while powers_group_bytes:
                power, powers_group_bytes = parse_bytes(Power, powers_group_bytes)
                powers += [power]

        assert not daide_bytes, '%s bytes remaining. Request is malformed' % len(daide_bytes)

        # Setting properties
        self.powers = [str(power) for power in powers]