


import contextlib
import csv
import json
import os
import sqlitea
import tarfile
import textwrap
import zipfile

import pyarrow as pa
import pyarrow.parquet as pq
import pytest

import datasets
import datasets.config






@pytest.fixture(scope='session'     )
def   _lowercase(					):
							a__      =10
							a__      =datasets.Features(
							    {
							        'tokens': datasets.Sequence(datasets.Value('string'     )     ),
							        'labels': datasets.Sequence(datasets.ClassLabel(names=['negative', 'positive']     )     ),
							        'answers': datasets.Sequence(
							            {
							                'text': datasets.Value('string'     ),
							                'answer_start': datasets.Value('int32'     ),
							            }     ),
							        'id': datasets.Value('int64'     ),
							    }     )
							a__      =datasets.Dataset.from_dict(
							    {
							        'tokens': [['foo'] * 5] * n,
							        'labels': [[1] * 5] * n,
							        'answers': [{'answer_start': [97], 'text': ['1976']}] * 10,
							        'id': list(range(__a     )     ),
							    }    ,     features=__a    ,     )
							return dataset






@pytest.fixture(scope='session'     )
def   _lowercase(					__a				:						Optional[int]    ,     __a				:						Dict     ):
							a__      =str(tmp_path_factory.mktemp('data'     ) / 'file.arrow'     )
							dataset.map(cache_file_name=__a     )
							return filename


# FILE_CONTENT + files


_lowerCAmelCase:						Tuple   				=       '\\n    Text data.\n    Second line of data.'






@pytest.fixture(scope='session'     )
def   _lowercase(					__a				:						List[Any]     ):
							a__      =tmp_path_factory.mktemp('data'     ) / 'file.txt'
							a__      =FILE_CONTENT
							with open(__a    ,     'w'     ) as f:
														f.write(__a     )
							return filename






@pytest.fixture(scope='session'     )
def   _lowercase(					__a				:						List[str]     ):
							import bza

							a__      =tmp_path_factory.mktemp('data'     ) / 'file.txt.bz2'
							a__      =bytes(__a    ,     'utf-8'     )
							with bza.open(__a    ,     'wb'     ) as f:
														f.write(__a     )
							return path






@pytest.fixture(scope='session'     )
def   _lowercase(					__a				:						List[Any]     ):
							import gzip

							a__      =str(tmp_path_factory.mktemp('data'     ) / 'file.txt.gz'     )
							a__      =bytes(__a    ,     'utf-8'     )
							with gzip.open(__a    ,     'wb'     ) as f:
														f.write(__a     )
							return path






@pytest.fixture(scope='session'     )
def   _lowercase(					__a				:						Tuple     ):
							if datasets.config.LZ4_AVAILABLE:
														import lza.frame

														a__      =tmp_path_factory.mktemp('data'     ) / 'file.txt.lz4'
														a__      =bytes(__a    ,     'utf-8'     )
														with lza.frame.open(__a    ,     'wb'     ) as f:
																					f.write(__a     )
														return path






@pytest.fixture(scope='session'     )
def   _lowercase(					__a				:						List[Any]    ,     __a				:						Tuple     ):
							if datasets.config.PY7ZR_AVAILABLE:
														import pyazr

														a__      =tmp_path_factory.mktemp('data'     ) / 'file.txt.7z'
														with pyazr.SevenZipFile(__a    ,     'w'     ) as archive:
																					archive.write(__a    ,     arcname=os.path.basename(__a     )     )
														return path






@pytest.fixture(scope='session'     )
def   _lowercase(					__a				:						str    ,     __a				:						Optional[int]     ):
							import tarfile

							a__      =tmp_path_factory.mktemp('data'     ) / 'file.txt.tar'
							with tarfile.TarFile(__a    ,     'w'     ) as f:
														f.add(__a    ,     arcname=os.path.basename(__a     )     )
							return path






