<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _extract_and_reconstruct_as_path(self, update_msg):
 """Extracts advertised AS path attributes in the given update message and reconstructs AS_PATH from AS_PATH and AS4_PATH if needed."""

        umsg_pattrs = update_msg.pathattr_map

        as_aggregator = umsg_pattrs.get(BGP_ATTR_TYPE_AGGREGATOR, None)
        as4_aggregator = umsg_pattrs.get(BGP_ATTR_TYPE_AS4_AGGREGATOR, None)
        if as_aggregator and as4_aggregator:
            # When both AGGREGATOR and AS4_AGGREGATOR are received,
            # if the AS number in the AGGREGATOR attribute is not AS_TRANS,
            # then:
            #  -  the AS4_AGGREGATOR attribute and the AS4_PATH attribute SHALL
            #     be ignored,
            #  -  the AGGREGATOR attribute SHALL be taken as the information
            #     about the aggregating node, and
            #  -  the AS_PATH attribute SHALL be taken as the AS path
            #     information.
            if as_aggregator.as_number != bgp.AS_TRANS:
                update_msg.path_attributes.remove(as4_aggregator)
                as4_path = umsg_pattrs.pop(BGP_ATTR_TYPE_AS4_PATH, None)
                if as4_path:
                    update_msg.path_attributes.remove(as4_path)
            # Otherwise,
            #  -  the AGGREGATOR attribute SHALL be ignored,
            #  -  the AS4_AGGREGATOR attribute SHALL be taken as the
            #     information about the aggregating node, and
            #  -  the AS path information would need to be constructed,
            #     as in all other cases.
            else:
                update_msg.path_attributes.remove(as_aggregator)
                update_msg.path_attributes.remove(as4_aggregator)
                update_msg.path_attributes.append(
                    bgp.BGPPathAttributeAggregator(
                        as_number=as4_aggregator.as_number,
                        addr=as4_aggregator.addr,
                    )
                )

        as_path = umsg_pattrs.get(BGP_ATTR_TYPE_AS_PATH, None)
        as4_path = umsg_pattrs.get(BGP_ATTR_TYPE_AS4_PATH, None)
        if as_path and as4_path:
            # If the number of AS numbers in the AS_PATH attribute is
            # less than the number of AS numbers in the AS4_PATH attribute,
            # then the AS4_PATH attribute SHALL be ignored, and the AS_PATH
            # attribute SHALL be taken as the AS path information.
            if as_path.get_as_path_len() < as4_path.get_as_path_len():
                update_msg.path_attributes.remove(as4_path)

            # If the number of AS numbers in the AS_PATH attribute is larger
            # than or equal to the number of AS numbers in the AS4_PATH
            # attribute, then the AS path information SHALL be constructed
            # by taking as many AS numbers and path segments as necessary
            # from the leading part of the AS_PATH attribute, and then
            # prepending them to the AS4_PATH attribute so that the AS path
            # information has a number of AS numbers identical to that of
            # the AS_PATH attribute.
            else:
                update_msg.path_attributes.remove(as_path)
                update_msg.path_attributes.remove(as4_path)
                as_path = self._construct_as_path_attr(as_path, as4_path)
                update_msg.path_attributes.append(as_path)