<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def framework_name_from_image(image_name):
 """Extract the framework and Python version from the image name. Args: image_name (str):
 Image URI, which should be one of the following forms: legacy: '<account>.dkr.ecr.<region>.amazonaws.com/sagemaker-<fw>-<py_ver>-<device>:<container_version>' legacy: '<account>.dkr.ecr.<region>.amazonaws.com/sagemaker-<fw>-<py_ver>-<device>:<fw_version>-<device>-<py_ver>' current: '<account>.dkr.ecr.<region>.amazonaws.com/sagemaker-<fw>:<fw_version>-<device>-<py_ver>' current: '<account>.dkr.ecr.<region>.amazonaws.com/sagemaker-rl-<fw>:<rl_toolkit><rl_version>-<device>-<py_ver>' Returns: tuple: A tuple containing: str: The framework name str: The Python version str: The image tag str: If the image is script mode """

    sagemaker_pattern = re.compile(ECR_URI_PATTERN)
    sagemaker_match = sagemaker_pattern.match(image_name)
    if sagemaker_match is None:
        return None, None, None, None
    else:
        # extract framework, python version and image tag
        # We must support both the legacy and current image name format.
        name_pattern = re.compile(
            r'^sagemaker(?:-rl)?-(tensorflow|mxnet|chainer|pytorch|scikit-learn)(?:-)?(scriptmode)?:(.*)-(.*?)-(py2|py3)$') # noqa
        legacy_name_pattern = re.compile(
            r'^sagemaker-(tensorflow|mxnet)-(py2|py3)-(cpu|gpu):(.*)$')

        name_match = name_pattern.match(sagemaker_match.group(9))
        legacy_match = legacy_name_pattern.match(sagemaker_match.group(9))

        if name_match is not None:
            fw, scriptmode, ver, device, py = name_match.group(1), name_match.group(2), name_match.group(3),\
                name_match.group(4), name_match.group(5)
            return fw, py, '{}-{}-{}'.format(ver, device, py), scriptmode
        elif legacy_match is not None:
            return legacy_match.group(1), legacy_match.group(2), legacy_match.group(4), None
        else:
            return None, None, None, None