@pytest.fixture(scope='session'     )
def   _lowercase(					__a				:						Union[str, Any]     ):
							import lzma

							a__      =tmp_path_factory.mktemp('data'     ) / 'file.txt.xz'
							a__      =bytes(__a    ,     'utf-8'     )
							with lzma.open(__a    ,     'wb'     ) as f:
														f.write(__a     )
							return path






@pytest.fixture(scope='session'     )
def   _lowercase(					__a				:						str    ,     __a				:						Any     ):
							import zipfile

							a__      =tmp_path_factory.mktemp('data'     ) / 'file.txt.zip'
							with zipfile.ZipFile(__a    ,     'w'     ) as f:
														f.write(__a    ,     arcname=os.path.basename(__a     )     )
							return path






@pytest.fixture(scope='session'     )
def   _lowercase(					__a				:						Tuple     ):
							if datasets.config.ZSTANDARD_AVAILABLE:
														import zstandard as zstd

														a__      =tmp_path_factory.mktemp('data'     ) / 'file.txt.zst'
														a__      =bytes(__a    ,     'utf-8'     )
														with zstd.open(__a    ,     'wb'     ) as f:
																					f.write(__a     )
														return path






@pytest.fixture(scope='session'     )
def   _lowercase(					__a				:						str     ):
							a__      =tmp_path_factory.mktemp('data'     ) / 'file.xml'
							a__      =textwrap.dedent(
							    '\\n    <?xml version="1.0" encoding="UTF-8" ?>\n    <tmx version="1.4">\n      <header segtype="sentence" srclang="ca" />\n      <body>\n        <tu>\n          <tuv xml:lang="ca"><seg>Contingut 1</seg></tuv>\n          <tuv xml:lang="en"><seg>Content 1</seg></tuv>\n        </tu>\n        <tu>\n          <tuv xml:lang="ca"><seg>Contingut 2</seg></tuv>\n          <tuv xml:lang="en"><seg>Content 2</seg></tuv>\n        </tu>\n        <tu>\n          <tuv xml:lang="ca"><seg>Contingut 3</seg></tuv>\n          <tuv xml:lang="en"><seg>Content 3</seg></tuv>\n        </tu>\n        <tu>\n          <tuv xml:lang="ca"><seg>Contingut 4</seg></tuv>\n          <tuv xml:lang="en"><seg>Content 4</seg></tuv>\n        </tu>\n        <tu>\n          <tuv xml:lang="ca"><seg>Contingut 5</seg></tuv>\n          <tuv xml:lang="en"><seg>Content 5</seg></tuv>\n        </tu>\n      </body>\n    </tmx>'     )
							with open(__a    ,     'w'     ) as f:
														f.write(__a     )
							return filename


_lowerCAmelCase:						str   				=       [
    {'col_1': '0', 'col_2': 0, 'col_3': 0.0},
    {'col_1': '1', 'col_2': 1, 'col_3': 1.0},
    {'col_1': '2', 'col_2': 2, 'col_3': 2.0},
    {'col_1': '3', 'col_2': 3, 'col_3': 3.0},
]
_lowerCAmelCase:						Any   				=       [
    {'col_1': '4', 'col_2': 4, 'col_3': 4.0},
    {'col_1': '5', 'col_2': 5, 'col_3': 5.0},
]
_lowerCAmelCase:						Optional[Any]   				=       {
    'col_1': ['0', '1', '2', '3'],
    'col_2': [0, 1, 2, 3],
    'col_3': [0.0, 1.0, 2.0, 3.0],
}

_lowerCAmelCase:						List[Any]   				=       [
    {'col_3': 0.0, 'col_1': '0', 'col_2': 0},
    {'col_3': 1.0, 'col_1': '1', 'col_2': 1},
]

_lowerCAmelCase:						Optional[int]   				=       [
    {'col_1': 's0', 'col_2': 0, 'col_3': 0.0},
    {'col_1': 's1', 'col_2': 1, 'col_3': 1.0},
    {'col_1': 's2', 'col_2': 2, 'col_3': 2.0},
    {'col_1': 's3', 'col_2': 3, 'col_3': 3.0},
]






