

import os
import string
import sys


__snake_case				:      int   		=			1 << 8

__snake_case				:      List[str]   		=			{
    """tab""": ord("""\t"""),
    """newline""": ord("""\r"""),
    """esc""": 27,
    """up""": 65 + ARROW_KEY_FLAG,
    """down""": 66 + ARROW_KEY_FLAG,
    """right""": 67 + ARROW_KEY_FLAG,
    """left""": 68 + ARROW_KEY_FLAG,
    """mod_int""": 91,
    """undefined""": sys.maxsize,
    """interrupt""": 3,
    """insert""": 50,
    """delete""": 51,
    """pg_up""": 53,
    """pg_down""": 54,
}

__snake_case				:      Any   		=			KEYMAP["""up"""]
__snake_case				:      Tuple   		=			KEYMAP["""left"""]

if sys.platform == "win32":
	__snake_case				:      Optional[Any]   		=			[]
	__snake_case				:      Dict   		=			{
	    B"""\xe0H""": KEYMAP["""up"""] - ARROW_KEY_FLAG,
	    B"""\x00H""": KEYMAP["""up"""] - ARROW_KEY_FLAG,
	    B"""\xe0P""": KEYMAP["""down"""] - ARROW_KEY_FLAG,
	    B"""\x00P""": KEYMAP["""down"""] - ARROW_KEY_FLAG,
	    B"""\xe0M""": KEYMAP["""right"""] - ARROW_KEY_FLAG,
	    B"""\x00M""": KEYMAP["""right"""] - ARROW_KEY_FLAG,
	    B"""\xe0K""": KEYMAP["""left"""] - ARROW_KEY_FLAG,
	    B"""\x00K""": KEYMAP["""left"""] - ARROW_KEY_FLAG,
	}

for i in range(10):
	__snake_case				:      Dict   		=			ord(str(i))


def 					_UpperCAmelCase				(						):

			'''simple docstring'''



			if os.name == "nt":
						import msvcrt

						a_						:						int 							= "mbcs"
						# Flush the keyboard buffer
						while msvcrt.kbhit():
									msvcrt.getch()
						if len(a__) == 0:
									# Read the keystroke
									a_						:						int 							= msvcrt.getch()

									# If it is a prefix char, get second part
									if ch in (b"\x00", b"\xe0"):
												a_						:						Union[str, Any] 							= ch + msvcrt.getch()
												# Translate actual Win chars to bullet char types
												try:
															a_						:						Optional[int] 							= chr(WIN_KEYMAP[cha])
															WIN_CH_BUFFER.append(chr(KEYMAP["""mod_int"""]))
															WIN_CH_BUFFER.append(a__)
															if ord(a__) in (
															    KEYMAP["insert"] - 1 << 9,
															    KEYMAP["delete"] - 1 << 9,
															    KEYMAP["pg_up"] - 1 << 9,
															    KEYMAP["pg_down"] - 1 << 9,
															):
																		WIN_CH_BUFFER.append(chr(1_2_6))
															a_						:						int 							= chr(KEYMAP["""esc"""])
												except KeyError:
															a_						:						Dict 							= cha[1]
									else:
												a_						:						Union[str, Any] 							= ch.decode(a__)
						else:
									a_						:						Optional[int] 							= WIN_CH_BUFFER.pop(0)
			elif os.name == "posix":
						import termios
						import tty

						a_						:						Tuple 							= sys.stdin.fileno()
						a_						:						int 							= termios.tcgetattr(a__)
						try:
									tty.setraw(a__)
									a_						:						Tuple 							= sys.stdin.read(1)
						finally:
									termios.tcsetattr(a__  ,	termios.TCSADRAIN  ,	a__)
			return ch



def 					_UpperCAmelCase				(						):

			'''simple docstring'''



			a_						:						str 							= get_raw_chars()
			if ord(a__) in [KEYMAP["interrupt"], KEYMAP["newline"]]:
						return char

			elif ord(a__) == KEYMAP["esc"]:
						a_						:						Tuple 							= get_raw_chars()
						if ord(a__) == KEYMAP["mod_int"]:
									a_						:						List[Any] 							= get_raw_chars()
									if ord(a__) >= KEYMAP["arrow_begin"] - ARROW_KEY_FLAG and ord(a__) <= KEYMAP["arrow_end"] - ARROW_KEY_FLAG:
												return chr(ord(a__) + ARROW_KEY_FLAG)
									else:
												return KEYMAP["undefined"]
						else:
									return get_raw_chars()

			else:
						if char in string.printable:
									return char
						else:
									return KEYMAP["undefined"]









from packaging import version

from .import_utils import is_accelerate_available


if is_accelerate_available():
  import accelerate






def    _A	(   lowerCamelCase ):
   if not is_accelerate_available():
      return method
   a__						:    List[Any]   		=	version.parse(accelerate.__version__ ).base_version
   if version.parse(lowerCamelCase ) < version.parse("0.17.0" ):
      return method

   def wrapper(self				,			*lowerCamelCase				,			**lowerCamelCase ):
      if hasattr(self				,			"_hf_hook" ) and hasattr(self._hf_hook				,			"pre_forward" ):
         self._hf_hook.pre_forward(self )
      return method(self				,			*lowerCamelCase				,			**lowerCamelCase )

   return wrapper

