





"""simple docstring"""





import logging
import os
import threading
import time


try:
  import warnings
except ImportError:
  __A											=						None

try:
  import msvcrt
except ImportError:
  __A											=						None

try:
  import fcntl
except ImportError:
  __A											=						None


# Backward compatibility
# ------------------------------------------------
try:
  TimeoutError
except NameError:
  __A											=						OSError


# Data
# ------------------------------------------------
__A											=						[
    """Timeout""",
    """BaseFileLock""",
    """WindowsFileLock""",
    """UnixFileLock""",
    """SoftFileLock""",
    """FileLock""",
]

__A											=						"""3.0.12"""


__A											=						None
def 					__A  ()   ->Dict:





  """simple docstring"""


  global _logger
  lowerCAmelCase__     :Optional[int]											=				_logger or logging.getLogger(__name__     )
  return _logger






class    _lowerCAmelCase  (	a			):
       """simple docstring"""




       def __init__(       self       ,					__UpperCAmelCase ):



         '''simple docstring'''

         lowerCAmelCase__     :List[str]											=				lock_file
         return None






       def __str__(       self ):



         '''simple docstring'''

         lowerCAmelCase__     :Any											=				F"The file lock '{self.lock_file}' could not be acquired."
         return temp






class    _lowerCAmelCase  :
       """simple docstring"""




       def __init__(       self       ,					__UpperCAmelCase ):



         '''simple docstring'''

         lowerCAmelCase__     :Tuple											=				lock
         return None






       def __enter__(       self ):



         '''simple docstring'''

         return self.lock






       def __exit__(       self       ,					__UpperCAmelCase       ,					__UpperCAmelCase       ,					__UpperCAmelCase ):



         '''simple docstring'''

         self.lock.release()
         return None






class    _lowerCAmelCase  :
       """simple docstring"""




       def __init__(       self       ,					__UpperCAmelCase       ,					__UpperCAmelCase=-1       ,					__UpperCAmelCase=None ):



         '''simple docstring'''

         lowerCAmelCase__     :Union[str, Any]											=				max_filename_length if max_filename_length is not None else 2_5_5
         # Hash the filename if it's too long
         lowerCAmelCase__     :int											=				self.hash_filename_if_too_long(__UpperCAmelCase       ,					__UpperCAmelCase )
         # The path to the lock file.
         lowerCAmelCase__     :Optional[int]											=				lock_file

         # The file descriptor for the *_lock_file* as it is returned by the
         # os.open() function.
         # This file lock is only NOT None, if the object currently holds the
         # lock.
         lowerCAmelCase__     :Any											=				None

         # The default timeout value.
         lowerCAmelCase__     :Optional[int]											=				timeout

         # We use this lock primarily for the lock counter.
         lowerCAmelCase__     :Optional[Any]											=				threading.Lock()

         # The lock counter is used for implementing the nested locking
         # mechanism. Whenever the lock is acquired, the counter is increased and
         # the lock is only released, when this value is 0 again.
         lowerCAmelCase__     :List[Any]											=				0
         return None






       @property
       def 	snake_case		(       self ):



         '''simple docstring'''

         return self._lock_file






       @property
       def 	snake_case		(       self ):



         '''simple docstring'''

         return self._timeout






       @timeout.setter
       def 	snake_case		(       self       ,					__UpperCAmelCase ):



         '''simple docstring'''

         lowerCAmelCase__     :Any											=				float(__UpperCAmelCase )
         return None






       def 	snake_case		(       self ):



         '''simple docstring'''

         raise NotImplementedError()






       def 	snake_case		(       self ):



         '''simple docstring'''

         raise NotImplementedError()






       @property
       def 	snake_case		(       self ):



         '''simple docstring'''

         return self._lock_file_fd is not None






       def 	snake_case		(       self       ,					__UpperCAmelCase=None       ,					__UpperCAmelCase=0.05 ):



         '''simple docstring'''

         if timeout is None:
           lowerCAmelCase__     :Dict											=				self.timeout

         # Increment the number right at the beginning.
         # We can still undo it, if something fails.
         with self._thread_lock:
           self._lock_counter += 1

         lowerCAmelCase__     :Dict											=				id(self )
         lowerCAmelCase__     :List[str]											=				self._lock_file
         lowerCAmelCase__     :str											=				time.time()
         try:
           while True:
             with self._thread_lock:
               if not self.is_locked:
                 logger().debug(F"Attempting to acquire lock {lock_id} on {lock_filename}" )
                 self._acquire()

             if self.is_locked:
               logger().debug(F"Lock {lock_id} acquired on {lock_filename}" )
               break
             elif timeout >= 0 and time.time() - start_time > timeout:
               logger().debug(F"Timeout on acquiring lock {lock_id} on {lock_filename}" )
               raise Timeout(self._lock_file )
             else:
               logger().debug(
                   F"Lock {lock_id} not acquired on {lock_filename}, waiting {poll_intervall} seconds ..." )
               time.sleep(__UpperCAmelCase )
         except:  # noqa
           # Something did go wrong, so decrement the counter.
           with self._thread_lock:
             lowerCAmelCase__     :str											=				max(0       ,					self._lock_counter - 1 )

           raise
         return _Acquire_ReturnProxy(lock=self )






       def 	snake_case		(       self       ,					__UpperCAmelCase=False ):



         '''simple docstring'''

         with self._thread_lock:
           if self.is_locked:
             self._lock_counter -= 1

             if self._lock_counter == 0 or force:
               lowerCAmelCase__     :List[str]											=				id(self )
               lowerCAmelCase__     :int											=				self._lock_file

               logger().debug(F"Attempting to release lock {lock_id} on {lock_filename}" )
               self._release()
               lowerCAmelCase__     :List[Any]											=				0
               logger().debug(F"Lock {lock_id} released on {lock_filename}" )

         return None






       def __enter__(       self ):



         '''simple docstring'''

         self.acquire()
         return self






       def __exit__(       self       ,					__UpperCAmelCase       ,					__UpperCAmelCase       ,					__UpperCAmelCase ):



         '''simple docstring'''

         self.release()
         return None






       def __del__(       self ):



         '''simple docstring'''

         self.release(force=__UpperCAmelCase )
         return None






       def 	snake_case		(       self       ,					__UpperCAmelCase       ,					__UpperCAmelCase ):



         '''simple docstring'''

         lowerCAmelCase__     :List[Any]											=				os.path.basename(__UpperCAmelCase )
         if len(__UpperCAmelCase ) > max_length and max_length > 0:
           lowerCAmelCase__     :List[str]											=				os.path.dirname(__UpperCAmelCase )
           lowerCAmelCase__     :int											=				str(hash(__UpperCAmelCase ) )
           lowerCAmelCase__     :List[Any]											=				filename[: max_length - len(__UpperCAmelCase ) - 8] + '...' + hashed_filename + '.lock'
           return os.path.join(__UpperCAmelCase       ,					__UpperCAmelCase )
         else:
           return path