@pytest.fixture(scope='session'     )
def   _lowercase(					):
							return DATA_DICT_OF_LISTS






@pytest.fixture(scope='session'     )
def   _lowercase(					__a				:						Optional[int]     ):
							a__      =datasets.Dataset.from_dict(__a     )
							a__      =str(tmp_path_factory.mktemp('data'     ) / 'dataset.arrow'     )
							dataset.map(cache_file_name=__a     )
							return path






@pytest.fixture(scope='session'     )
def   _lowercase(					__a				:						Optional[Any]     ):
							a__      =str(tmp_path_factory.mktemp('data'     ) / 'dataset.sqlite'     )
							with contextlib.closing(sqlitea.connect(__a     )     ) as con:
														a__      =con.cursor()
														cur.execute('CREATE TABLE dataset(col_1 text, col_2 int, col_3 real)'     )
														for item in DATA:
																					cur.execute('INSERT INTO dataset(col_1, col_2, col_3) VALUES (?, ?, ?)'    ,     tuple(item.values()     )     )
														con.commit()
							return path






@pytest.fixture(scope='session'     )
def   _lowercase(					__a				:						List[Any]     ):
							a__      =str(tmp_path_factory.mktemp('data'     ) / 'dataset.csv'     )
							with open(__a    ,     'w'    ,     newline=''     ) as f:
														a__      =csv.DictWriter(__a    ,     fieldnames=['col_1', 'col_2', 'col_3']     )
														writer.writeheader()
														for item in DATA:
																					writer.writerow(__a     )
							return path






@pytest.fixture(scope='session'     )
def   _lowercase(					__a				:						List[Any]     ):
							a__      =str(tmp_path_factory.mktemp('data'     ) / 'dataset2.csv'     )
							with open(__a    ,     'w'    ,     newline=''     ) as f:
														a__      =csv.DictWriter(__a    ,     fieldnames=['col_1', 'col_2', 'col_3']     )
														writer.writeheader()
														for item in DATA:
																					writer.writerow(__a     )
							return path






@pytest.fixture(scope='session'     )
def   _lowercase(					__a				:						Optional[int]    ,     __a				:						Tuple     ):
							import bza

							a__      =tmp_path_factory.mktemp('data'     ) / 'dataset.csv.bz2'
							with open(__a    ,     'rb'     ) as f:
														a__      =f.read()
							# data = bytes(FILE_CONTENT, "utf-8")
							with bza.open(__a    ,     'wb'     ) as f:
														f.write(__a     )
							return path






@pytest.fixture(scope='session'     )
def   _lowercase(					__a				:						Optional[int]    ,     __a				:						Optional[Any]    ,     __a				:						int     ):
							a__      =tmp_path_factory.mktemp('data'     ) / 'dataset.csv.zip'
							with zipfile.ZipFile(__a    ,     'w'     ) as f:
														f.write(__a    ,     arcname=os.path.basename(__a     )     )
														f.write(__a    ,     arcname=os.path.basename(__a     )     )
							return path






@pytest.fixture(scope='session'     )
def   _lowercase(					__a				:						Dict    ,     __a				:						str    ,     __a				:						Tuple     ):
							a__      =tmp_path_factory.mktemp('data'     ) / 'dataset.csv.zip'
							with zipfile.ZipFile(__a    ,     'w'     ) as f:
														f.write(__a    ,     arcname=os.path.basename(csv_path.replace('.csv'    ,     '.CSV'     )     )     )
														f.write(__a    ,     arcname=os.path.basename(csva_path.replace('.csv'    ,     '.CSV'     )     )     )
							return path






@pytest.fixture(scope='session'     )
def   _lowercase(					__a				:						Any    ,     __a				:						str    ,     __a				:						Union[str, Any]     ):
							a__      =tmp_path_factory.mktemp('data'     ) / 'dataset_with_dir.csv.zip'
							with zipfile.ZipFile(__a    ,     'w'     ) as f:
														f.write(__a    ,     arcname=os.path.join('main_dir'    ,     os.path.basename(__a     )     )     )
														f.write(__a    ,     arcname=os.path.join('main_dir'    ,     os.path.basename(__a     )     )     )
							return path






