code: def _wcmatch_version(given_version):
      """
      Return nearest matching supported Unicode version level.
  
      If an exact match is not determined, the nearest lowest version level is
      returned after a warning is emitted.  For example, given supported levels
      ``4.1.0`` and ``5.0.0``, and a version string of ``4.9.9``, then ``4.1.0``
      is selected and returned:
  
      >>> _wcmatch_version('4.9.9')
      '4.1.0'
      >>> _wcmatch_version('8.0')
      '8.0.0'
      >>> _wcmatch_version('1')
      '4.1.0'
  
      :param str given_version: given version for compare, may be ``auto``
          (default), to select Unicode Version from Environment Variable,
          ``UNICODE_VERSION``. If the environment variable is not set, then the
          latest is used.
      :rtype: str
      :returns: unicode string, or non-unicode ``str`` type for python 2
          when given ``version`` is also type ``str``.
      """
      # Design note: the choice to return the same type that is given certainly
      # complicates it for python 2 str-type, but allows us to define an api that
      # uses 'string-type' for unicode version level definitions, so all of our
      # example code works with all versions of python.
      #
      # That, along with the string-to-numeric and comparisons of earliest,
      # latest, matching, or nearest, greatly complicates this function.
      # Performance is somewhat curbed by memoization.
      _return_str = not _PY3 and isinstance(given_version, str)
  
      if _return_str:
          # avoid list-comprehension to work around a coverage issue:
          # https://github.com/nedbat/coveragepy/issues/753
          unicode_versions = list(
              map(lambda ucs: ucs.encode(), list_versions())
          )
      else:
          unicode_versions = list_versions()
      latest_version = unicode_versions[-1]
  
      if given_version in ("auto", "auto"):
          given_version = os.environ.get(
              "UNICODE_VERSION",
              "latest" if not _return_str else latest_version.encode(),
          )
  
      if given_version in ("latest", "latest"):
          # default match, when given as 'latest', use the most latest unicode
          # version specification level supported.
          return (
              latest_version
              if not _return_str
              else latest_version.encode()
          )
  
      if given_version in unicode_versions:
          # exact match, downstream has specified an explicit matching version
          # matching any value of list_versions().
          return (
              given_version
              if not _return_str
              else given_version.encode()
          )
  
      # The user's version is not supported by ours. We return the newest unicode
      # version level that we support below their given value.
      try:
          cmp_given = _wcversion_value(given_version)
  
      except ValueError:
          # submitted value raises ValueError in int(), warn and use latest.
          warnings.warn(
              "UNICODE_VERSION value, {given_version!r}, is invalid. "
              "Value should be in form of `integer[.]+', the latest "
              "supported unicode version {latest_version!r} has been "
              "inferred.".format(
                  given_version=given_version,
                  latest_version=latest_version,
              )
          )
          return (
              latest_version
              if not _return_str
              else latest_version.encode()
          )
  
      # given version is less than any available version, return earliest
      # version.
      earliest_version = unicode_versions[0]
      cmp_earliest_version = _wcversion_value(earliest_version)
  
      if cmp_given <= cmp_earliest_version:
          # this probably isn't what you wanted, the oldest wcwidth.c you will
          # find in the wild is likely version 5 or 6, which we both support,
          # but it's better than not saying anything at all.
          warnings.warn(
              "UNICODE_VERSION value, {given_version!r}, is lower "
              "than any available unicode version. Returning lowest "
              "version level, {earliest_version!r}".format(
                  given_version=given_version,
                  earliest_version=earliest_version,
              )
          )
          return (
              earliest_version
              if not _return_str
              else earliest_version.encode()
          )
  
      # create list of versions which are less than our equal to given version,
      # and return the tail value, which is the highest level we may support,
      # or the latest value we support, when completely unmatched or higher
      # than any supported version.
      #
      # function will never complete, always returns.
      for idx, unicode_version in enumerate(unicode_versions):
          # look ahead to next value
          try:
              cmp_next_version = _wcversion_value(
                  unicode_versions[idx + 1]
              )
          except IndexError:
              # at end of list, return latest version
              return (
                  latest_version
                  if not _return_str
                  else latest_version.encode()
              )
  
          # Maybe our given version has less parts, as in tuple(8, 0), than the
          # next compare version tuple(8, 0, 0). Test for an exact match by
          # comparison of only the leading dotted piece(s): (8, 0) == (8, 0).
          if cmp_given == cmp_next_version[: len(cmp_given)]:
              return unicode_versions[idx + 1]
  
          # Or, if any next value is greater than our given support level
          # version, return the current value in index.  Even though it must
          # be less than the given value, its our closest possible match. That
          # is, 4.1 is returned for given 4.9.9, where 4.1 and 5.0 are available.
          if cmp_next_version > cmp_given:
              return unicode_version
      assert False, (
          "Code path unreachable",
          given_version,
          unicode_versions,
      )
  
file_path: catboost/contrib/python/wcwidth/py2/wcwidth/wcwidth.py
imports: from __future__ import division
  import os
  import sys
  import warnings
  from .table_vs16 import VS16_NARROW_TO_WIDE
  from .table_wide import WIDE_EASTASIAN
  from .table_zero import ZERO_WIDTH
  from .unicode_versions import list_versions
label_desc: Use image node_id 5 for calling a global function with example usage: _wcmatch_version(given_version) and returns: unknown, unknown, unknown, unknown, unicode_versions, unicode_version, unknown