<commit_before># coding=utf-8
"""
This module contains patches to Esri's *arcpy._mp.Map* class.  These patches may insert functionality or fix issues
directly in the *arcpy._mp.Map* class.
"""

import arcpy

from ..._str.utils import caseless_equal
from ._cim_helpers import get_cim_version


def add_set_layer_visibility():
    def set_layer_visibility(self: arcpy._mp.Map, layer_visibility: str) -> None:
        """Set layer visibility based on a string description.

        Args:
            layer_visibility (str): A description of the layer visibility to apply, in the same format as the MapServer ExportMap layers specification.

        Raises:
            ValueError: Raised in the event the layer visibility input can not be parsed or is otherwised unrecognized.
        """

        if not layer_visibility:
            raise ValueError("Layer visibility cannot be None.")

        try:
            (layers_op, layers_list) = [s.strip() for s in layer_visibility.split(":")]
            layers_list = [id.strip() for id in layers_list.split(",")]
        except:
            raise ValueError("Could not parse layers list to determine layer visiblity: %s", layer_visibility)

        layer: arcpy._mp.Layer
        for layer in self.listLayers():
            layer_id = str(layer.getDefinition(get_cim_version()).serviceLayerID)

            if caseless_equal(layers_op, "show"):
                # make only the specified layers visible
                if layer_id in layers_list:
                    layer.visible = True
                else:
                    layer.visible = False
            elif caseless_equal(layers_op, "hide"):<commit_msg>Fixed issues with Py2/3 compat<commit_after># coding=utf-8
"""
This module contains patches to Esri's *arcpy._mp.Map* class.  These patches may insert functionality or fix issues
directly in the *arcpy._mp.Map* class.
"""

import arcpy

from arcpy._mp import Layer, Map

from ..._str.utils import caseless_equal
from ._cim_helpers import get_cim_version


def add_set_layer_visibility():
    def set_layer_visibility(self, layer_visibility):
        # type: (Map, str) -> None
        """Set layer visibility based on a string description.

        Args:
            layer_visibility (str): A description of the layer visibility to apply, in the same format as the MapServer ExportMap layers specification.

        Raises:
            ValueError: Raised in the event the layer visibility input can not be parsed or is otherwised unrecognized.
        """

        if not layer_visibility:
            raise ValueError("Layer visibility cannot be None.")

        try:
            (layers_op, layers_list) = [s.strip() for s in layer_visibility.split(":")]
            layers_list = [id.strip() for id in layers_list.split(",")]
        except:
            raise ValueError("Could not parse layers list to determine layer visiblity: %s", layer_visibility)

        for layer in self.listLayers():
            layer = layer  #type: Layer
            layer_id = str(layer.getDefinition(get_cim_version()).serviceLayerID)

            if caseless_equal(layers_op, "show"):
                # make only the specified layers visible
                if layer_id in layers_list:
                    layer.visible = True
                else:
                    layer.visible = False
            elif caseless_equal(layers_op, "hide"):
{'fraction_non_alphanumeric': 0.08030705639208739, 'fraction_numerical': 0.00118098612341305, 'mean_word_length': 2.4677584442169906, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5974036', 'n_tokens_mistral': 921, 'n_tokens_neox': 882, 'n_words': 319}