1import string 2 3from ._compat import PY2 4from ._compat import unicode 5 6 7if PY2: 8 from pipenv.vendor.backports.functools_lru_cache import lru_cache 9else: 10 from functools import lru_cache 11 12 13class TOMLChar(unicode): 14 def __init__(self, c): 15 super(TOMLChar, self).__init__() 16 17 if len(self) > 1: 18 raise ValueError("A TOML character must be of length 1") 19 20 BARE = string.ascii_letters + string.digits + "-_" 21 KV = "= \t" 22 NUMBER = string.digits + "+-_.e" 23 SPACES = " \t" 24 NL = "\n\r" 25 WS = SPACES + NL 26 27 @lru_cache(maxsize=None) 28 def is_bare_key_char(self): # type: () -> bool 29 """ 30 Whether the character is a valid bare key name or not. 31 """ 32 return self in self.BARE 33 34 @lru_cache(maxsize=None) 35 def is_kv_sep(self): # type: () -> bool 36 """ 37 Whether the character is a valid key/value separator ot not. 38 """ 39 return self in self.KV 40 41 @lru_cache(maxsize=None) 42 def is_int_float_char(self): # type: () -> bool 43 """ 44 Whether the character if a valid integer or float value character or not. 45 """ 46 return self in self.NUMBER 47 48 @lru_cache(maxsize=None) 49 def is_ws(self): # type: () -> bool 50 """ 51 Whether the character is a whitespace character or not. 52 """ 53 return self in self.WS 54 55 @lru_cache(maxsize=None) 56 def is_nl(self): # type: () -> bool 57 """ 58 Whether the character is a new line character or not. 59 """ 60 return self in self.NL 61 62 @lru_cache(maxsize=None) 63 def is_spaces(self): # type: () -> bool 64 """ 65 Whether the character is a space or not 66 """ 67 return self in self.SPACES 68