<commit_before># This file is part of the MapProxy project.
# Copyright (C) 2010-2016 Omniscale <http://omniscale.de>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
from mapproxy.compat import string_type
from mapproxy.util.fs import ensure_directory
from mapproxy.request.base import NoCaseMultiDict

def location_funcs(layout):
    if layout == 'tc':
        return tile_location_tc, level_location
    elif layout == 'mp':
        return tile_location_mp, level_location
    elif layout == 'tms':
        return tile_location_tms, level_location
    elif layout == 'reverse_tms':
        return tile_location_reverse_tms, None
    elif layout == 'quadkey':
        return tile_location_quadkey, no_level_location
    elif layout == 'arcgis':
        return tile_location_arcgiscache, level_location_arcgiscache
    else:
        raise ValueError('unknown directory_layout "%s"' % layout)

def level_location(level, cache_dir, dimensions=None):
    """
    Return the path where all tiles for `level` will be stored.

    >>> os.path.abspath(level_location(2, '/tmp/cache')) == os.path.abspath('/tmp/cache/02')
    True
    """
    dim_path = dimensions_part(dimensions)

    if isinstance(level, string_type):
        return os.path.join(cache_dir, dim_path, level)
    else:
        return os.path.join(cache_dir, dim_path, "%02d" % level)

def dimensions_part(dimensions):
    """
    Return the subpath where all tiles for `dimensions` will be stored.
    >>> dimensions_part(['reference-time', 'time'], {"time": "2016-11-24T18:00Z", "reference-time": "2016-11-24T00:00Z"})
    '2016-11-24T00:00Z/2016-11-24T18:00Z'<commit_msg>fixing UnexpectedException dimensions_part test<commit_after># This file is part of the MapProxy project.
# Copyright (C) 2010-2016 Omniscale <http://omniscale.de>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
from mapproxy.compat import string_type
from mapproxy.util.fs import ensure_directory
from mapproxy.request.base import NoCaseMultiDict

def location_funcs(layout):
    if layout == 'tc':
        return tile_location_tc, level_location
    elif layout == 'mp':
        return tile_location_mp, level_location
    elif layout == 'tms':
        return tile_location_tms, level_location
    elif layout == 'reverse_tms':
        return tile_location_reverse_tms, None
    elif layout == 'quadkey':
        return tile_location_quadkey, no_level_location
    elif layout == 'arcgis':
        return tile_location_arcgiscache, level_location_arcgiscache
    else:
        raise ValueError('unknown directory_layout "%s"' % layout)

def level_location(level, cache_dir, dimensions=None):
    """
    Return the path where all tiles for `level` will be stored.

    >>> os.path.abspath(level_location(2, '/tmp/cache')) == os.path.abspath('/tmp/cache/02')
    True
    """
    dim_path = dimensions_part(dimensions)

    if isinstance(level, string_type):
        return os.path.join(cache_dir, dim_path, level)
    else:
        return os.path.join(cache_dir, dim_path, "%02d" % level)

def dimensions_part(dimensions):
    """
    Return the subpath where all tiles for `dimensions` will be stored.
    >>> dimensions_part({'time': '2020-08-25T00:00:00Z', 'dim_reference_time': '2020-08-25T00:00:00Z'})
    'time-2020-08-25T00:00:00Z/dim_reference_time-2020-08-25T00:00:00Z'
    
{'fraction_non_alphanumeric': 0.1005767012687428, 'fraction_numerical': 0.03183391003460208, 'mean_word_length': 3.9328782707622296, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '317825', 'n_tokens_mistral': 1376, 'n_tokens_neox': 1296, 'n_words': 408}