1
  4   ˆl–ßi~”ªn-j�vãM\dJbÑ¿ŽþDè–l¯ŒŒ‰±Œ óÊ626ÉÀÇ r    €}q (X	   locale_idqX   ce_RUqX   territoriesq}qX	   languagesq}qX   variantsq}qX   scriptsq	}q
X   list_patternsq}qX	   week_dataq}q(X   min_daysqKX	   first_dayqK uX   zone_formatsq}qX
   time_zonesq}qX
   meta_zonesq}qX   number_symbolsq}qX   decimal_formatsq}qX   scientific_formatsq}qX   percent_formatsq}qX   currency_formatsq}q X   currency_unit_patternsq!}q"X   currency_namesq#}q$X   currency_names_pluralq%}q&X   currency_symbolsq'}q(X   unit_patternsq)}q*X   compound_unit_patternsq+}q,X   unit_display_namesq-}q.X   date_fieldsq/}q0X   measurement_systemsq1}q2u.  C   ˆl–Ãa¾”Ê:”Ê�~ão\må1hß�þY–9VnQFë£(ÓÀþË„Œ…ÿÊ_ŠI|¥�+Wé3ž¯ÂÉ ?¿    """Utility functions to expand configuration directives or special values
(such glob patterns).

We can split the process of interpreting configuration files into 2 steps:

1. The parsing the file contents from strings to value objects
   that can be understand by Python (for example a string with a comma
   separated list of keywords into an actual Python list of strings).

2. The expansion (or post-processing) of these values according to the
   semantics ``setuptools`` assign to them (for example a configuration field
   with the ``file:`` directive should be expanded from a list of file paths to
   a single string with the contents of those files concatenated)

This module focus on the second step, and therefore allow sharing the expansion
functions among several configuration file formats.

**PRIVATE MODULE**: API reserved for setuptools internal usage only.
"""
import ast
import importlib
import io
import os
import pathlib
import sys
import warnings
from glob import iglob
from configparser import ConfigParser
from importlib.machinery import ModuleSpec
from itertools import chain
from typing import (
    TYPE_CHECKING,
    Callable,
    Dict,
    Iterable,
    Iterator,
    List,
    Mapping,
    Optional,
    Tuple,
    TypeVar,
    Union,
    cast
)
from pathlib import Path
from types import ModuleType

from distutils.errors import DistutilsOptionError

from .._path import same_path as _same_path

if TYPE_CHECKING:
    from setuptools.dist import Distribution  # noqa
    from setuptools.discovery import ConfigDiscovery  # noqa
    from distutils.dist import DistributionMetadata  # noqa

chain_iter = chain.from_iterable
_Path = Union[str, os.PathLike]
_K = TypeVar("_K")
_V = TypeVar("_V", covariant=True)


class StaticModule:
    """Proxy to a module object that avoids executing arbitrary code."""

    def __init__(self, name: str, spec: ModuleSpec):
        module = ast.parse(pathlib.Path(spec.origin).read_bytes())
        vars(self).update(locals())
        del self.self

    def _find_assignments(self) -> Iterator[Tuple[ast.AST, ast.AST]]:
        for statement in self.module.body:
            if isinstance(statement, ast.Assign):
                yield from ((target, statement.value) for target in statement.targets)
            elif isinstance(statement, ast.AnnAssign) and statement.value:
                yield (statement.target, statement.value)

    def __getattr__(self, attr):
        """Attempt to load an attribute "statically", via :func:`ast.literal_eval`."""
        try:
            return next(
                ast.literal_eval(value)
                for target, value in self._find_assignments()
                if isinstance(target, ast.Name) and target.id == attr
            )
        except Exception as e:
            raise AttributeError(f"{self.name} has no attribute {attr}") from e


def glob_relative(
    patterns: Iterable[str], root_dir: Optional[_Path] = None
) -> List[str]:
    """Expand the list of glob patterns, but preserving relative paths.

    :param list[str] patterns: List of glob patterns
    :param str root_dir: Path to which globs should be relative
                         (current directory by default)
    :rtype: list
    """
    glob_characters = {'*', '?', '[', ']', '{', '}'}
    expanded_values = []
    root_di