@pytest.fixture(scope='session'     )
def   _lowercase(					__a				:						List[Any]     ):
							a__      =str(tmp_path_factory.mktemp('data'     ) / 'dataset.parquet'     )
							a__      =pa.schema(
							    {
							        'col_1': pa.string(),
							        'col_2': pa.intaa(),
							        'col_3': pa.floataa(),
							    }     )
							with open(__a    ,     'wb'     ) as f:
														a__      =pq.ParquetWriter(__a    ,     schema=__a     )
														a__      =pa.Table.from_pydict({k: [DATA[i][k] for i in range(len(__a     )     )] for k in DATA[0]}    ,     schema=__a     )
														writer.write_table(__a     )
														writer.close()
							return path






@pytest.fixture(scope='session'     )
def   _lowercase(					__a				:						Dict     ):
							a__      =str(tmp_path_factory.mktemp('data'     ) / 'dataset.json'     )
							a__      ={'data': DATA}
							with open(__a    ,     'w'     ) as f:
														json.dump(__a    ,     __a     )
							return path






@pytest.fixture(scope='session'     )
def   _lowercase(					__a				:						str     ):
							a__      =str(tmp_path_factory.mktemp('data'     ) / 'dataset.json'     )
							a__      ={'data': DATA_DICT_OF_LISTS}
							with open(__a    ,     'w'     ) as f:
														json.dump(__a    ,     __a     )
							return path






@pytest.fixture(scope='session'     )
def   _lowercase(					__a				:						Optional[Any]     ):
							a__      =str(tmp_path_factory.mktemp('data'     ) / 'dataset.jsonl'     )
							with open(__a    ,     'w'     ) as f:
														for item in DATA:
																					f.write(json.dumps(__a     ) + '\n'     )
							return path






@pytest.fixture(scope='session'     )
def   _lowercase(					__a				:						Optional[Any]     ):
							a__      =str(tmp_path_factory.mktemp('data'     ) / 'dataset2.jsonl'     )
							with open(__a    ,     'w'     ) as f:
														for item in DATA:
																					f.write(json.dumps(__a     ) + '\n'     )
							return path






@pytest.fixture(scope='session'     )
def   _lowercase(					__a				:						Tuple     ):
							a__      =str(tmp_path_factory.mktemp('data'     ) / 'dataset_312.jsonl'     )
							with open(__a    ,     'w'     ) as f:
														for item in DATA_312:
																					f.write(json.dumps(__a     ) + '\n'     )
							return path






@pytest.fixture(scope='session'     )
def   _lowercase(					__a				:						Dict     ):
							a__      =str(tmp_path_factory.mktemp('data'     ) / 'dataset-str.jsonl'     )
							with open(__a    ,     'w'     ) as f:
														for item in DATA_STR:
																					f.write(json.dumps(__a     ) + '\n'     )
							return path






@pytest.fixture(scope='session'     )
def   _lowercase(					__a				:						List[str]    ,     __a				:						Union[str, Any]     ):
							import gzip

							a__      =str(tmp_path_factory.mktemp('data'     ) / 'dataset.txt.gz'     )
							with open(__a    ,     'rb'     ) as orig_file:
														with gzip.open(__a    ,     'wb'     ) as zipped_file:
																					zipped_file.writelines(__a     )
							return path






@pytest.fixture(scope='session'     )
def   _lowercase(					__a				:						Optional[Any]    ,     __a				:						Tuple     ):
							import gzip

							a__      =str(tmp_path_factory.mktemp('data'     ) / 'dataset.jsonl.gz'     )
							with open(__a    ,     'rb'     ) as orig_file:
														with gzip.open(__a    ,     'wb'     ) as zipped_file:
																					zipped_file.writelines(__a     )
							return path






