
"""simple docstring"""




from typing import Dict, List, Optional, Tuple, Union

import numpy as np

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import (
    center_crop,
    get_resize_output_image_size,
    normalize,
    rescale,
    resize,
    to_channel_dimension_format,
)
from ...image_utils import (
    IMAGENET_STANDARD_MEAN,
    IMAGENET_STANDARD_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_torch_available, is_torch_tensor, logging


if is_torch_available():
						import torch


lowerCAmelCase__				=					logging.get_logger(__name__)





class 			snake_case  (				__lowercase ):
							UpperCAmelCase__      =   ['''pixel_values''']

							def __init__(self							,							SCREAMING_SNAKE_CASE_ = True							,							SCREAMING_SNAKE_CASE_ = None							,							SCREAMING_SNAKE_CASE_ = PILImageResampling.BILINEAR							,							SCREAMING_SNAKE_CASE_ = True							,							SCREAMING_SNAKE_CASE_ = None							,							SCREAMING_SNAKE_CASE_ = True							,							SCREAMING_SNAKE_CASE_ = 1 / 2_55							,							SCREAMING_SNAKE_CASE_ = True							,							SCREAMING_SNAKE_CASE_ = None							,							SCREAMING_SNAKE_CASE_ = None							,							**SCREAMING_SNAKE_CASE_							,							):

									"""simple docstring"""







									super().__init__(**SCREAMING_SNAKE_CASE_     )
									SCREAMING_SNAKE_CASE_    			=			size if size is not None else {'''shortest_edge''': 2_56}
									SCREAMING_SNAKE_CASE_    			=			get_size_dict(SCREAMING_SNAKE_CASE_							,							default_to_square=SCREAMING_SNAKE_CASE_     )
									SCREAMING_SNAKE_CASE_    			=			crop_size if crop_size is not None else {'''height''': 2_24, '''width''': 2_24}
									SCREAMING_SNAKE_CASE_    			=			get_size_dict(SCREAMING_SNAKE_CASE_							,							param_name='''crop_size'''     )
									SCREAMING_SNAKE_CASE_    			=			do_resize
									SCREAMING_SNAKE_CASE_    			=			size
									SCREAMING_SNAKE_CASE_    			=			resample
									SCREAMING_SNAKE_CASE_    			=			do_center_crop
									SCREAMING_SNAKE_CASE_    			=			crop_size
									SCREAMING_SNAKE_CASE_    			=			do_rescale
									SCREAMING_SNAKE_CASE_    			=			rescale_factor
									SCREAMING_SNAKE_CASE_    			=			do_normalize
									SCREAMING_SNAKE_CASE_    			=			image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
									SCREAMING_SNAKE_CASE_    			=			image_std if image_std is not None else IMAGENET_STANDARD_STD

							def _lowercase       (self							,							SCREAMING_SNAKE_CASE_							,							SCREAMING_SNAKE_CASE_							,							SCREAMING_SNAKE_CASE_ = PILImageResampling.BICUBIC							,							SCREAMING_SNAKE_CASE_ = None							,							**SCREAMING_SNAKE_CASE_							,							):

									"""simple docstring"""







									SCREAMING_SNAKE_CASE_    			=			get_size_dict(SCREAMING_SNAKE_CASE_							,							default_to_square=SCREAMING_SNAKE_CASE_     )
									if "shortest_edge" not in size:
											raise ValueError(f'The `size` parameter must contain the key `shortest_edge`. Got {size.keys()}'     )
									SCREAMING_SNAKE_CASE_    			=			get_resize_output_image_size(SCREAMING_SNAKE_CASE_							,							size=size['''shortest_edge''']							,							default_to_square=SCREAMING_SNAKE_CASE_     )
									return resize(SCREAMING_SNAKE_CASE_							,							size=SCREAMING_SNAKE_CASE_							,							resample=SCREAMING_SNAKE_CASE_							,							data_format=SCREAMING_SNAKE_CASE_							,							**SCREAMING_SNAKE_CASE_     )

							def _lowercase       (self							,							SCREAMING_SNAKE_CASE_							,							SCREAMING_SNAKE_CASE_							,							SCREAMING_SNAKE_CASE_ = None							,							**SCREAMING_SNAKE_CASE_							,							):

									"""simple docstring"""







									SCREAMING_SNAKE_CASE_    			=			get_size_dict(SCREAMING_SNAKE_CASE_     )
									if "height" not in size or "width" not in size:
											raise ValueError(f'The `size` parameter must contain the keys `height` and `width`. Got {size.keys()}'     )
									return center_crop(SCREAMING_SNAKE_CASE_							,							size=(size['''height'''], size['''width'''])							,							data_format=SCREAMING_SNAKE_CASE_							,							**SCREAMING_SNAKE_CASE_     )

							def _lowercase       (self							,							SCREAMING_SNAKE_CASE_							,							SCREAMING_SNAKE_CASE_							,							SCREAMING_SNAKE_CASE_ = None							,							**SCREAMING_SNAKE_CASE_     ):

									"""simple docstring"""







									return rescale(SCREAMING_SNAKE_CASE_							,							scale=SCREAMING_SNAKE_CASE_							,							data_format=SCREAMING_SNAKE_CASE_							,							**SCREAMING_SNAKE_CASE_     )

							def _lowercase       (self							,							SCREAMING_SNAKE_CASE_							,							SCREAMING_SNAKE_CASE_							,							SCREAMING_SNAKE_CASE_							,							SCREAMING_SNAKE_CASE_ = None							,							**SCREAMING_SNAKE_CASE_							,							):

									"""simple docstring"""







									return normalize(SCREAMING_SNAKE_CASE_							,							mean=SCREAMING_SNAKE_CASE_							,							std=SCREAMING_SNAKE_CASE_							,							data_format=SCREAMING_SNAKE_CASE_							,							**SCREAMING_SNAKE_CASE_     )

							def _lowercase       (self							,							SCREAMING_SNAKE_CASE_							,							SCREAMING_SNAKE_CASE_ = None							,							SCREAMING_SNAKE_CASE_ = None							,							SCREAMING_SNAKE_CASE_ = None							,							SCREAMING_SNAKE_CASE_ = None							,							SCREAMING_SNAKE_CASE_ = None							,							SCREAMING_SNAKE_CASE_ = None							,							SCREAMING_SNAKE_CASE_ = None							,							SCREAMING_SNAKE_CASE_ = None							,							SCREAMING_SNAKE_CASE_ = None							,							SCREAMING_SNAKE_CASE_ = None							,							SCREAMING_SNAKE_CASE_ = None							,							SCREAMING_SNAKE_CASE_ = ChannelDimension.FIRST							,							**SCREAMING_SNAKE_CASE_							,							):

									"""simple docstring"""







									SCREAMING_SNAKE_CASE_    			=			do_resize if do_resize is not None else self.do_resize
									SCREAMING_SNAKE_CASE_    			=			size if size is not None else self.size
									SCREAMING_SNAKE_CASE_    			=			get_size_dict(SCREAMING_SNAKE_CASE_							,							default_to_square=SCREAMING_SNAKE_CASE_     )
									SCREAMING_SNAKE_CASE_    			=			resample if resample is not None else self.resample
									SCREAMING_SNAKE_CASE_    			=			do_center_crop if do_center_crop is not None else self.do_center_crop
									SCREAMING_SNAKE_CASE_    			=			crop_size if crop_size is not None else self.crop_size
									SCREAMING_SNAKE_CASE_    			=			get_size_dict(SCREAMING_SNAKE_CASE_							,							param_name='''crop_size'''     )
									SCREAMING_SNAKE_CASE_    			=			do_rescale if do_rescale is not None else self.do_rescale
									SCREAMING_SNAKE_CASE_    			=			rescale_factor if rescale_factor is not None else self.rescale_factor
									SCREAMING_SNAKE_CASE_    			=			do_normalize if do_normalize is not None else self.do_normalize
									SCREAMING_SNAKE_CASE_    			=			image_mean if image_mean is not None else self.image_mean
									SCREAMING_SNAKE_CASE_    			=			image_std if image_std is not None else self.image_std

									SCREAMING_SNAKE_CASE_    			=			make_list_of_images(SCREAMING_SNAKE_CASE_     )

									if not valid_images(SCREAMING_SNAKE_CASE_     ):
											raise ValueError(
											    '''Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, '''
											    '''torch.Tensor, tf.Tensor or jax.ndarray.'''     )

									if do_resize and size is None:
											raise ValueError('''Size must be specified if do_resize is True.'''     )

									if do_center_crop and crop_size is None:
											raise ValueError('''Crop size must be specified if do_center_crop is True.'''     )

									if do_rescale and rescale_factor is None:
											raise ValueError('''Rescale factor must be specified if do_rescale is True.'''     )

									if do_normalize and (image_mean is None or image_std is None):
											raise ValueError('''Image mean and std must be specified if do_normalize is True.'''     )

									# All transformations expect numpy arrays.
									SCREAMING_SNAKE_CASE_    			=			[to_numpy_array(SCREAMING_SNAKE_CASE_     ) for image in images]

									if do_resize:
											SCREAMING_SNAKE_CASE_    			=			[self.resize(image=SCREAMING_SNAKE_CASE_							,							size=SCREAMING_SNAKE_CASE_							,							resample=SCREAMING_SNAKE_CASE_     ) for image in images]

									if do_center_crop:
											SCREAMING_SNAKE_CASE_    			=			[self.center_crop(image=SCREAMING_SNAKE_CASE_							,							size=SCREAMING_SNAKE_CASE_     ) for image in images]

									if do_rescale:
											SCREAMING_SNAKE_CASE_    			=			[self.rescale(image=SCREAMING_SNAKE_CASE_							,							scale=SCREAMING_SNAKE_CASE_     ) for image in images]

									if do_normalize:
											SCREAMING_SNAKE_CASE_    			=			[self.normalize(image=SCREAMING_SNAKE_CASE_							,							mean=SCREAMING_SNAKE_CASE_							,							std=SCREAMING_SNAKE_CASE_     ) for image in images]

									SCREAMING_SNAKE_CASE_    			=			[to_channel_dimension_format(SCREAMING_SNAKE_CASE_							,							SCREAMING_SNAKE_CASE_     ) for image in images]

									SCREAMING_SNAKE_CASE_    			=			{'''pixel_values''': images}
									return BatchFeature(data=SCREAMING_SNAKE_CASE_							,							tensor_type=SCREAMING_SNAKE_CASE_     )







							def _lowercase       (self							,							SCREAMING_SNAKE_CASE_							,							SCREAMING_SNAKE_CASE_ = None     ):

									"""simple docstring"""







									SCREAMING_SNAKE_CASE_    			=			outputs.logits

									# Resize logits and compute semantic segmentation maps
									if target_sizes is not None:
											if len(SCREAMING_SNAKE_CASE_     ) != len(SCREAMING_SNAKE_CASE_     ):
													raise ValueError(
													    '''Make sure that you pass in as many target sizes as the batch dimension of the logits'''     )

											if is_torch_tensor(SCREAMING_SNAKE_CASE_     ):
													SCREAMING_SNAKE_CASE_    			=			target_sizes.numpy()

											SCREAMING_SNAKE_CASE_    			=			[]

											for idx in range(len(SCREAMING_SNAKE_CASE_     )     ):
													SCREAMING_SNAKE_CASE_    			=			torch.nn.functional.interpolate(
													    logits[idx].unsqueeze(dim=0     )							,							size=target_sizes[idx]							,							mode='''bilinear'''							,							align_corners=SCREAMING_SNAKE_CASE_     )
													SCREAMING_SNAKE_CASE_    			=			resized_logits[0].argmax(dim=0     )
													semantic_segmentation.append(SCREAMING_SNAKE_CASE_     )
									else:
											SCREAMING_SNAKE_CASE_    			=			logits.argmax(dim=1     )
											SCREAMING_SNAKE_CASE_    			=			[semantic_segmentation[i] for i in range(semantic_segmentation.shape[0]     )]

									return semantic_segmentation

"""simple docstring"""




import asyncio
import os
import re
import sys
import tempfile
import unittest
from contextlib import contextmanager
from copy import deepcopy
from distutils.util import strtobool
from enum import Enum
from importlib.util import find_spec
from pathlib import Path
from unittest.mock import patch

import pyarrow as pa
import pytest
import requests
from packaging import version

from datasets import config


if config.PY_VERSION < version.parse('3.8'):
						import importlib_metadata
else:
						import importlib.metadata as importlib_metadata



def 							_lowerCamelCase			(			__a,				__a=False     ):
		try:
				SCREAMING_SNAKE_CASE_    			=			os.environ[key]
		except KeyError:
				# KEY isn't set, default to `default`.
				SCREAMING_SNAKE_CASE_    			=			default
		else:
				# KEY is set, convert it to True or False.
				try:
						SCREAMING_SNAKE_CASE_    			=			strtobool(__a     )
				except ValueError:
						# More values are supported, but let's keep the message simple.
						raise ValueError(F'If set, {key} must be yes or no.'     )
		return _value


lowerCAmelCase__				=					parse_flag_from_env('RUN_SLOW', default=False)
lowerCAmelCase__				=					parse_flag_from_env('RUN_REMOTE', default=False)
lowerCAmelCase__				=					parse_flag_from_env('RUN_LOCAL', default=True)
lowerCAmelCase__				=					parse_flag_from_env('RUN_PACKAGED', default=True)

# Compression
lowerCAmelCase__				=					pytest.mark.skipif(not config.LZ4_AVAILABLE, reason='test requires lz4')
lowerCAmelCase__				=					pytest.mark.skipif(not config.PY7ZR_AVAILABLE, reason='test requires py7zr')
lowerCAmelCase__				=					pytest.mark.skipif(not config.ZSTANDARD_AVAILABLE, reason='test requires zstandard')

# Audio
lowerCAmelCase__				=					pytest.mark.skipif(
    # On Windows and OS X, soundfile installs sndfile
    find_spec('soundfile') is None or version.parse(importlib_metadata.version('soundfile')) < version.parse('0.12.0'),
    reason='test requires sndfile>=0.12.1: \'pip install \"soundfile>=0.12.1\"\'; ',
)

# Beam
lowerCAmelCase__				=					pytest.mark.skipif(
    not config.BEAM_AVAILABLE or config.DILL_VERSION >= version.parse('0.3.2'),
    reason='test requires apache-beam and a compatible dill version',
)

# Dill-cloudpickle compatibility
lowerCAmelCase__				=					pytest.mark.skipif(
    config.DILL_VERSION <= version.parse('0.3.2'),
    reason='test requires dill>0.3.2 for cloudpickle compatibility',
)

# Windows
lowerCAmelCase__				=					pytest.mark.skipif(
    sys.platform == 'win32',
    reason='test should not be run on Windows',
)



def 							_lowerCamelCase			(			__a     ):
		try:
				import faiss  # noqa
		except ImportError:
				SCREAMING_SNAKE_CASE_    			=			unittest.skip('''test requires faiss'''     )(__a     )
		return test_case



def 							_lowerCamelCase			(			__a     ):
		try:
				import regex  # noqa
		except ImportError:
				SCREAMING_SNAKE_CASE_    			=			unittest.skip('''test requires regex'''     )(__a     )
		return test_case



def 							_lowerCamelCase			(			__a     ):
		try:
				import elasticsearch  # noqa
		except ImportError:
				SCREAMING_SNAKE_CASE_    			=			unittest.skip('''test requires elasticsearch'''     )(__a     )
		return test_case



def 							_lowerCamelCase			(			__a     ):
		try:
				import sqlalchemy  # noqa
		except ImportError:
				SCREAMING_SNAKE_CASE_    			=			unittest.skip('''test requires sqlalchemy'''     )(__a     )
		return test_case



def 							_lowerCamelCase			(			__a     ):
		if not config.TORCH_AVAILABLE:
				SCREAMING_SNAKE_CASE_    			=			unittest.skip('''test requires PyTorch'''     )(__a     )
		return test_case



def 							_lowerCamelCase			(			__a     ):
		if not config.TF_AVAILABLE:
				SCREAMING_SNAKE_CASE_    			=			unittest.skip('''test requires TensorFlow'''     )(__a     )
		return test_case



def 							_lowerCamelCase			(			__a     ):
		if not config.JAX_AVAILABLE:
				SCREAMING_SNAKE_CASE_    			=			unittest.skip('''test requires JAX'''     )(__a     )
		return test_case



def 							_lowerCamelCase			(			__a     ):
		if not config.PIL_AVAILABLE:
				SCREAMING_SNAKE_CASE_    			=			unittest.skip('''test requires Pillow'''     )(__a     )
		return test_case



def 							_lowerCamelCase			(			__a     ):
		try:
				import transformers  # noqa F401
		except ImportError:
				return unittest.skip('''test requires transformers'''     )(__a     )
		else:
				return test_case



def 							_lowerCamelCase			(			__a     ):
		try:
				import tiktoken  # noqa F401
		except ImportError:
				return unittest.skip('''test requires tiktoken'''     )(__a     )
		else:
				return test_case



def 							_lowerCamelCase			(			__a     ):
		try:
				import spacy  # noqa F401
		except ImportError:
				return unittest.skip('''test requires spacy'''     )(__a     )
		else:
				return test_case



def 							_lowerCamelCase			(			__a     ):

		def _require_spacy_model(__a     ):
				try:
						import spacy  # noqa F401

						spacy.load(__a     )
				except ImportError:
						return unittest.skip('''test requires spacy'''     )(__a     )
				except OSError:
						return unittest.skip('''test requires spacy model \'{}\''''.format(__a     )     )(__a     )
				else:
						return test_case

		return _require_spacy_model



def 							_lowerCamelCase			(			__a     ):
		try:
				import pyspark  # noqa F401
		except ImportError:
				return unittest.skip('''test requires pyspark'''     )(__a     )
		else:
				return test_case



def 							_lowerCamelCase			(			__a     ):
		try:
				import joblibspark  # noqa F401
		except ImportError:
				return unittest.skip('''test requires joblibspark'''     )(__a     )
		else:
				return test_case



def 							_lowerCamelCase			(			__a     ):
		if not _run_slow_tests or _run_slow_tests == 0:
				SCREAMING_SNAKE_CASE_    			=			unittest.skip('''test is slow'''     )(__a     )
		return test_case



def 							_lowerCamelCase			(			__a     ):
		if not _run_local_tests or _run_local_tests == 0:
				SCREAMING_SNAKE_CASE_    			=			unittest.skip('''test is local'''     )(__a     )
		return test_case



def 							_lowerCamelCase			(			__a     ):
		if not _run_packaged_tests or _run_packaged_tests == 0:
				SCREAMING_SNAKE_CASE_    			=			unittest.skip('''test is packaged'''     )(__a     )
		return test_case



def 							_lowerCamelCase			(			__a     ):
		if not _run_remote_tests or _run_remote_tests == 0:
				SCREAMING_SNAKE_CASE_    			=			unittest.skip('''test requires remote'''     )(__a     )
		return test_case



def 							_lowerCamelCase			(			*__a     ):
		def decorate(cls     ):
				for name, fn in cls.__dict__.items():
						if callable(__a     ) and name.startswith('''test'''     ):
								for decorator in decorators:
										SCREAMING_SNAKE_CASE_    			=			decorator(__a     )
								setattr(cls,				__a,				__a     )
				return cls

		return decorate





class 			snake_case  (				__lowercase ):
							pass







class 			snake_case  (				__lowercase ):
							UpperCAmelCase__      =   0
							UpperCAmelCase__      =   1
							UpperCAmelCase__      =   2







@contextmanager
def 							_lowerCamelCase			(			__a=OfflineSimulationMode.CONNECTION_FAILS,				__a=1E-16     ):
		SCREAMING_SNAKE_CASE_    			=			requests.Session().request

		def timeout_request(__a,				__a,				__a,				**__a     ):
				# Change the url to an invalid url so that the connection hangs
				SCREAMING_SNAKE_CASE_    			=			'''https://10.255.255.1'''
				if kwargs.get('''timeout'''     ) is None:
						raise RequestWouldHangIndefinitelyError(
						    F'Tried a call to {url} in offline mode with no timeout set. Please set a timeout.'     )
				SCREAMING_SNAKE_CASE_    			=			timeout
				try:
						return online_request(__a,				__a,				**__a     )
				except Exception as e:
						# The following changes in the error are just here to make the offline timeout error prettier
						SCREAMING_SNAKE_CASE_    			=			url
						SCREAMING_SNAKE_CASE_    			=			e.args[0]
						SCREAMING_SNAKE_CASE_    			=			(max_retry_error.args[0].replace('''10.255.255.1''',				F'OfflineMock[{url}]'     ),)
						SCREAMING_SNAKE_CASE_    			=			(max_retry_error,)
						raise

		def raise_connection_error(__a,				__a,				**__a     ):
				raise requests.ConnectionError('''Offline mode is enabled.''',				request=__a     )

		if mode is OfflineSimulationMode.CONNECTION_FAILS:
				with patch('''requests.Session.send''',				__a     ):
						yield
		elif mode is OfflineSimulationMode.CONNECTION_TIMES_OUT:
				# inspired from https://stackoverflow.com/a/904609
				with patch('''requests.Session.request''',				__a     ):
						yield
		elif mode is OfflineSimulationMode.HF_DATASETS_OFFLINE_SET_TO_1:
				with patch('''datasets.config.HF_DATASETS_OFFLINE''',				__a     ):
						yield
		else:
				raise ValueError('''Please use a value from the OfflineSimulationMode enum.'''     )



@contextmanager
def 							_lowerCamelCase			(			*__a,				**__a     ):
		SCREAMING_SNAKE_CASE_    			=			str(Path().resolve()     )
		with tempfile.TemporaryDirectory(*__a,				**__a     ) as tmp_dir:
				try:
						os.chdir(__a     )
						yield
				finally:
						os.chdir(__a     )



@contextmanager
def 							_lowerCamelCase			(			):
		import gc

		gc.collect()
		SCREAMING_SNAKE_CASE_    			=			pa.total_allocated_bytes()
		yield
		assert pa.total_allocated_bytes() - previous_allocated_memory > 0, "Arrow memory didn't increase."



@contextmanager
def 							_lowerCamelCase			(			):
		import gc

		gc.collect()
		SCREAMING_SNAKE_CASE_    			=			pa.total_allocated_bytes()
		yield
		assert pa.total_allocated_bytes() - previous_allocated_memory <= 0, "Arrow memory wasn't expected to increase."



def 							_lowerCamelCase			(			__a,				__a     ):
		return deepcopy(__a     ).integers(0,				100,				10     ).tolist() == deepcopy(__a     ).integers(0,				100,				10     ).tolist()



def 							_lowerCamelCase			(			__a     ):
		import decorator
		from requests.exceptions import HTTPError

		def _wrapper(__a,				*__a,				**__a     ):
				try:
						return func(*__a,				**__a     )
				except HTTPError as err:
						if str(__a     ).startswith('''500'''     ) or str(__a     ).startswith('''502'''     ):
								pytest.xfail(str(__a     )     )
						raise err

		return decorator.decorator(_wrapper,				__a     )





class 			snake_case  :

							def __init__(self							,							SCREAMING_SNAKE_CASE_							,							SCREAMING_SNAKE_CASE_							,							SCREAMING_SNAKE_CASE_     ):

									"""simple docstring"""







									SCREAMING_SNAKE_CASE_    			=			returncode
									SCREAMING_SNAKE_CASE_    			=			stdout
									SCREAMING_SNAKE_CASE_    			=			stderr







async def 							_lowerCamelCase			(			__a,				__a     ):
		while True:
				SCREAMING_SNAKE_CASE_    			=			await stream.readline()
				if line:
						callback(__a     )
				else:
						break



async def 							_lowerCamelCase			(			__a,				__a=None,				__a=None,				__a=None,				__a=False,				__a=False     ):
		if echo:
				print('''\nRunning: ''',				''' '''.join(__a     )     )

		SCREAMING_SNAKE_CASE_    			=			await asyncio.create_subprocess_exec(
		    cmd[0],				*cmd[1:],				stdin=__a,				stdout=asyncio.subprocess.PIPE,				stderr=asyncio.subprocess.PIPE,				env=__a,				)

		# note: there is a warning for a possible deadlock when using `wait` with huge amounts of data in the pipe
		# https://docs.python.org/3/library/asyncio-subprocess.html#asyncio.asyncio.subprocess.Process.wait
		#
		# If it starts hanging, will need to switch to the following code. The problem is that no data
		# will be seen until it's done and if it hangs for example there will be no debug info.
		# out, err = await p.communicate()
		# return _RunOutput(p.returncode, out, err)

		SCREAMING_SNAKE_CASE_    			=			[]
		SCREAMING_SNAKE_CASE_    			=			[]

		def tee(__a,				__a,				__a,				__a=""     ):
				SCREAMING_SNAKE_CASE_    			=			line.decode('''utf-8'''     ).rstrip()
				sink.append(__a     )
				if not quiet:
						print(__a,				__a,				file=__a     )

    # XXX: the timeout doesn't seem to make any difference here
		await asyncio.wait(
		    [
		        _read_stream(p.stdout,				lambda __a     : tee(__a,				__a,				sys.stdout,				label='''stdout:'''     )     ),
		        _read_stream(p.stderr,				lambda __a     : tee(__a,				__a,				sys.stderr,				label='''stderr:'''     )     ),
		    ],				timeout=__a,				)
		return _RunOutput(await p.wait(),				__a,				__a     )



def 							_lowerCamelCase			(			__a,				__a=None,				__a=None,				__a=180,				__a=False,				__a=True     ):
		SCREAMING_SNAKE_CASE_    			=			asyncio.get_event_loop()
		SCREAMING_SNAKE_CASE_    			=			loop.run_until_complete(
		    _stream_subprocess(__a,				env=__a,				stdin=__a,				timeout=__a,				quiet=__a,				echo=__a     )     )

		SCREAMING_SNAKE_CASE_    			=			''' '''.join(__a     )
		if result.returncode > 0:
				SCREAMING_SNAKE_CASE_    			=			'''\n'''.join(result.stderr     )
				raise RuntimeError(
				    F'\'{cmd_str}\' failed with returncode {result.returncode}\n\n'
				    F'The combined stderr from workers follows:\n{stderr}'     )

		# check that the subprocess actually did run and produced some output, should the test rely on
		# the remote side to do the testing
		if not result.stdout and not result.stderr:
				raise RuntimeError(F'\'{cmd_str}\' produced no output.'     )

		return result



def 							_lowerCamelCase			(			):
		SCREAMING_SNAKE_CASE_    			=			os.environ.get('''PYTEST_XDIST_WORKER''',				'''gw0'''     )
		SCREAMING_SNAKE_CASE_    			=			re.sub(r'''^gw''',				'''''',				__a,				0,				re.M     )
		return int(__a     )



def 							_lowerCamelCase			(			):
		SCREAMING_SNAKE_CASE_    			=			29_500
		SCREAMING_SNAKE_CASE_    			=			pytest_xdist_worker_id()
		return port + uniq_delta