Beispiel #1
0
    def _parse_datagram(self) -> None:
        try:
            self._address_regexp, index = osc_types.get_string(self._dgram, 0)
            if not self._dgram[index:]:
                # No params is legit, just return now.
                return

            # Get the parameters types.
            type_tag, index = osc_types.get_string(self._dgram, index)
            if type_tag.startswith(','):
                type_tag = type_tag[1:]

            params = []
            param_stack = [params]
            # Parse each parameter given its type.
            for param in type_tag:
                if param == "i":  # Integer.
                    val, index = osc_types.get_int(self._dgram, index)
                elif param == "f":  # Float.
                    val, index = osc_types.get_float(self._dgram, index)
                elif param == "d":  # Double.
                    val, index = osc_types.get_double(self._dgram, index)
                elif param == "s":  # String.
                    val, index = osc_types.get_string(self._dgram, index)
                elif param == "b":  # Blob.
                    val, index = osc_types.get_blob(self._dgram, index)
                elif param == "r":  # RGBA.
                    val, index = osc_types.get_rgba(self._dgram, index)
                elif param == "m":  # MIDI.
                    val, index = osc_types.get_midi(self._dgram, index)
                elif param == "t":  # osc time tag:
                    val, index = osc_types.get_ttag(self._dgram, index)
                elif param == "T":  # True.
                    val = True
                elif param == "F":  # False.
                    val = False
                elif param == "[":  # Array start.
                    array = []
                    param_stack[-1].append(array)
                    param_stack.append(array)
                elif param == "]":  # Array stop.
                    if len(param_stack) < 2:
                        raise ParseError(
                            'Unexpected closing bracket in type tag: {0}'.
                            format(type_tag))
                    param_stack.pop()
                # TODO: Support more exotic types as described in the specification.
                else:
                    logging.warning(
                        'Unhandled parameter type: {0}'.format(param))
                    continue
                if param not in "[]":
                    param_stack[-1].append(val)
            if len(param_stack) != 1:
                raise ParseError(
                    'Missing closing bracket in type tag: {0}'.format(
                        type_tag))
            self._parameters = params
        except osc_types.ParseError as pe:
            raise ParseError('Found incorrect datagram, ignoring it', pe)
	def _parse_datagram(self):
		self._address_regexp, index = osc_types.get_string(self._dgram, 0)
		if not self._dgram[index:]:
			# No params is legit, just return now.
			return

		# Get the parameters types.
		type_tag, index = osc_types.get_string(self._dgram, index)
		if type_tag.startswith(','):
			type_tag = type_tag[1:]

		# Parse each parameter given its type.
		for param in type_tag:
			if param == "i":  # Integer.
				val, index = osc_types.get_int(self._dgram, index)
			elif param == "f":  # Float.
				val, index = osc_types.get_float(self._dgram, index)
			elif param == "s":  # String.
				val, index = osc_types.get_string(self._dgram, index)
			elif param == "b":  # Blob.
				val, index = osc_types.get_blob(self._dgram, index)
			elif param == "T": # True.
				val = True
			elif param == "F": # False.
				val = False
			# TODO: Support more exotic types as described in the specification.
			else:
				logging.getLogger().warning('Unhandled parameter type: {0}'.format(param))
				continue
			self._parameters.append(val)
Beispiel #3
0
    def _parse_datagram(self):
        try:
            self._address_regexp, index = osc_types.get_string(self._dgram, 0)
            if not self._dgram[index:]:
                # No params is legit, just return now.
                return

            # Get the parameters types.
            type_tag, index = osc_types.get_string(self._dgram, index)
            if type_tag.startswith(','):
                type_tag = type_tag[1:]

            # Parse each parameter given its type.
            for param in type_tag:
                if param == "i":  # Integer.
                    val, index = osc_types.get_int(self._dgram, index)
                elif param == "f":  # Float.
                    val, index = osc_types.get_float(self._dgram, index)
                elif param == "s":  # String.
                    val, index = osc_types.get_string(self._dgram, index)
                elif param == "b":  # Blob.
                    val, index = osc_types.get_blob(self._dgram, index)
                elif param == "T":  # True.
                    val = True
                elif param == "F":  # False.
                    val = False
                # TODO: Support more exotic types as described in the specification.
                else:
                    logging.warning(
                        'Unhandled parameter type: {0}'.format(param))
                    continue
                self._parameters.append(val)
        except osc_types.ParseError as pe:
            raise ParseError('Found incorrect datagram, ignoring it', pe)
