





import posixpath
from pathlib import Path
from unittest.mock import patch

import pytest
from fsspec.implementations.local import AbstractFileSystem, LocalFileSystem, stringify_path
from fsspec.registry import _registry as _fsspec_registry





class A_   (     _lowerCamelCase  ):
   lowerCAmelCase__  	=					"""mock"""




   def __init__(self      :int       ,  *_UpperCamelCase      :int       ,  _UpperCamelCase      :Tuple       ,  **_UpperCamelCase      :str					)->   List[str]:
         super().__init__()
         __A			  =							LocalFileSystem(*_UpperCamelCase       ,  **_UpperCamelCase					)
         __A			  =							Path(_UpperCamelCase					).resolve().as_posix() + '''/'''




   def _lowerCAmelCase (self      :str       ,  _UpperCamelCase      :Dict       ,  *_UpperCamelCase      :int       ,  **_UpperCamelCase      :Dict					)->   int:
         __A			  =							posixpath.join(self.local_root_dir       ,  self._strip_protocol(_UpperCamelCase					)					)
         return self._fs.mkdir(_UpperCamelCase       ,  *_UpperCamelCase       ,  **_UpperCamelCase					)




   def _lowerCAmelCase (self      :Union[str, Any]       ,  _UpperCamelCase      :List[Any]       ,  *_UpperCamelCase      :List[Any]       ,  **_UpperCamelCase      :Union[str, Any]					)->   List[Any]:
         __A			  =							posixpath.join(self.local_root_dir       ,  self._strip_protocol(_UpperCamelCase					)					)
         return self._fs.makedirs(_UpperCamelCase       ,  *_UpperCamelCase       ,  **_UpperCamelCase					)




   def _lowerCAmelCase (self      :Union[str, Any]       ,  _UpperCamelCase      :Union[str, Any]					)->   Dict:
         __A			  =							posixpath.join(self.local_root_dir       ,  self._strip_protocol(_UpperCamelCase					)					)
         return self._fs.rmdir(_UpperCamelCase					)




   def _lowerCAmelCase (self      :Tuple       ,  _UpperCamelCase      :Optional[int]       ,  _UpperCamelCase      :Optional[int]=True       ,  *_UpperCamelCase      :Optional[Any]       ,  **_UpperCamelCase      :Tuple					)->   Tuple:
         __A			  =							posixpath.join(self.local_root_dir       ,  self._strip_protocol(_UpperCamelCase					)					)
         __A			  =							self._fs.ls(_UpperCamelCase       ,  detail=_UpperCamelCase       ,  *_UpperCamelCase       ,  **_UpperCamelCase					)
         if detail:
               return [{**info, "name": info["name"][len(self.local_root_dir					) :]} for info in out]
         else:
               return [name[len(self.local_root_dir					) :] for name in out]




   def _lowerCAmelCase (self      :int       ,  _UpperCamelCase      :Optional[Any]       ,  *_UpperCamelCase      :Optional[Any]       ,  **_UpperCamelCase      :Tuple					)->   Union[str, Any]:
         __A			  =							posixpath.join(self.local_root_dir       ,  self._strip_protocol(_UpperCamelCase					)					)
         __A			  =							dict(self._fs.info(_UpperCamelCase       ,  *_UpperCamelCase       ,  **_UpperCamelCase					)					)
         __A			  =							out['''name'''][len(self.local_root_dir					) :]
         return out




   def _lowerCAmelCase (self      :List[str]       ,  _UpperCamelCase      :int       ,  _UpperCamelCase      :Dict       ,  *_UpperCamelCase      :str       ,  **_UpperCamelCase      :Union[str, Any]					)->   Optional[Any]:
         __A			  =							posixpath.join(self.local_root_dir       ,  self._strip_protocol(_UpperCamelCase					)					)
         __A			  =							posixpath.join(self.local_root_dir       ,  self._strip_protocol(_UpperCamelCase					)					)
         return self._fs.cp_file(_UpperCamelCase       ,  _UpperCamelCase       ,  *_UpperCamelCase       ,  **_UpperCamelCase					)




   def _lowerCAmelCase (self      :Optional[Any]       ,  _UpperCamelCase      :List[Any]       ,  *_UpperCamelCase      :Optional[Any]       ,  **_UpperCamelCase      :List[Any]					)->   Optional[Any]:
         __A			  =							posixpath.join(self.local_root_dir       ,  self._strip_protocol(_UpperCamelCase					)					)
         return self._fs.rm_file(_UpperCamelCase       ,  *_UpperCamelCase       ,  **_UpperCamelCase					)




   def _lowerCAmelCase (self      :Optional[int]       ,  _UpperCamelCase      :Union[str, Any]       ,  *_UpperCamelCase      :Optional[int]       ,  **_UpperCamelCase      :List[str]					)->   int:
         __A			  =							posixpath.join(self.local_root_dir       ,  self._strip_protocol(_UpperCamelCase					)					)
         return self._fs.rm(_UpperCamelCase       ,  *_UpperCamelCase       ,  **_UpperCamelCase					)




   def _lowerCAmelCase (self      :Optional[Any]       ,  _UpperCamelCase      :Any       ,  *_UpperCamelCase      :str       ,  **_UpperCamelCase      :Tuple					)->   Optional[int]:
         __A			  =							posixpath.join(self.local_root_dir       ,  self._strip_protocol(_UpperCamelCase					)					)
         return self._fs._open(_UpperCamelCase       ,  *_UpperCamelCase       ,  **_UpperCamelCase					)




   def _lowerCAmelCase (self      :Dict       ,  _UpperCamelCase      :Any					)->   List[Any]:
         __A			  =							posixpath.join(self.local_root_dir       ,  self._strip_protocol(_UpperCamelCase					)					)
         return self._fs.created(_UpperCamelCase					)




   def _lowerCAmelCase (self      :Dict       ,  _UpperCamelCase      :str					)->   Union[str, Any]:
         __A			  =							posixpath.join(self.local_root_dir       ,  self._strip_protocol(_UpperCamelCase					)					)
         return self._fs.modified(_UpperCamelCase					)






   @classmethod
   def _lowerCAmelCase (cls      :Optional[Any]       ,  _UpperCamelCase      :Dict					)->   Union[str, Any]:
         __A			  =							stringify_path(_UpperCamelCase					)
         if path.startswith('''mock://'''					):
               __A			  =							path[7:]
         return path