class    _lowerCAmelCase  (	a			):
       """simple docstring"""




       def __init__(       self       ,					__UpperCAmelCase       ,					__UpperCAmelCase=-1       ,					__UpperCAmelCase=None ):



         '''simple docstring'''

         from .file_utils import relative_to_absolute_path

         super().__init__(__UpperCAmelCase       ,					timeout=__UpperCAmelCase       ,					max_filename_length=__UpperCAmelCase )
         lowerCAmelCase__     :Any											=				'\\\\?\\' + relative_to_absolute_path(self.lock_file )






       def 	snake_case		(       self ):



         '''simple docstring'''

         lowerCAmelCase__     :List[str]											=				os.O_RDWR | os.O_CREAT | os.O_TRUNC

         try:
           lowerCAmelCase__     :List[str]											=				os.open(self._lock_file       ,					__UpperCAmelCase )
         except OSError:
           pass
         else:
           try:
             msvcrt.locking(__UpperCAmelCase       ,					msvcrt.LK_NBLCK       ,					1 )
           except OSError:
             os.close(__UpperCAmelCase )
           else:
             lowerCAmelCase__     :Any											=				fd
         return None






       def 	snake_case		(       self ):



         '''simple docstring'''

         lowerCAmelCase__     :List[Any]											=				self._lock_file_fd
         lowerCAmelCase__     :int											=				None
         msvcrt.locking(__UpperCAmelCase       ,					msvcrt.LK_UNLCK       ,					1 )
         os.close(__UpperCAmelCase )

         try:
           os.remove(self._lock_file )
         # Probably another instance of the application
         # that acquired the file lock.
         except OSError:
           pass
         return None






