File six.py of Package failed_python-guessit
# Minimal vendored subset of the 'six' compatibility module to satisfy build-time
# test imports. This is intentionally tiny and only provides the symbols used by
# the test-suite / package (text_type, binary_type, string_types, integer_types,
# u, iteritems). It is not a full replacement for the real 'six' package.
#
# This shim avoids adding an external dependency so tests running in the build
# environment (without test-deps) can import the expected names.
import sys
from typing import Any, Dict, Iterable, Tuple
PY3 = sys.version_info[0] == 3
# Text and binary types
text_type = str
binary_type = bytes
# Common tuple aliases
string_types: Tuple[type, ...] = (str,)
integer_types: Tuple[type, ...] = (int,)
def u(s: Any) -> str:
"""Return a text (str) representation of s. Decode bytes using utf-8."""
if isinstance(s, bytes):
return s.decode('utf-8')
return str(s)
def iteritems(d: Dict) -> Iterable[Tuple[Any, Any]]:
"""Return an iterator over dict items (compat for Py2's iteritems)."""
return iter(d.items())
# Provide a minimal reraise helper similar to six.reraise. This implementation
# focuses on Python 3 behaviour and is sufficient for typical usage in tests.
def reraise(exc_type, value, tb=None):
if tb is not None:
raise value.with_traceback(tb)
raise value