@pytest.fixture(scope='session'     )
def   _lowercase(					__a				:						Optional[int]    ,     __a				:						Optional[int]    ,     __a				:						List[Any]     ):
							a__      =tmp_path_factory.mktemp('data'     ) / 'dataset.jsonl.zip'
							with zipfile.ZipFile(__a    ,     'w'     ) as f:
														f.write(__a    ,     arcname=os.path.basename(__a     )     )
														f.write(__a    ,     arcname=os.path.basename(__a     )     )
							return path






@pytest.fixture(scope='session'     )
def   _lowercase(					__a				:						Any    ,     __a				:						Optional[Any]    ,     __a				:						Tuple    ,     __a				:						Dict     ):
							a__      =tmp_path_factory.mktemp('data'     ) / 'dataset_nested.jsonl.zip'
							with zipfile.ZipFile(__a    ,     'w'     ) as f:
														f.write(__a    ,     arcname=os.path.join('nested'    ,     os.path.basename(__a     )     )     )
							return path






@pytest.fixture(scope='session'     )
def   _lowercase(					__a				:						Optional[int]    ,     __a				:						Optional[int]    ,     __a				:						Union[str, Any]     ):
							a__      =tmp_path_factory.mktemp('data'     ) / 'dataset_with_dir.jsonl.zip'
							with zipfile.ZipFile(__a    ,     'w'     ) as f:
														f.write(__a    ,     arcname=os.path.join('main_dir'    ,     os.path.basename(__a     )     )     )
														f.write(__a    ,     arcname=os.path.join('main_dir'    ,     os.path.basename(__a     )     )     )
							return path






@pytest.fixture(scope='session'     )
def   _lowercase(					__a				:						Optional[Any]    ,     __a				:						Union[str, Any]    ,     __a				:						Any     ):
							a__      =tmp_path_factory.mktemp('data'     ) / 'dataset.jsonl.tar'
							with tarfile.TarFile(__a    ,     'w'     ) as f:
														f.add(__a    ,     arcname=os.path.basename(__a     )     )
														f.add(__a    ,     arcname=os.path.basename(__a     )     )
							return path






@pytest.fixture(scope='session'     )
def   _lowercase(					__a				:						int    ,     __a				:						Union[str, Any]    ,     __a				:						str    ,     __a				:						Union[str, Any]     ):
							a__      =tmp_path_factory.mktemp('data'     ) / 'dataset_nested.jsonl.tar'
							with tarfile.TarFile(__a    ,     'w'     ) as f:
														f.add(__a    ,     arcname=os.path.join('nested'    ,     os.path.basename(__a     )     )     )
							return path






@pytest.fixture(scope='session'     )
def   _lowercase(					__a				:						Any     ):
							a__      =['0', '1', '2', '3']
							a__      =str(tmp_path_factory.mktemp('data'     ) / 'dataset.txt'     )
							with open(__a    ,     'w'     ) as f:
														for item in data:
																					f.write(item + '\n'     )
							return path






@pytest.fixture(scope='session'     )
def   _lowercase(					__a				:						Any     ):
							a__      =['0', '1', '2', '3']
							a__      =str(tmp_path_factory.mktemp('data'     ) / 'dataset2.txt'     )
							with open(__a    ,     'w'     ) as f:
														for item in data:
																					f.write(item + '\n'     )
							return path






@pytest.fixture(scope='session'     )
def   _lowercase(					__a				:						Any     ):
							a__      =['0', '1', '2', '3']
							a__      =tmp_path_factory.mktemp('data'     ) / 'dataset.abc'
							with open(__a    ,     'w'     ) as f:
														for item in data:
																					f.write(item + '\n'     )
							return path






@pytest.fixture(scope='session'     )
def   _lowercase(					__a				:						List[str]    ,     __a				:						Optional[Any]    ,     __a				:						Dict     ):
							a__      =tmp_path_factory.mktemp('data'     ) / 'dataset.text.zip'
							with zipfile.ZipFile(__a    ,     'w'     ) as f:
														f.write(__a    ,     arcname=os.path.basename(__a     )     )
														f.write(__a    ,     arcname=os.path.basename(__a     )     )
							return path






