from__future__importannotationsimportrefromhashlibimportblake2bfromioimportBytesIOfromsysimportbyteorderfromtypingimportTYPE_CHECKING,UnionifTYPE_CHECKING:# pragma: no coverfrom_typeshedimportReadableBuffer
[docs]defensure_int64(i:int)->int:"""ensure the integer in PostgreSQL advisory lock's range (Signed INT64) * max of signed int64: ``2**63-1`` (``+0x7FFF_FFFF_FFFF_FFFF``) * min of signed int64: ``-2**63`` (``-0x8000_0000_0000_0000``) Returns: Signed int64 key """## no force convert UINT greater than 2**63-1 to SINT# if i > 0x7FFF_FFFF_FFFF_FFFF:# return int.from_bytes(i.to_bytes(8, byteorder, signed=False), byteorder, signed=True)ifnotisinstance(i,int):raiseTypeError(f"int type expected, but actual type is {type(i)}")ifi>0x7FFF_FFFF_FFFF_FFFF:raiseOverflowError("int too big")ifi<-0x8000_0000_0000_0000:raiseOverflowError("int too small")returni
[docs]defcamel_case(s:str)->str:"""Convert string into camel case. Args: s: String to convert Returns: Camel case string. """s=re.sub(r"\w[\s\W]+\w","",s)ifnots:returnsreturnlower_case(s[0])+re.sub(r"[\-_\.\s]([a-z])",lambdax:upper_case(str(x.group(1))),s[1:])
[docs]deflower_case(s:str)->str:"""Convert string into lower case. Args: s: String to convert Returns: Lowercase case string. """returns.lower()
[docs]defupper_case(s:str)->str:"""Convert string into upper case. Args: s: String to convert Returns: Uppercase case string. """returns.upper()
[docs]defcapital_case(s:str)->str:"""Convert string into capital case. First letters will be uppercase. Args: s: String to convert Returns: Capital case string. """ifnots:returnsreturnupper_case(s[0])+s[1:]
[docs]defpascal_case(s:str)->str:"""Convert string into pascal case. Args: s: String to convert Returns: Pascal case string. """returncapital_case(camel_case(s))