<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def __EncodedAttribute_encode_jpeg_rgb32(self, rgb32, width=0, height=0, quality=100.0):
 """Encode a 32 bit rgb color image as JPEG format. :param rgb32: an object containning image information :type rgb32: :py:obj:`str` or :class:`numpy.ndarray` or seq< seq<element> > :param width: image width. **MUST** be given if rgb32 is a string or if it is a :class:`numpy.ndarray` with ndims != 2. Otherwise it is calculated internally. :type width: :py:obj:`int` :param height: image height. **MUST** be given if rgb32 is a string or if it is a :class:`numpy.ndarray` with ndims != 2. Otherwise it is calculated internally. :type height: :py:obj:`int` .. note:: When :class:`numpy.ndarray` is given: - rgb32 **MUST** be CONTIGUOUS, ALIGNED - if rgb32.ndims != 2, width and height **MUST** be given and rgb32.nbytes/4 **MUST** match width*height - if rgb32.ndims == 2, rgb32.itemsize **MUST** be 4 (typically, rgb32.dtype is one of `numpy.dtype.int32`, `numpy.dtype.uint32`) Example:: def read_myattr(self, attr):
 enc = tango.EncodedAttribute() data = numpy.arange(100, dtype=numpy.int32) data = numpy.array((data,data,data)) enc.encode_jpeg_rgb32(data) attr.set_value(enc) """

    if not is_seq(rgb32):
        raise TypeError("Expected sequence (str, numpy.ndarray, list, tuple "
                        "or bytearray) as first argument")

    is_str = is_pure_str(rgb32)
    if is_str:
        if not width or not height:
            raise ValueError("When giving a string as data, you must also "
                             "supply width and height")

    if np and isinstance(rgb32, np.ndarray):
        if rgb32.ndim != 2:
            if not width or not height:
                raise ValueError("When giving a non 2D numpy array, width and "
                                 "height must be supplied")
            if rgb32.nbytes / 4 != width * height:
                raise ValueError("numpy array size mismatch")
        else:
            if rgb32.itemsize != 4:
                raise TypeError("Expected numpy array with itemsize == 4")
        if not rgb32.flags.c_contiguous:
            raise TypeError("Currently, only contiguous, aligned numpy arrays "
                            "are supported")
        if not rgb32.flags.aligned:
            raise TypeError("Currently, only contiguous, aligned numpy arrays "
                            "are supported")

    if not is_str and (not width or not height):
        height = len(rgb32)
        if height < 1:
            raise IndexError("Expected sequence with at least one row")

        row0 = rgb32[0]
        if not is_seq(row0):
            raise IndexError("Expected sequence (str, numpy.ndarray, list, tuple or "
                             "bytearray) inside a sequence")
        width = len(row0)
        if is_pure_str(row0) or type(row0) == bytearray:
            width /= 4

    self._encode_jpeg_rgb32(rgb32, width, height, quality)