class A_   (     _lowerCamelCase  ):
   lowerCAmelCase__  	=					"""tmp"""
   lowerCAmelCase__  	=					None




   def __init__(self      :Optional[int]       ,  *_UpperCamelCase      :Any       ,  **_UpperCamelCase      :Dict					)->   Optional[int]:
         assert self.tmp_dir is not None, "TmpDirFileSystem.tmp_dir is not set"
         super().__init__(*_UpperCamelCase       ,  **_UpperCamelCase       ,  local_root_dir=self.tmp_dir       ,  auto_mkdir=_UpperCamelCase					)






   @classmethod
   def _lowerCAmelCase (cls      :str       ,  _UpperCamelCase      :Optional[int]					)->   Optional[int]:
         __A			  =							stringify_path(_UpperCamelCase					)
         if path.startswith('''tmp://'''					):
               __A			  =							path[6:]
         return path





@pytest.fixture
def _a							(      )      ->		Optional[Any]:







      '''simple docstring'''






      __A			  =							MockFileSystem
      __A			  =							TmpDirFileSystem
      yield
      del _fsspec_registry["mock"]
      del _fsspec_registry["tmp"]



@pytest.fixture
def _a							(      lowerCamelCase:  Dict   ,							lowerCamelCase:  int					)      ->		str:







      '''simple docstring'''






      __A			  =							tmp_path_factory.mktemp('''mockfs'''					)
      return MockFileSystem(local_root_dir=lowerCamelCase   ,							auto_mkdir=lowerCamelCase					)







@pytest.fixture
def _a							(      lowerCamelCase:  Optional[Any]   ,							lowerCamelCase:  Tuple					)      ->		int:







      '''simple docstring'''






      __A			  =							tmp_path_factory.mktemp('''tmpfs'''					)
      with patch.object(lowerCamelCase   ,							'''tmp_dir'''   ,							lowerCamelCase					):
            yield TmpDirFileSystem()












from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tokenizers_available, is_torch_available


snake_case__   :				Tuple						=	{
    'configuration_realm': ['REALM_PRETRAINED_CONFIG_ARCHIVE_MAP', 'RealmConfig'],
    'tokenization_realm': ['RealmTokenizer'],
}

try:
       if not is_tokenizers_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       snake_case__   :				Tuple						=	['RealmTokenizerFast']

try:
       if not is_torch_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       snake_case__   :				str						=	[
           'REALM_PRETRAINED_MODEL_ARCHIVE_LIST',
           'RealmEmbedder',
           'RealmForOpenQA',
           'RealmKnowledgeAugEncoder',
           'RealmPreTrainedModel',
           'RealmReader',
           'RealmScorer',
           'load_tf_weights_in_realm',
       ]
       snake_case__   :				Any						=	['RealmRetriever']


if TYPE_CHECKING:
       from .configuration_realm import REALM_PRETRAINED_CONFIG_ARCHIVE_MAP, RealmConfig
       from .tokenization_realm import RealmTokenizer

       try:
              if not is_tokenizers_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .tokenization_realm import RealmTokenizerFast

       try:
              if not is_torch_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_realm import (
                  REALM_PRETRAINED_MODEL_ARCHIVE_LIST,
                  RealmEmbedder,
                  RealmForOpenQA,
                  RealmKnowledgeAugEncoder,
                  RealmPreTrainedModel,
                  RealmReader,
                  RealmScorer,
                  load_tf_weights_in_realm,
              )
              from .retrieval_realm import RealmRetriever


else:
       import sys

       snake_case__   :				Any						=	_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)