Beispiel #4
0
  def _parse_datagram(self):
    try:
      self._address_regexp, index = osc_types.get_string(self._dgram, 0)
      if not self._dgram[index:]:
        # No params is legit, just return now.
        return

      # Get the parameters types.
      type_tag, index = osc_types.get_string(self._dgram, index)
      if type_tag.startswith(','):
        type_tag = type_tag[1:]

      # Parse each parameter given its type.
      for param in type_tag:
        if param == "i":  # Integer.
          val, index = osc_types.get_int(self._dgram, index)
        elif param == "f":  # Float.
          val, index = osc_types.get_float(self._dgram, index)
        elif param == "s":  # String.
          val, index = osc_types.get_string(self._dgram, index)
        elif param == "b":  # Blob.
          val, index = osc_types.get_blob(self._dgram, index)
        # TODO: Support more exotic types as described in the specification.
        elif param == 0:
          # We've reached the end of the param string, finish now.
          return
        else:
          logging.warning('Unhandled parameter type: {0}'.format(param))
          continue
        self._parameters.append(val)
    except osc_types.ParseError as pe:
      raise ParseError('Found incorrect datagram, ignoring it', pe)
Beispiel #5
0
  def _parse_datagram(self):
    try:
      self._address_regexp, index = osc_types.get_string(self._dgram, 0)
      if not self._dgram[index:]:
        # No params is legit, just return now.
        return

      # Get the parameters types.
      type_tag, index = osc_types.get_string(self._dgram, index)
      if type_tag.startswith(','):
        type_tag = type_tag[1:]

      params = []
      param_stack = [params]
      # Parse each parameter given its type.
      for param in type_tag:
        if param == "i":  # Integer.
          val, index = osc_types.get_int(self._dgram, index)
        elif param == "f":  # Float.
          val, index = osc_types.get_float(self._dgram, index)
        elif param == "d":  # Double.
          val, index = osc_types.get_double(self._dgram, index)
        elif param == "s":  # String.
          val, index = osc_types.get_string(self._dgram, index)
        elif param == "b":  # Blob.
          val, index = osc_types.get_blob(self._dgram, index)
        elif param == "r":  # RGBA.
          val, index = osc_types.get_rgba(self._dgram, index)
        elif param == "m":  # MIDI.
          val, index = osc_types.get_midi(self._dgram, index)
        elif param == "t":  # osc time tag:
            val, index = osc_types.get_ttag(self._dgram, index)
        elif param == "T":  # True.
          val = True
        elif param == "F":  # False.
          val = False
        elif param == "[":  # Array start.
          array = []
          param_stack[-1].append(array)
          param_stack.append(array)
        elif param == "]": # Array stop.
          if len(param_stack) < 2:
            raise ParseError('Unexpected closing bracket in type tag: {0}'.format(type_tag))
          param_stack.pop()
        # TODO: Support more exotic types as described in the specification.
        else:
          logging.warning('Unhandled parameter type: {0}'.format(param))
          continue
        if param not in "[]":
          param_stack[-1].append(val)
      if len(param_stack) != 1:
        raise ParseError('Missing closing bracket in type tag: {0}'.format(type_tag))
      self._parameters = params
    except osc_types.ParseError as pe:
      raise ParseError('Found incorrect datagram, ignoring it', pe)
Beispiel #6
0
    def test_get_blob(self):
        cases = {
            b"\x00\x00\x00\x00": (b"", 4),
            b"\x00\x00\x00\x08stuff\x00\x00\x00": (b"stuff\x00\x00\x00", 12),
            b"\x00\x00\x00\x04\x00\x00\x00\x00": (b"\x00\x00\x00\x00", 8),
            b"\x00\x00\x00\x02\x00\x00\x00\x00": (b"\x00\x00", 8),
            b"\x00\x00\x00\x08stuff\x00\x00\x00datagramcontinues":
            (b"stuff\x00\x00\x00", 12),
        }

        for dgram, expected in cases.items():
            self.assertEqual(expected, osc_types.get_blob(dgram, 0))
Beispiel #7
0
  def test_get_blob(self):
    cases = {
        b"\x00\x00\x00\x00": (b"", 4),
        b"\x00\x00\x00\x08stuff\x00\x00\x00": (b"stuff\x00\x00\x00", 12),
        b"\x00\x00\x00\x04\x00\x00\x00\x00": (b"\x00\x00\x00\x00", 8),
        b"\x00\x00\x00\x02\x00\x00\x00\x00": (b"\x00\x00", 8),

        b"\x00\x00\x00\x08stuff\x00\x00\x00datagramcontinues": (
            b"stuff\x00\x00\x00", 12),
    }

    for dgram, expected in cases.items():
      self.assertEqual(expected, osc_types.get_blob(dgram, 0))