@pytest.fixture(scope='session'     )
def   _lowercase(					__a				:						int    ,     __a				:						Union[str, Any]    ,     __a				:						Optional[int]     ):
							a__      =tmp_path_factory.mktemp('data'     ) / 'dataset_with_dir.text.zip'
							with zipfile.ZipFile(__a    ,     'w'     ) as f:
														f.write(__a    ,     arcname=os.path.join('main_dir'    ,     os.path.basename(__a     )     )     )
														f.write(__a    ,     arcname=os.path.join('main_dir'    ,     os.path.basename(__a     )     )     )
							return path






@pytest.fixture(scope='session'     )
def   _lowercase(					__a				:						List[Any]    ,     __a				:						Union[str, Any]    ,     __a				:						Union[str, Any]     ):
							a__      =tmp_path_factory.mktemp('data'     ) / 'dataset.ext.zip'
							with zipfile.ZipFile(__a    ,     'w'     ) as f:
														f.write(__a    ,     arcname=os.path.basename('unsupported.ext'     )     )
														f.write(__a    ,     arcname=os.path.basename('unsupported_2.ext'     )     )
							return path






@pytest.fixture(scope='session'     )
def   _lowercase(					__a				:						Dict     ):
							a__      ='\n'.join(['First', 'Second\u2029with Unicode new line', 'Third']     )
							a__      =str(tmp_path_factory.mktemp('data'     ) / 'dataset_with_unicode_new_lines.txt'     )
							with open(__a    ,     'w'    ,     encoding='utf-8'     ) as f:
														f.write(__a     )
							return path






@pytest.fixture(scope='session'     )
def   _lowercase(					):
							return os.path.join('tests'    ,     'features'    ,     'data'    ,     'test_image_rgb.jpg'     )






@pytest.fixture(scope='session'     )
def   _lowercase(					):
							return os.path.join('tests'    ,     'features'    ,     'data'    ,     'test_audio_44100.wav'     )






@pytest.fixture(scope='session'     )
def   _lowercase(					__a				:						Optional[Any]    ,     __a				:						Optional[Any]     ):
							a__      =tmp_path_factory.mktemp('data'     ) / 'dataset.img.zip'
							with zipfile.ZipFile(__a    ,     'w'     ) as f:
														f.write(__a    ,     arcname=os.path.basename(__a     )     )
														f.write(__a    ,     arcname=os.path.basename(__a     ).replace('.jpg'    ,     '2.jpg'     )     )
							return path







@pytest.fixture(scope='session'     )
def   _lowercase(					__a				:						List[Any]     ):
							a__      =tmp_path_factory.mktemp('data_dir'     )

							(data_dir / "subdir").mkdir()
							with open(data_dir / 'subdir' / 'train.txt'    ,     'w'     ) as f:
														f.write('foo\n' * 10     )
							with open(data_dir / 'subdir' / 'test.txt'    ,     'w'     ) as f:
														f.write('bar\n' * 10     )
							# hidden file
							with open(data_dir / 'subdir' / '.test.txt'    ,     'w'     ) as f:
														f.write('bar\n' * 10     )

							# hidden directory
							(data_dir / ".subdir").mkdir()
							with open(data_dir / '.subdir' / 'train.txt'    ,     'w'     ) as f:
														f.write('foo\n' * 10     )
							with open(data_dir / '.subdir' / 'test.txt'    ,     'w'     ) as f:
														f.write('bar\n' * 10     )

							return data_dir





from importlib import import_module

from .logging import get_logger


_lowerCAmelCase:						str   				=       get_logger(__name__)