class    _lowerCAmelCase  (	a			):
       """simple docstring"""




       def __init__(       self       ,					__UpperCAmelCase       ,					__UpperCAmelCase=-1       ,					__UpperCAmelCase=None ):



         '''simple docstring'''

         lowerCAmelCase__     :Optional[int]											=				os.statvfs(os.path.dirname(__UpperCAmelCase ) ).f_namemax
         super().__init__(__UpperCAmelCase       ,					timeout=__UpperCAmelCase       ,					max_filename_length=__UpperCAmelCase )






       def 	snake_case		(       self ):



         '''simple docstring'''

         lowerCAmelCase__     :Optional[Any]											=				os.O_RDWR | os.O_CREAT | os.O_TRUNC
         lowerCAmelCase__     :Optional[Any]											=				os.open(self._lock_file       ,					__UpperCAmelCase )

         try:
           fcntl.flock(__UpperCAmelCase       ,					fcntl.LOCK_EX | fcntl.LOCK_NB )
         except OSError:
           os.close(__UpperCAmelCase )
         else:
           lowerCAmelCase__     :Optional[Any]											=				fd
         return None






       def 	snake_case		(       self ):



         '''simple docstring'''

         lowerCAmelCase__     :Union[str, Any]											=				self._lock_file_fd
         lowerCAmelCase__     :Optional[Any]											=				None
         fcntl.flock(__UpperCAmelCase       ,					fcntl.LOCK_UN )
         os.close(__UpperCAmelCase )
         return None






class    _lowerCAmelCase  (	a			):
       """simple docstring"""




       def 	snake_case		(       self ):



         '''simple docstring'''

         lowerCAmelCase__     :List[str]											=				os.O_WRONLY | os.O_CREAT | os.O_EXCL | os.O_TRUNC
         try:
           lowerCAmelCase__     :int											=				os.open(self._lock_file       ,					__UpperCAmelCase )
         except OSError:
           pass
         else:
           lowerCAmelCase__     :Optional[Any]											=				fd
         return None






       def 	snake_case		(       self ):



         '''simple docstring'''

         os.close(self._lock_file_fd )
         lowerCAmelCase__     :Union[str, Any]											=				None

         try:
           os.remove(self._lock_file )
         # The file is already deleted and that's what we want.
         except OSError:
           pass
         return None






__A											=						None

if msvcrt:
  __A											=						WindowsFileLock
elif fcntl:
  __A											=						UnixFileLock
else:
  __A											=						SoftFileLock

  if warnings is not None:
    warnings.warn("""only soft file lock is available""")



from typing import TYPE_CHECKING

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


A_			:					Tuple    			=     {
    'configuration_xlm': ['XLM_PRETRAINED_CONFIG_ARCHIVE_MAP', 'XLMConfig', 'XLMOnnxConfig'],
    'tokenization_xlm': ['XLMTokenizer'],
}

try:
	if not is_torch_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	A_			:					Dict    			=     [
	    'XLM_PRETRAINED_MODEL_ARCHIVE_LIST',
	    'XLMForMultipleChoice',
	    'XLMForQuestionAnswering',
	    'XLMForQuestionAnsweringSimple',
	    'XLMForSequenceClassification',
	    'XLMForTokenClassification',
	    'XLMModel',
	    'XLMPreTrainedModel',
	    'XLMWithLMHeadModel',
	]

try:
	if not is_tf_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	A_			:					str    			=     [
	    'TF_XLM_PRETRAINED_MODEL_ARCHIVE_LIST',
	    'TFXLMForMultipleChoice',
	    'TFXLMForQuestionAnsweringSimple',
	    'TFXLMForSequenceClassification',
	    'TFXLMForTokenClassification',
	    'TFXLMMainLayer',
	    'TFXLMModel',
	    'TFXLMPreTrainedModel',
	    'TFXLMWithLMHeadModel',
	]


if TYPE_CHECKING:
	from .configuration_xlm import XLM_PRETRAINED_CONFIG_ARCHIVE_MAP, XLMConfig, XLMOnnxConfig
	from .tokenization_xlm import XLMTokenizer

	try:
		if not is_torch_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_xlm import (
		    XLM_PRETRAINED_MODEL_ARCHIVE_LIST,
		    XLMForMultipleChoice,
		    XLMForQuestionAnswering,
		    XLMForQuestionAnsweringSimple,
		    XLMForSequenceClassification,
		    XLMForTokenClassification,
		    XLMModel,
		    XLMPreTrainedModel,
		    XLMWithLMHeadModel,
		)

	try:
		if not is_tf_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_tf_xlm import (
		    TF_XLM_PRETRAINED_MODEL_ARCHIVE_LIST,
		    TFXLMForMultipleChoice,
		    TFXLMForQuestionAnsweringSimple,
		    TFXLMForSequenceClassification,
		    TFXLMForTokenClassification,
		    TFXLMMainLayer,
		    TFXLMModel,
		    TFXLMPreTrainedModel,
		    TFXLMWithLMHeadModel,
		)

else:
	import sys

	A_			:					Tuple    			=     _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)