class       lowercase_					:





				def __init__(				self       ,  lowercase_       ,  lowercase_=None)  -> Tuple:
											a__      =attrs or []
											if module is not None:
																		for key in module.__dict__:
																									if key in attrs or not key.startswith('__'):
																																setattr(self       ,  lowercase_       ,  getattr(lowercase_       ,  lowercase_))
											a__      =module._original_module if isinstance(lowercase_       ,  _PatchedModuleObj) else module







class       lowercase_					:
				snake_case	    =[]





				def __init__(				self       ,  lowercase_       ,  lowercase_       ,  lowercase_       ,  lowercase_=None)  -> List[str]:
											a__      =obj
											a__      =target
											a__      =new
											a__      =target.split('.')[0]
											a__      ={}
											a__      =attrs or []





				def __enter__(				self)  -> Optional[int]:
											*a__    ,     a__      =self.target.split('.')

											# Patch modules:
											# it's used to patch attributes of submodules like "os.path.join";
											# in this case we need to patch "os" and "os.path"

											for i in range(len(lowercase_)):
																		try:
																									a__      =import_module('.'.join(submodules[: i + 1]))
																		except ModuleNotFoundError:
																									continue
																		# We iterate over all the globals in self.obj in case we find "os" or "os.path"
																		for attr in self.obj.__dir__():
																									a__      =getattr(self.obj       ,  lowercase_)
																									# We don't check for the name of the global, but rather if its value *is* "os" or "os.path".
																									# This allows to patch renamed modules like "from os import path as ospath".
																									if obj_attr is submodule or (
																									    (isinstance(lowercase_       ,  _PatchedModuleObj) and obj_attr._original_module is submodule)
																									):
																																a__      =obj_attr
																																# patch at top level
																																setattr(self.obj       ,  lowercase_       ,  _PatchedModuleObj(lowercase_       ,  attrs=self.attrs))
																																a__      =getattr(self.obj       ,  lowercase_)
																																# construct lower levels patches
																																for key in submodules[i + 1 :]:
																																							setattr(lowercase_       ,  lowercase_       ,  _PatchedModuleObj(getattr(lowercase_       ,  lowercase_       ,  lowercase_)       ,  attrs=self.attrs))
																																							a__      =getattr(lowercase_       ,  lowercase_)
																																# finally set the target attribute
																																setattr(lowercase_       ,  lowercase_       ,  self.new)

        # Patch attribute itself:
        # it's used for builtins like "open",
        # and also to patch "os.path.join" we may also need to patch "join"
        # itself if it was imported as "from os.path import join".

											if submodules:  # if it's an attribute of a submodule like "os.path.join"
																		try:
																									a__      =getattr(import_module('.'.join(lowercase_))       ,  lowercase_)
																		except (AttributeError, ModuleNotFoundError):
																									return
																		# We iterate over all the globals in self.obj in case we find "os.path.join"
																		for attr in self.obj.__dir__():
																									# We don't check for the name of the global, but rather if its value *is* "os.path.join".
																									# This allows to patch renamed attributes like "from os.path import join as pjoin".
																									if getattr(self.obj       ,  lowercase_) is attr_value:
																																a__      =getattr(self.obj       ,  lowercase_)
																																setattr(self.obj       ,  lowercase_       ,  self.new)
											elif target_attr in globals()["__builtins__"]:  # if it'a s builtin like "open"
																		a__      =globals()['__builtins__'][target_attr]
																		setattr(self.obj       ,  lowercase_       ,  self.new)
											else:
																		raise RuntimeError(F"""Tried to patch attribute {target_attr} instead of a submodule.""")





				def __exit__(				self       ,  *lowercase_)  -> str:
											for attr in list(self.original):
																		setattr(self.obj       ,  lowercase_       ,  self.original.pop(lowercase_))





				def 						__UpperCamelCase    (				self)  -> Any:
											self.__enter__()
											self._active_patches.append(self)





				def 						__UpperCamelCase    (				self)  -> Union[str, Any]:
											try:
																		self._active_patches.remove(self)
											except ValueError:
																		# If the patch hasn't been started this will fail
																		return None

											return self.__exit__()

