"""Check if a host is in the Google Chrome HSTS Preload list"""

import functools
import os
import typing

__version__ = "2020.9.29"
__checksum__ = "598603b7530346ce511693a60ae92537ab62fa66528dfd0ad68a711418ec3877"
__all__ = ["in_hsts_preload"]

# fmt: off
_GTLD_INCLUDE_SUBDOMAINS = {b'android', b'app', b'bank', b'chrome', b'dev', b'foo', b'gle', b'gmail', b'google', b'hangout', b'insurance', b'meet', b'new', b'page', b'play', b'search', b'youtube'}  # noqa: E501
_JUMPTABLE = [[(0, 11), (11, 5), None, (16, 57), (73, 26), (99, 12), None, (111, 19), (130, 22), (152, 7), (159, 20), (179, 18), None, (197, 22), (219, 45), (264, 7), (271, 9), (280, 36), (316, 10), (326, 10), (336, 21), None, (357, 50), (407, 8), (415, 9), (424, 19), (443, 13), (456, 14), (470, 14), None, None, (484, 29), (513, 16), (529, 35), (564, 14), (578, 24), (602, 9), None, (611, 25), (636, 20), (656, 8), (664, 13), (677, 10), None, (687, 17), (704, 6), (710, 26), (736, 5), (741, 5), (746, 10), (756, 10), (766, 11), (777, 12), (789, 27), None, (816, 11), (827, 11), (838, 7), (845, 29), (874, 18), (892, 27), (919, 46), (965, 25), (990, 16), (1006, 8), (1014, 5), (1019, 22), (1041, 18), None, (1059, 36), (1095, 15), (1110, 8), (1118, 11), None, (1129, 5), (1134, 16), (1150, 14), (1164, 18), None, (1182, 14), (1196, 18), (1214, 48), (1262, 19), (1281, 5), (1286, 46), (1332, 14), (1346, 14), (1360, 20), None, (1380, 10), (1390, 13), (1403, 10), (1413, 19), None, (1432, 13), (1445, 19), (1464, 5), (1469, 4), (1473, 22), (1495, 10), (1505, 7), (1512, 14), (1526, 21), (1547, 11), (1558, 10), (1568, 12), (1580, 32), None, (1612, 10), (1622, 14), (1636, 12), (1648, 45), (1693, 15), None, (1708, 11), (1719, 23), (1742, 21), (1763, 26), (1789, 6), (1795, 6), (1801, 7), (1808, 5), (1813, 20), (1833, 23), (1856, 24), (1880, 13), (1893, 15), (1908, 19), (1927, 6), (1933, 61), (1994, 44), (2038, 12), (2050, 23), (2073, 16), (2089, 38), (2127, 6), (2133, 12), (2145, 44), (2189, 6), (2195, 41), (2236, 13), (2249, 23), (2272, 30), (2302, 16), (2318, 8), (2326, 15), (2341, 12), (2353, 19), (2372, 21), (2393, 15), None, (2408, 35), (2443, 21), (2464, 17), (2481, 19), (2500, 26), (2526, 5), (2531, 37), (2568, 26), (2594, 16), (2610, 10), (2620, 17), (2637, 23), (2660, 14), (2674, 17), (2691, 8), (2699, 4), (2703, 7), (2710, 29), (2739, 6), (2745, 18), (2763, 27), (2790, 20), (2810, 17), (2827, 19), (2846, 12), (2858, 40), (2898, 40), (2938, 12), (2950, 48), (2998, 25), (3023, 12), None, (3035, 8), (3043, 20), (3063, 19), (3082, 6), (3088, 23), None, (3111, 30), (3141, 33), (3174, 14), (3188, 12), (3200, 27), None, (3227, 26), (3253, 41), (3294, 50), (3344, 15), (3359, 20), (3379, 15), (3394, 21), (3415, 32), (3447, 24), (3471, 20), (3491, 13), (3504, 60), (3564, 19), (3583, 9), (3592, 12), (3604, 12), (3616, 11), (3627, 10), (3637, 48), (3685, 32), None, (3717, 25), (3742, 12), None, (3754, 8), (3762, 8), (3770, 7), None, (3777, 25), (3802, 17), None, (3819, 21), (3840, 35), (3875, 12), (3887, 10), (3897, 36), (3933, 20), (3953, 22), (3975, 23), (3998, 19), (4017, 12), (4029, 5), (4034, 30), (4064, 24), (4088, 14), (4102, 14), (4116, 47), (4163, 46), None, None, (4209, 51), (4260, 42), None, (4302, 14), None, (4316, 15), (4331, 8), (4339, 21), (4360, 6), (4366, 16), (4382, 17)], [(4399, 6384), (10783, 6864), (17647, 7203), (24850, 6155), (31005, 6437), (37442, 6221), (43663, 7069), (50732, 6418), (57150, 6930), (64080, 6214), (70294, 7294), (77588, 6574), (84162, 6882), (91044, 7307), (98351, 6627), (104978, 6887), (111865, 7208), (119073, 6010), (125083, 6338), (131421, 6630), (138051, 7042), (145093, 6644), (151737, 7116), (158853, 6218), (165071, 6495), (171566, 6756), (178322, 6745), (185067, 7107), (192174, 6330), (198504, 6855), (205359, 6947), (212306, 6603), (218909, 6637), (225546, 7101), (232647, 6311), (238958, 6912), (245870, 6310), (252180, 7209), (259389, 6866), (266255, 7034), (273289, 7664), (280953, 6501), (287454, 6487), (293941, 6274), (300215, 6446), (306661, 6299), (312960, 6515), (319475, 7139), (326614, 6491), (333105, 6008), (339113, 6513), (345626, 6746), (352372, 6726), (359098, 6882), (365980, 7002), (372982, 6932), (379914, 6974), (386888, 6106), (392994, 7036), (400030, 5952), (405982, 6781), (412763, 6549), (419312, 6445), (425757, 6960), (432717, 6738), (439455, 6809), (446264, 6353), (452617, 7244), (459861, 6915), (466776, 6899), (473675, 6602), (480277, 6654), (486931, 5775), (492706, 7126), (499832, 7149), (506981, 7198), (514179, 6107), (520286, 7300), (527586, 7099), (534685, 6204), (540889, 6941), (547830, 5861), (553691, 6520), (560211, 6814), (567025, 6554), (573579, 6503), (580082, 6758), (586840, 6715), (593555, 6923), (600478, 6825), (607303, 7423), (614726, 6101), (620827, 6407), (627234, 6654), (633888, 6593), (640481, 7220), (647701, 7164), (654865, 6516), (661381, 6342), (667723, 6321), (674044, 6400), (680444, 6804), (687248, 6315), (693563, 6622), (700185, 6332), (706517, 6965), (713482, 6868), (720350, 7178), (727528, 8203), (735731, 7233), (742964, 7109), (750073, 6688), (756761, 6467), (763228, 6785), (770013, 7016), (777029, 6818), (783847, 6315), (790162, 6465), (796627, 6484), (803111, 7241), (810352, 7042), (817394, 7118), (824512, 7106), (831618, 7076), (838694, 7942), (846636, 6519), (853155, 5956), (859111, 7075), (866186, 6671), (872857, 8222), (881079, 7251), (888330, 6175), (894505, 6912), (901417, 6965), (908382, 6396), (914778, 6910), (921688, 6261), (927949, 6845), (934794, 6609), (941403, 6651), (948054, 6684), (954738, 7370), (962108, 6406), (968514, 6368), (974882, 6759), (981641, 6660), (988301, 6671), (994972, 6957), (1001929, 6408), (1008337, 7283), (1015620, 6706), (1022326, 6866), (1029192, 7098), (1036290, 6578), (1042868, 6818), (1049686, 6747), (1056433, 6548), (1062981, 6608), (1069589, 6394), (1075983, 6116), (1082099, 6377), (1088476, 6799), (1095275, 7349), (1102624, 6253), (1108877, 6689), (1115566, 7007), (1122573, 6423), (1128996, 6421), (1135417, 7090), (1142507, 6660), (1149167, 6068), (1155235, 6636), (1161871, 7840), (1169711, 6257), (1175968, 6446), (1182414, 6948), (1189362, 6496), (1195858, 6822), (1202680, 6508), (1209188, 6171), (1215359, 7671), (1223030, 6868), (1229898, 6660), (1236558, 7109), (1243667, 7511), (1251178, 7458), (1258636, 6230), (1264866, 7144), (1272010, 6415), (1278425, 6680), (1285105, 6959), (1292064, 6387), (1298451, 7016), (1305467, 7192), (1312659, 6709), (1319368, 6817), (1326185, 6584), (1332769, 6564), (1339333, 6832), (1346165, 6428), (1352593, 6861), (1359454, 6182), (1365636, 7137), (1372773, 6966), (1379739, 6692), (1386431, 7204), (1393635, 5911), (1399546, 6830), (1406376, 6614), (1412990, 6961), (1419951, 6952), (1426903, 7170), (1434073, 6779), (1440852, 6975), (1447827, 6971), (1454798, 6490), (1461288, 6704), (1467992, 6757), (1474749, 6738), (1481487, 6549), (1488036, 6652), (1494688, 6172), (1500860, 7634), (1508494, 6775), (1515269, 6421), (1521690, 6734), (1528424, 6846), (1535270, 6065), (1541335, 6943), (1548278, 6644), (1554922, 7606), (1562528, 6572), (1569100, 6174), (1575274, 7121), (1582395, 6478), (1588873, 7294), (1596167, 6357), (1602524, 6461), (1608985, 5864), (1614849, 6846), (1621695, 6597), (1628292, 6964), (1635256, 6459), (1641715, 6673), (1648388, 6616), (1655004, 7192), (1662196, 6514), (1668710, 5950), (1674660, 6708), (1681368, 6404), (1687772, 6842), (1694614, 7089), (1701703, 7208), (1708911, 6348), (1715259, 6369), (1721628, 6795)], [(1728423, 716), (1729139, 669), (1729808, 665), (1730473, 757), (1731230, 553), (1731783, 670), (1732453, 698), (1733151, 836), (1733987, 640), (1734627, 667), (1735294, 536), (1735830, 574), (1736404, 792), (1737196, 853), (1738049, 1020), (1739069, 850), (1739919, 1242), (1741161, 669), (1741830, 875), (1742705, 696), (1743401, 757), (1744158, 765), (1744923, 865), (1745788, 731), (1746519, 717), (1747236, 695), (1747931, 955), (1748886, 1131), (1750017, 807), (1750824, 734), (1751558, 922), (1752480, 787), (1753267, 586), (1753853, 733), (1754586, 748), (1755334, 800), (1756134, 678), (1756812, 746), (1757558, 724), (1758282, 1119), (1759401, 695), (1760096, 812), (1760908, 748), (1761656, 719), (1762375, 728), (1763103, 396), (1763499, 942), (1764441, 870), (1765311, 735), (1766046, 592), (1766638, 834), (1767472, 692), (1768164, 780), (1768944, 1012), (1769956, 944), (1770900, 558), (1771458, 661), (1772119, 550), (1772669, 578), (1773247, 771), (1774018, 772), (1774790, 776), (1775566, 1054), (1776620, 927), (1777547, 725), (1778272, 719), (1778991, 767), (1779758, 494), (1780252, 595), (1780847, 592), (1781439, 692), (1782131, 877), (1783008, 596), (1783604, 725), (1784329, 650), (1784979, 685), (1785664, 573), (1786237, 711), (1786948, 787), (1787735, 496), (1788231, 814), (1789045, 629), (1789674, 828), (1790502, 646), (1791148, 603), (1791751, 425), (1792176, 597), (1792773, 746), (1793519, 804), (1794323, 782), (1795105, 853), (1795958, 1092), (1797050, 839), (1797889, 856), (1798745, 725), (1799470, 436), (1799906, 955), (1800861, 857), (1801718, 580), (1802298, 671), (1802969, 728), (1803697, 885), (1804582, 903), (1805485, 571), (1806056, 632), (1806688, 772), (1807460, 419), (1807879, 466), (1808345, 924), (1809269, 963), (1810232, 851), (1811083, 793), (1811876, 654), (1812530, 792), (1813322, 672), (1813994, 699), (1814693, 709), (1815402, 505), (1815907, 722), (1816629, 710), (1817339, 930), (1818269, 700), (1818969, 804), (1819773, 483), (1820256, 691), (1820947, 780), (1821727, 835), (1822562, 926), (1823488, 806), (1824294, 942), (1825236, 802), (1826038, 524), (1826562, 815), (1827377, 651), (1828028, 803), (1828831, 779), (1829610, 737), (1830347, 681), (1831028, 635), (1831663, 673), (1832336, 621), (1832957, 674), (1833631, 694), (1834325, 648), (1834973, 494), (1835467, 603), (1836070, 661), (1836731, 597), (1837328, 729), (1838057, 594), (1838651, 773), (1839424, 514), (1839938, 550), (1840488, 701), (1841189, 642), (1841831, 657), (1842488, 639), (1843127, 870), (1843997, 610), (1844607, 622), (1845229, 903), (1846132, 870), (1847002, 583), (1847585, 695), (1848280, 873), (1849153, 659), (1849812, 692), (1850504, 455), (1850959, 609), (1851568, 681), (1852249, 810), (1853059, 619), (1853678, 932), (1854610, 760), (1855370, 807), (1856177, 721), (1856898, 668), (1857566, 582), (1858148, 664), (1858812, 706), (1859518, 1412), (1860930, 575), (1861505, 662), (1862167, 650), (1862817, 1027), (1863844, 800), (1864644, 798), (1865442, 546), (1865988, 609), (1866597, 823), (1867420, 601), (1868021, 589), (1868610, 814), (1869424, 720), (1870144, 892), (1871036, 810), (1871846, 764), (1872610, 710), (1873320, 868), (1874188, 637), (1874825, 947), (1875772, 662), (1876434, 819), (1877253, 630), (1877883, 742), (1878625, 510), (1879135, 828), (1879963, 826), (1880789, 665), (1881454, 916), (1882370, 787), (1883157, 868), (1884025, 954), (1884979, 1077), (1886056, 887), (1886943, 669), (1887612, 895), (1888507, 731), (1889238, 533), (1889771, 443), (1890214, 794), (1891008, 823), (1891831, 455), (1892286, 1026), (1893312, 513), (1893825, 778), (1894603, 881), (1895484, 792), (1896276, 806), (1897082, 696), (1897778, 826), (1898604, 751), (1899355, 784), (1900139, 607), (1900746, 579), (1901325, 445), (1901770, 666), (1902436, 484), (1902920, 816), (1903736, 880), (1904616, 764), (1905380, 718), (1906098, 658), (1906756, 604), (1907360, 848), (1908208, 495), (1908703, 606), (1909309, 780), (1910089, 494), (1910583, 870), (1911453, 2090), (1913543, 548), (1914091, 707), (1914798, 890), (1915688, 912), (1916600, 539)], [(1917139, 48), None, (1917187, 35), (1917222, 42), None, None, None, None, None, None, None, None, None, None, None, None, None, (1917264, 42), None, (1917306, 25), (1917331, 44), (1917375, 22), (1917397, 18), None, None, None, None, (1917415, 26), None, None, None, None, (1917441, 21), (1917462, 25), None, None, (1917487, 26), None, None, None, None, (1917513, 44), (1917557, 21), (1917578, 23), None, None, None, None, (1917601, 48), None, None, None, None, None, (1917649, 31), None, None, None, None, (1917680, 42), None, (1917722, 22), None, (1917744, 21), None, (1917765, 26), (1917791, 42), None, None, (1917833, 77), None, None, None, None, None, (1917910, 21), (1917931, 21), None, None, (1917952, 34), (1917986, 42), None, None, None, (1918028, 25), None, None, (1918053, 21), None, None, None, None, None, (1918074, 24), (1918098, 21), None, None, (1918119, 26), None, (1918145, 18), None, (1918163, 54), None, None, None, None, None, None, (1918217, 26), None, (1918243, 19), None, (1918262, 20), None, None, (1918282, 42), (1918324, 42), (1918366, 17), None, (1918383, 26), None, (1918409, 26), None, None, None, (1918435, 26), (1918461, 20), (1918481, 26), None, (1918507, 42), (1918549, 63), None, None, None, (1918612, 40), (1918652, 48), None, None, None, (1918700, 47), None, None, None, None, None, None, None, (1918747, 42), None, (1918789, 55), None, (1918844, 9), None, (1918853, 21), (1918874, 42), None, None, (1918916, 42), (1918958, 82), None, None, (1919040, 42), None, None, None, None, None, None, None, None, None, (1919082, 42), (1919124, 21), (1919145, 21), None, (1919166, 42), (1919208, 25), None, None, (1919233, 21), (1919254, 42), None, None, (1919296, 21), (1919317, 19), (1919336, 26), None, None, None, (1919362, 21), None, None, (1919383, 38), None, (1919421, 22), (1919443, 21), (1919464, 21), None, None, (1919485, 63), None, (1919548, 21), (1919569, 42), None, (1919611, 17), None, None, None, None, (1919628, 21), (1919649, 21), None, None, (1919670, 21), None, None, (1919691, 21), None, (1919712, 26), None, (1919738, 50), None, None, None, (1919788, 50), (1919838, 26), (1919864, 21), (1919885, 21), (1919906, 19), None, (1919925, 35), (1919960, 26), (1919986, 23), (1920009, 21), (1920030, 42), None, None, None, None, None, None, (1920072, 21), None, None, None, (1920093, 21), None, None, (1920114, 90), None, (1920204, 239), (1920443, 38), None, None, None, None]]  # noqa: E501
_CRC8_TABLE = [
    0x00, 0x07, 0x0e, 0x09, 0x1c, 0x1b, 0x12, 0x15,
    0x38, 0x3f, 0x36, 0x31, 0x24, 0x23, 0x2a, 0x2d,
    0x70, 0x77, 0x7e, 0x79, 0x6c, 0x6b, 0x62, 0x65,
    0x48, 0x4f, 0x46, 0x41, 0x54, 0x53, 0x5a, 0x5d,
    0xe0, 0xe7, 0xee, 0xe9, 0xfc, 0xfb, 0xf2, 0xf5,
    0xd8, 0xdf, 0xd6, 0xd1, 0xc4, 0xc3, 0xca, 0xcd,
    0x90, 0x97, 0x9e, 0x99, 0x8c, 0x8b, 0x82, 0x85,
    0xa8, 0xaf, 0xa6, 0xa1, 0xb4, 0xb3, 0xba, 0xbd,
    0xc7, 0xc0, 0xc9, 0xce, 0xdb, 0xdc, 0xd5, 0xd2,
    0xff, 0xf8, 0xf1, 0xf6, 0xe3, 0xe4, 0xed, 0xea,
    0xb7, 0xb0, 0xb9, 0xbe, 0xab, 0xac, 0xa5, 0xa2,
    0x8f, 0x88, 0x81, 0x86, 0x93, 0x94, 0x9d, 0x9a,
    0x27, 0x20, 0x29, 0x2e, 0x3b, 0x3c, 0x35, 0x32,
    0x1f, 0x18, 0x11, 0x16, 0x03, 0x04, 0x0d, 0x0a,
    0x57, 0x50, 0x59, 0x5e, 0x4b, 0x4c, 0x45, 0x42,
    0x6f, 0x68, 0x61, 0x66, 0x73, 0x74, 0x7d, 0x7a,
    0x89, 0x8e, 0x87, 0x80, 0x95, 0x92, 0x9b, 0x9c,
    0xb1, 0xb6, 0xbf, 0xb8, 0xad, 0xaa, 0xa3, 0xa4,
    0xf9, 0xfe, 0xf7, 0xf0, 0xe5, 0xe2, 0xeb, 0xec,
    0xc1, 0xc6, 0xcf, 0xc8, 0xdd, 0xda, 0xd3, 0xd4,
    0x69, 0x6e, 0x67, 0x60, 0x75, 0x72, 0x7b, 0x7c,
    0x51, 0x56, 0x5f, 0x58, 0x4d, 0x4a, 0x43, 0x44,
    0x19, 0x1e, 0x17, 0x10, 0x05, 0x02, 0x0b, 0x0c,
    0x21, 0x26, 0x2f, 0x28, 0x3d, 0x3a, 0x33, 0x34,
    0x4e, 0x49, 0x40, 0x47, 0x52, 0x55, 0x5c, 0x5b,
    0x76, 0x71, 0x78, 0x7f, 0x6a, 0x6d, 0x64, 0x63,
    0x3e, 0x39, 0x30, 0x37, 0x22, 0x25, 0x2c, 0x2b,
    0x06, 0x01, 0x08, 0x0f, 0x1a, 0x1d, 0x14, 0x13,
    0xae, 0xa9, 0xa0, 0xa7, 0xb2, 0xb5, 0xbc, 0xbb,
    0x96, 0x91, 0x98, 0x9f, 0x8a, 0x8d, 0x84, 0x83,
    0xde, 0xd9, 0xd0, 0xd7, 0xc2, 0xc5, 0xcc, 0xcb,
    0xe6, 0xe1, 0xe8, 0xef, 0xfa, 0xfd, 0xf4, 0xf3
]
# fmt: on

_IS_LEAF = 0x80
_INCLUDE_SUBDOMAINS = 0x40


try:
    from importlib.resources import open_binary

    def open_pkg_binary(path: str) -> typing.BinaryIO:
        return open_binary("hstspreload", path)


except ImportError:

    def open_pkg_binary(path: str) -> typing.BinaryIO:
        return open(
            os.path.join(os.path.dirname(os.path.abspath(__file__)), path),
            "rb",
        )


@functools.lru_cache(maxsize=1024)
def in_hsts_preload(host: typing.AnyStr) -> bool:
    """Determines if an IDNA-encoded host is on the HSTS preload list"""

    if isinstance(host, str):
        host = host.encode("ascii")
    labels = host.lower().split(b".")

    # Fast-branch for gTLDs that are registered to preload all sub-domains.
    if labels[-1] in _GTLD_INCLUDE_SUBDOMAINS:
        return True

    with open_pkg_binary("hstspreload.bin") as f:
        for layer, label in enumerate(labels[::-1]):
            # None of our layers are greater than 4 deep.
            if layer > 3:
                return False

            # Read the jump table for the layer and label
            jump_info = _JUMPTABLE[layer][_crc8(label)]
            if jump_info is None:
                # No entry: host is not preloaded
                return False

            # Read the set of entries for that layer and label
            f.seek(jump_info[0])
            data = bytearray(jump_info[1])
            f.readinto(data)

            for is_leaf, include_subdomains, ent_label in _iter_entries(data):
                # We found a potential leaf
                if is_leaf:
                    if ent_label == host:
                        return True
                    if include_subdomains and host.endswith(b"." + ent_label):
                        return True

                # Continue traversing as we're not at a leaf.
                elif label == ent_label:
                    break
            else:
                return False
    return False


def _iter_entries(data: bytes) -> typing.Iterable[typing.Tuple[int, int, bytes]]:
    while data:
        flags = data[0]
        size = data[1]
        label = bytes(data[2 : 2 + size])
        yield (flags & _IS_LEAF, flags & _INCLUDE_SUBDOMAINS, label)
        data = data[2 + size :]


def _crc8(value: bytes) -> int:
    # CRC8 reference implementation: https://github.com/niccokunzmann/crc8
    checksum = 0x00
    for byte in value:
        checksum = _CRC8_TABLE[checksum ^ byte]
    return checksum

179b99e91557e8e5ca56664999b7472bea7df153
<mask token>


@functools.lru_cache(maxsize=1024)
def in_hsts_preload(host: typing.AnyStr) ->bool:
    """Determines if an IDNA-encoded host is on the HSTS preload list"""
    if isinstance(host, str):
        host = host.encode('ascii')
    labels = host.lower().split(b'.')
    if labels[-1] in _GTLD_INCLUDE_SUBDOMAINS:
        return True
    with open_pkg_binary('hstspreload.bin') as f:
        for layer, label in enumerate(labels[::-1]):
            if layer > 3:
                return False
            jump_info = _JUMPTABLE[layer][_crc8(label)]
            if jump_info is None:
                return False
            f.seek(jump_info[0])
            data = bytearray(jump_info[1])
            f.readinto(data)
            for is_leaf, include_subdomains, ent_label in _iter_entries(data):
                if is_leaf:
                    if ent_label == host:
                        return True
                    if include_subdomains and host.endswith(b'.' + ent_label):
                        return True
                elif label == ent_label:
                    break
            else:
                return False
    return False


def _iter_entries(data: bytes) ->typing.Iterable[typing.Tuple[int, int, bytes]
    ]:
    while data:
        flags = data[0]
        size = data[1]
        label = bytes(data[2:2 + size])
        yield flags & _IS_LEAF, flags & _INCLUDE_SUBDOMAINS, label
        data = data[2 + size:]


def _crc8(value: bytes) ->int:
    checksum = 0
    for byte in value:
        checksum = _CRC8_TABLE[checksum ^ byte]
    return checksum

<mask token>
try:
    from importlib.resources import open_binary

    def open_pkg_binary(path: str) ->typing.BinaryIO:
        return open_binary('hstspreload', path)
except ImportError:

    def open_pkg_binary(path: str) ->typing.BinaryIO:
        return open(os.path.join(os.path.dirname(os.path.abspath(__file__)),
            path), 'rb')


@functools.lru_cache(maxsize=1024)
def in_hsts_preload(host: typing.AnyStr) ->bool:
    """Determines if an IDNA-encoded host is on the HSTS preload list"""
    if isinstance(host, str):
        host = host.encode('ascii')
    labels = host.lower().split(b'.')
    if labels[-1] in _GTLD_INCLUDE_SUBDOMAINS:
        return True
    with open_pkg_binary('hstspreload.bin') as f:
        for layer, label in enumerate(labels[::-1]):
            if layer > 3:
                return False
            jump_info = _JUMPTABLE[layer][_crc8(label)]
            if jump_info is None:
                return False
            f.seek(jump_info[0])
            data = bytearray(jump_info[1])
            f.readinto(data)
            for is_leaf, include_subdomains, ent_label in _iter_entries(data):
                if is_leaf:
                    if ent_label == host:
                        return True
                    if include_subdomains and host.endswith(b'.' + ent_label):
                        return True
                elif label == ent_label:
                    break
            else:
                return False
    return False


def _iter_entries(data: bytes) ->typing.Iterable[typing.Tuple[int, int, bytes]
    ]:
    while data:
        flags = data[0]
        size = data[1]
        label = bytes(data[2:2 + size])
        yield flags & _IS_LEAF, flags & _INCLUDE_SUBDOMAINS, label
        data = data[2 + size:]


def _crc8(value: bytes) ->int:
    checksum = 0
    for byte in value:
        checksum = _CRC8_TABLE[checksum ^ byte]
    return checksum

<mask token>
__version__ = '2020.9.29'
__checksum__ = (
    '598603b7530346ce511693a60ae92537ab62fa66528dfd0ad68a711418ec3877')
__all__ = ['in_hsts_preload']
_GTLD_INCLUDE_SUBDOMAINS = {b'android', b'app', b'bank', b'chrome', b'dev',
    b'foo', b'gle', b'gmail', b'google', b'hangout', b'insurance', b'meet',
    b'new', b'page', b'play', b'search', b'youtube'}
_JUMPTABLE = [[(0, 11), (11, 5), None, (16, 57), (73, 26), (99, 12), None,
    (111, 19), (130, 22), (152, 7), (159, 20), (179, 18), None, (197, 22),
    (219, 45), (264, 7), (271, 9), (280, 36), (316, 10), (326, 10), (336, 
    21), None, (357, 50), (407, 8), (415, 9), (424, 19), (443, 13), (456, 
    14), (470, 14), None, None, (484, 29), (513, 16), (529, 35), (564, 14),
    (578, 24), (602, 9), None, (611, 25), (636, 20), (656, 8), (664, 13), (
    677, 10), None, (687, 17), (704, 6), (710, 26), (736, 5), (741, 5), (
    746, 10), (756, 10), (766, 11), (777, 12), (789, 27), None, (816, 11),
    (827, 11), (838, 7), (845, 29), (874, 18), (892, 27), (919, 46), (965, 
    25), (990, 16), (1006, 8), (1014, 5), (1019, 22), (1041, 18), None, (
    1059, 36), (1095, 15), (1110, 8), (1118, 11), None, (1129, 5), (1134, 
    16), (1150, 14), (1164, 18), None, (1182, 14), (1196, 18), (1214, 48),
    (1262, 19), (1281, 5), (1286, 46), (1332, 14), (1346, 14), (1360, 20),
    None, (1380, 10), (1390, 13), (1403, 10), (1413, 19), None, (1432, 13),
    (1445, 19), (1464, 5), (1469, 4), (1473, 22), (1495, 10), (1505, 7), (
    1512, 14), (1526, 21), (1547, 11), (1558, 10), (1568, 12), (1580, 32),
    None, (1612, 10), (1622, 14), (1636, 12), (1648, 45), (1693, 15), None,
    (1708, 11), (1719, 23), (1742, 21), (1763, 26), (1789, 6), (1795, 6), (
    1801, 7), (1808, 5), (1813, 20), (1833, 23), (1856, 24), (1880, 13), (
    1893, 15), (1908, 19), (1927, 6), (1933, 61), (1994, 44), (2038, 12), (
    2050, 23), (2073, 16), (2089, 38), (2127, 6), (2133, 12), (2145, 44), (
    2189, 6), (2195, 41), (2236, 13), (2249, 23), (2272, 30), (2302, 16), (
    2318, 8), (2326, 15), (2341, 12), (2353, 19), (2372, 21), (2393, 15),
    None, (2408, 35), (2443, 21), (2464, 17), (2481, 19), (2500, 26), (2526,
    5), (2531, 37), (2568, 26), (2594, 16), (2610, 10), (2620, 17), (2637, 
    23), (2660, 14), (2674, 17), (2691, 8), (2699, 4), (2703, 7), (2710, 29
    ), (2739, 6), (2745, 18), (2763, 27), (2790, 20), (2810, 17), (2827, 19
    ), (2846, 12), (2858, 40), (2898, 40), (2938, 12), (2950, 48), (2998, 
    25), (3023, 12), None, (3035, 8), (3043, 20), (3063, 19), (3082, 6), (
    3088, 23), None, (3111, 30), (3141, 33), (3174, 14), (3188, 12), (3200,
    27), None, (3227, 26), (3253, 41), (3294, 50), (3344, 15), (3359, 20),
    (3379, 15), (3394, 21), (3415, 32), (3447, 24), (3471, 20), (3491, 13),
    (3504, 60), (3564, 19), (3583, 9), (3592, 12), (3604, 12), (3616, 11),
    (3627, 10), (3637, 48), (3685, 32), None, (3717, 25), (3742, 12), None,
    (3754, 8), (3762, 8), (3770, 7), None, (3777, 25), (3802, 17), None, (
    3819, 21), (3840, 35), (3875, 12), (3887, 10), (3897, 36), (3933, 20),
    (3953, 22), (3975, 23), (3998, 19), (4017, 12), (4029, 5), (4034, 30),
    (4064, 24), (4088, 14), (4102, 14), (4116, 47), (4163, 46), None, None,
    (4209, 51), (4260, 42), None, (4302, 14), None, (4316, 15), (4331, 8),
    (4339, 21), (4360, 6), (4366, 16), (4382, 17)], [(4399, 6384), (10783, 
    6864), (17647, 7203), (24850, 6155), (31005, 6437), (37442, 6221), (
    43663, 7069), (50732, 6418), (57150, 6930), (64080, 6214), (70294, 7294
    ), (77588, 6574), (84162, 6882), (91044, 7307), (98351, 6627), (104978,
    6887), (111865, 7208), (119073, 6010), (125083, 6338), (131421, 6630),
    (138051, 7042), (145093, 6644), (151737, 7116), (158853, 6218), (165071,
    6495), (171566, 6756), (178322, 6745), (185067, 7107), (192174, 6330),
    (198504, 6855), (205359, 6947), (212306, 6603), (218909, 6637), (225546,
    7101), (232647, 6311), (238958, 6912), (245870, 6310), (252180, 7209),
    (259389, 6866), (266255, 7034), (273289, 7664), (280953, 6501), (287454,
    6487), (293941, 6274), (300215, 6446), (306661, 6299), (312960, 6515),
    (319475, 7139), (326614, 6491), (333105, 6008), (339113, 6513), (345626,
    6746), (352372, 6726), (359098, 6882), (365980, 7002), (372982, 6932),
    (379914, 6974), (386888, 6106), (392994, 7036), (400030, 5952), (405982,
    6781), (412763, 6549), (419312, 6445), (425757, 6960), (432717, 6738),
    (439455, 6809), (446264, 6353), (452617, 7244), (459861, 6915), (466776,
    6899), (473675, 6602), (480277, 6654), (486931, 5775), (492706, 7126),
    (499832, 7149), (506981, 7198), (514179, 6107), (520286, 7300), (527586,
    7099), (534685, 6204), (540889, 6941), (547830, 5861), (553691, 6520),
    (560211, 6814), (567025, 6554), (573579, 6503), (580082, 6758), (586840,
    6715), (593555, 6923), (600478, 6825), (607303, 7423), (614726, 6101),
    (620827, 6407), (627234, 6654), (633888, 6593), (640481, 7220), (647701,
    7164), (654865, 6516), (661381, 6342), (667723, 6321), (674044, 6400),
    (680444, 6804), (687248, 6315), (693563, 6622), (700185, 6332), (706517,
    6965), (713482, 6868), (720350, 7178), (727528, 8203), (735731, 7233),
    (742964, 7109), (750073, 6688), (756761, 6467), (763228, 6785), (770013,
    7016), (777029, 6818), (783847, 6315), (790162, 6465), (796627, 6484),
    (803111, 7241), (810352, 7042), (817394, 7118), (824512, 7106), (831618,
    7076), (838694, 7942), (846636, 6519), (853155, 5956), (859111, 7075),
    (866186, 6671), (872857, 8222), (881079, 7251), (888330, 6175), (894505,
    6912), (901417, 6965), (908382, 6396), (914778, 6910), (921688, 6261),
    (927949, 6845), (934794, 6609), (941403, 6651), (948054, 6684), (954738,
    7370), (962108, 6406), (968514, 6368), (974882, 6759), (981641, 6660),
    (988301, 6671), (994972, 6957), (1001929, 6408), (1008337, 7283), (
    1015620, 6706), (1022326, 6866), (1029192, 7098), (1036290, 6578), (
    1042868, 6818), (1049686, 6747), (1056433, 6548), (1062981, 6608), (
    1069589, 6394), (1075983, 6116), (1082099, 6377), (1088476, 6799), (
    1095275, 7349), (1102624, 6253), (1108877, 6689), (1115566, 7007), (
    1122573, 6423), (1128996, 6421), (1135417, 7090), (1142507, 6660), (
    1149167, 6068), (1155235, 6636), (1161871, 7840), (1169711, 6257), (
    1175968, 6446), (1182414, 6948), (1189362, 6496), (1195858, 6822), (
    1202680, 6508), (1209188, 6171), (1215359, 7671), (1223030, 6868), (
    1229898, 6660), (1236558, 7109), (1243667, 7511), (1251178, 7458), (
    1258636, 6230), (1264866, 7144), (1272010, 6415), (1278425, 6680), (
    1285105, 6959), (1292064, 6387), (1298451, 7016), (1305467, 7192), (
    1312659, 6709), (1319368, 6817), (1326185, 6584), (1332769, 6564), (
    1339333, 6832), (1346165, 6428), (1352593, 6861), (1359454, 6182), (
    1365636, 7137), (1372773, 6966), (1379739, 6692), (1386431, 7204), (
    1393635, 5911), (1399546, 6830), (1406376, 6614), (1412990, 6961), (
    1419951, 6952), (1426903, 7170), (1434073, 6779), (1440852, 6975), (
    1447827, 6971), (1454798, 6490), (1461288, 6704), (1467992, 6757), (
    1474749, 6738), (1481487, 6549), (1488036, 6652), (1494688, 6172), (
    1500860, 7634), (1508494, 6775), (1515269, 6421), (1521690, 6734), (
    1528424, 6846), (1535270, 6065), (1541335, 6943), (1548278, 6644), (
    1554922, 7606), (1562528, 6572), (1569100, 6174), (1575274, 7121), (
    1582395, 6478), (1588873, 7294), (1596167, 6357), (1602524, 6461), (
    1608985, 5864), (1614849, 6846), (1621695, 6597), (1628292, 6964), (
    1635256, 6459), (1641715, 6673), (1648388, 6616), (1655004, 7192), (
    1662196, 6514), (1668710, 5950), (1674660, 6708), (1681368, 6404), (
    1687772, 6842), (1694614, 7089), (1701703, 7208), (1708911, 6348), (
    1715259, 6369), (1721628, 6795)], [(1728423, 716), (1729139, 669), (
    1729808, 665), (1730473, 757), (1731230, 553), (1731783, 670), (1732453,
    698), (1733151, 836), (1733987, 640), (1734627, 667), (1735294, 536), (
    1735830, 574), (1736404, 792), (1737196, 853), (1738049, 1020), (
    1739069, 850), (1739919, 1242), (1741161, 669), (1741830, 875), (
    1742705, 696), (1743401, 757), (1744158, 765), (1744923, 865), (1745788,
    731), (1746519, 717), (1747236, 695), (1747931, 955), (1748886, 1131),
    (1750017, 807), (1750824, 734), (1751558, 922), (1752480, 787), (
    1753267, 586), (1753853, 733), (1754586, 748), (1755334, 800), (1756134,
    678), (1756812, 746), (1757558, 724), (1758282, 1119), (1759401, 695),
    (1760096, 812), (1760908, 748), (1761656, 719), (1762375, 728), (
    1763103, 396), (1763499, 942), (1764441, 870), (1765311, 735), (1766046,
    592), (1766638, 834), (1767472, 692), (1768164, 780), (1768944, 1012),
    (1769956, 944), (1770900, 558), (1771458, 661), (1772119, 550), (
    1772669, 578), (1773247, 771), (1774018, 772), (1774790, 776), (1775566,
    1054), (1776620, 927), (1777547, 725), (1778272, 719), (1778991, 767),
    (1779758, 494), (1780252, 595), (1780847, 592), (1781439, 692), (
    1782131, 877), (1783008, 596), (1783604, 725), (1784329, 650), (1784979,
    685), (1785664, 573), (1786237, 711), (1786948, 787), (1787735, 496), (
    1788231, 814), (1789045, 629), (1789674, 828), (1790502, 646), (1791148,
    603), (1791751, 425), (1792176, 597), (1792773, 746), (1793519, 804), (
    1794323, 782), (1795105, 853), (1795958, 1092), (1797050, 839), (
    1797889, 856), (1798745, 725), (1799470, 436), (1799906, 955), (1800861,
    857), (1801718, 580), (1802298, 671), (1802969, 728), (1803697, 885), (
    1804582, 903), (1805485, 571), (1806056, 632), (1806688, 772), (1807460,
    419), (1807879, 466), (1808345, 924), (1809269, 963), (1810232, 851), (
    1811083, 793), (1811876, 654), (1812530, 792), (1813322, 672), (1813994,
    699), (1814693, 709), (1815402, 505), (1815907, 722), (1816629, 710), (
    1817339, 930), (1818269, 700), (1818969, 804), (1819773, 483), (1820256,
    691), (1820947, 780), (1821727, 835), (1822562, 926), (1823488, 806), (
    1824294, 942), (1825236, 802), (1826038, 524), (1826562, 815), (1827377,
    651), (1828028, 803), (1828831, 779), (1829610, 737), (1830347, 681), (
    1831028, 635), (1831663, 673), (1832336, 621), (1832957, 674), (1833631,
    694), (1834325, 648), (1834973, 494), (1835467, 603), (1836070, 661), (
    1836731, 597), (1837328, 729), (1838057, 594), (1838651, 773), (1839424,
    514), (1839938, 550), (1840488, 701), (1841189, 642), (1841831, 657), (
    1842488, 639), (1843127, 870), (1843997, 610), (1844607, 622), (1845229,
    903), (1846132, 870), (1847002, 583), (1847585, 695), (1848280, 873), (
    1849153, 659), (1849812, 692), (1850504, 455), (1850959, 609), (1851568,
    681), (1852249, 810), (1853059, 619), (1853678, 932), (1854610, 760), (
    1855370, 807), (1856177, 721), (1856898, 668), (1857566, 582), (1858148,
    664), (1858812, 706), (1859518, 1412), (1860930, 575), (1861505, 662),
    (1862167, 650), (1862817, 1027), (1863844, 800), (1864644, 798), (
    1865442, 546), (1865988, 609), (1866597, 823), (1867420, 601), (1868021,
    589), (1868610, 814), (1869424, 720), (1870144, 892), (1871036, 810), (
    1871846, 764), (1872610, 710), (1873320, 868), (1874188, 637), (1874825,
    947), (1875772, 662), (1876434, 819), (1877253, 630), (1877883, 742), (
    1878625, 510), (1879135, 828), (1879963, 826), (1880789, 665), (1881454,
    916), (1882370, 787), (1883157, 868), (1884025, 954), (1884979, 1077),
    (1886056, 887), (1886943, 669), (1887612, 895), (1888507, 731), (
    1889238, 533), (1889771, 443), (1890214, 794), (1891008, 823), (1891831,
    455), (1892286, 1026), (1893312, 513), (1893825, 778), (1894603, 881),
    (1895484, 792), (1896276, 806), (1897082, 696), (1897778, 826), (
    1898604, 751), (1899355, 784), (1900139, 607), (1900746, 579), (1901325,
    445), (1901770, 666), (1902436, 484), (1902920, 816), (1903736, 880), (
    1904616, 764), (1905380, 718), (1906098, 658), (1906756, 604), (1907360,
    848), (1908208, 495), (1908703, 606), (1909309, 780), (1910089, 494), (
    1910583, 870), (1911453, 2090), (1913543, 548), (1914091, 707), (
    1914798, 890), (1915688, 912), (1916600, 539)], [(1917139, 48), None, (
    1917187, 35), (1917222, 42), None, None, None, None, None, None, None,
    None, None, None, None, None, None, (1917264, 42), None, (1917306, 25),
    (1917331, 44), (1917375, 22), (1917397, 18), None, None, None, None, (
    1917415, 26), None, None, None, None, (1917441, 21), (1917462, 25),
    None, None, (1917487, 26), None, None, None, None, (1917513, 44), (
    1917557, 21), (1917578, 23), None, None, None, None, (1917601, 48),
    None, None, None, None, None, (1917649, 31), None, None, None, None, (
    1917680, 42), None, (1917722, 22), None, (1917744, 21), None, (1917765,
    26), (1917791, 42), None, None, (1917833, 77), None, None, None, None,
    None, (1917910, 21), (1917931, 21), None, None, (1917952, 34), (1917986,
    42), None, None, None, (1918028, 25), None, None, (1918053, 21), None,
    None, None, None, None, (1918074, 24), (1918098, 21), None, None, (
    1918119, 26), None, (1918145, 18), None, (1918163, 54), None, None,
    None, None, None, None, (1918217, 26), None, (1918243, 19), None, (
    1918262, 20), None, None, (1918282, 42), (1918324, 42), (1918366, 17),
    None, (1918383, 26), None, (1918409, 26), None, None, None, (1918435, 
    26), (1918461, 20), (1918481, 26), None, (1918507, 42), (1918549, 63),
    None, None, None, (1918612, 40), (1918652, 48), None, None, None, (
    1918700, 47), None, None, None, None, None, None, None, (1918747, 42),
    None, (1918789, 55), None, (1918844, 9), None, (1918853, 21), (1918874,
    42), None, None, (1918916, 42), (1918958, 82), None, None, (1919040, 42
    ), None, None, None, None, None, None, None, None, None, (1919082, 42),
    (1919124, 21), (1919145, 21), None, (1919166, 42), (1919208, 25), None,
    None, (1919233, 21), (1919254, 42), None, None, (1919296, 21), (1919317,
    19), (1919336, 26), None, None, None, (1919362, 21), None, None, (
    1919383, 38), None, (1919421, 22), (1919443, 21), (1919464, 21), None,
    None, (1919485, 63), None, (1919548, 21), (1919569, 42), None, (1919611,
    17), None, None, None, None, (1919628, 21), (1919649, 21), None, None,
    (1919670, 21), None, None, (1919691, 21), None, (1919712, 26), None, (
    1919738, 50), None, None, None, (1919788, 50), (1919838, 26), (1919864,
    21), (1919885, 21), (1919906, 19), None, (1919925, 35), (1919960, 26),
    (1919986, 23), (1920009, 21), (1920030, 42), None, None, None, None,
    None, None, (1920072, 21), None, None, None, (1920093, 21), None, None,
    (1920114, 90), None, (1920204, 239), (1920443, 38), None, None, None, None]
    ]
_CRC8_TABLE = [0, 7, 14, 9, 28, 27, 18, 21, 56, 63, 54, 49, 36, 35, 42, 45,
    112, 119, 126, 121, 108, 107, 98, 101, 72, 79, 70, 65, 84, 83, 90, 93, 
    224, 231, 238, 233, 252, 251, 242, 245, 216, 223, 214, 209, 196, 195, 
    202, 205, 144, 151, 158, 153, 140, 139, 130, 133, 168, 175, 166, 161, 
    180, 179, 186, 189, 199, 192, 201, 206, 219, 220, 213, 210, 255, 248, 
    241, 246, 227, 228, 237, 234, 183, 176, 185, 190, 171, 172, 165, 162, 
    143, 136, 129, 134, 147, 148, 157, 154, 39, 32, 41, 46, 59, 60, 53, 50,
    31, 24, 17, 22, 3, 4, 13, 10, 87, 80, 89, 94, 75, 76, 69, 66, 111, 104,
    97, 102, 115, 116, 125, 122, 137, 142, 135, 128, 149, 146, 155, 156, 
    177, 182, 191, 184, 173, 170, 163, 164, 249, 254, 247, 240, 229, 226, 
    235, 236, 193, 198, 207, 200, 221, 218, 211, 212, 105, 110, 103, 96, 
    117, 114, 123, 124, 81, 86, 95, 88, 77, 74, 67, 68, 25, 30, 23, 16, 5, 
    2, 11, 12, 33, 38, 47, 40, 61, 58, 51, 52, 78, 73, 64, 71, 82, 85, 92, 
    91, 118, 113, 120, 127, 106, 109, 100, 99, 62, 57, 48, 55, 34, 37, 44, 
    43, 6, 1, 8, 15, 26, 29, 20, 19, 174, 169, 160, 167, 178, 181, 188, 187,
    150, 145, 152, 159, 138, 141, 132, 131, 222, 217, 208, 215, 194, 197, 
    204, 203, 230, 225, 232, 239, 250, 253, 244, 243]
_IS_LEAF = 128
_INCLUDE_SUBDOMAINS = 64
try:
    from importlib.resources import open_binary

    def open_pkg_binary(path: str) ->typing.BinaryIO:
        return open_binary('hstspreload', path)
except ImportError:

    def open_pkg_binary(path: str) ->typing.BinaryIO:
        return open(os.path.join(os.path.dirname(os.path.abspath(__file__)),
            path), 'rb')


@functools.lru_cache(maxsize=1024)
def in_hsts_preload(host: typing.AnyStr) ->bool:
    """Determines if an IDNA-encoded host is on the HSTS preload list"""
    if isinstance(host, str):
        host = host.encode('ascii')
    labels = host.lower().split(b'.')
    if labels[-1] in _GTLD_INCLUDE_SUBDOMAINS:
        return True
    with open_pkg_binary('hstspreload.bin') as f:
        for layer, label in enumerate(labels[::-1]):
            if layer > 3:
                return False
            jump_info = _JUMPTABLE[layer][_crc8(label)]
            if jump_info is None:
                return False
            f.seek(jump_info[0])
            data = bytearray(jump_info[1])
            f.readinto(data)
            for is_leaf, include_subdomains, ent_label in _iter_entries(data):
                if is_leaf:
                    if ent_label == host:
                        return True
                    if include_subdomains and host.endswith(b'.' + ent_label):
                        return True
                elif label == ent_label:
                    break
            else:
                return False
    return False


def _iter_entries(data: bytes) ->typing.Iterable[typing.Tuple[int, int, bytes]
    ]:
    while data:
        flags = data[0]
        size = data[1]
        label = bytes(data[2:2 + size])
        yield flags & _IS_LEAF, flags & _INCLUDE_SUBDOMAINS, label
        data = data[2 + size:]


def _crc8(value: bytes) ->int:
    checksum = 0
    for byte in value:
        checksum = _CRC8_TABLE[checksum ^ byte]
    return checksum

<mask token>
import functools
import os
import typing
__version__ = '2020.9.29'
__checksum__ = (
    '598603b7530346ce511693a60ae92537ab62fa66528dfd0ad68a711418ec3877')
__all__ = ['in_hsts_preload']
_GTLD_INCLUDE_SUBDOMAINS = {b'android', b'app', b'bank', b'chrome', b'dev',
    b'foo', b'gle', b'gmail', b'google', b'hangout', b'insurance', b'meet',
    b'new', b'page', b'play', b'search', b'youtube'}
_JUMPTABLE = [[(0, 11), (11, 5), None, (16, 57), (73, 26), (99, 12), None,
    (111, 19), (130, 22), (152, 7), (159, 20), (179, 18), None, (197, 22),
    (219, 45), (264, 7), (271, 9), (280, 36), (316, 10), (326, 10), (336, 
    21), None, (357, 50), (407, 8), (415, 9), (424, 19), (443, 13), (456, 
    14), (470, 14), None, None, (484, 29), (513, 16), (529, 35), (564, 14),
    (578, 24), (602, 9), None, (611, 25), (636, 20), (656, 8), (664, 13), (
    677, 10), None, (687, 17), (704, 6), (710, 26), (736, 5), (741, 5), (
    746, 10), (756, 10), (766, 11), (777, 12), (789, 27), None, (816, 11),
    (827, 11), (838, 7), (845, 29), (874, 18), (892, 27), (919, 46), (965, 
    25), (990, 16), (1006, 8), (1014, 5), (1019, 22), (1041, 18), None, (
    1059, 36), (1095, 15), (1110, 8), (1118, 11), None, (1129, 5), (1134, 
    16), (1150, 14), (1164, 18), None, (1182, 14), (1196, 18), (1214, 48),
    (1262, 19), (1281, 5), (1286, 46), (1332, 14), (1346, 14), (1360, 20),
    None, (1380, 10), (1390, 13), (1403, 10), (1413, 19), None, (1432, 13),
    (1445, 19), (1464, 5), (1469, 4), (1473, 22), (1495, 10), (1505, 7), (
    1512, 14), (1526, 21), (1547, 11), (1558, 10), (1568, 12), (1580, 32),
    None, (1612, 10), (1622, 14), (1636, 12), (1648, 45), (1693, 15), None,
    (1708, 11), (1719, 23), (1742, 21), (1763, 26), (1789, 6), (1795, 6), (
    1801, 7), (1808, 5), (1813, 20), (1833, 23), (1856, 24), (1880, 13), (
    1893, 15), (1908, 19), (1927, 6), (1933, 61), (1994, 44), (2038, 12), (
    2050, 23), (2073, 16), (2089, 38), (2127, 6), (2133, 12), (2145, 44), (
    2189, 6), (2195, 41), (2236, 13), (2249, 23), (2272, 30), (2302, 16), (
    2318, 8), (2326, 15), (2341, 12), (2353, 19), (2372, 21), (2393, 15),
    None, (2408, 35), (2443, 21), (2464, 17), (2481, 19), (2500, 26), (2526,
    5), (2531, 37), (2568, 26), (2594, 16), (2610, 10), (2620, 17), (2637, 
    23), (2660, 14), (2674, 17), (2691, 8), (2699, 4), (2703, 7), (2710, 29
    ), (2739, 6), (2745, 18), (2763, 27), (2790, 20), (2810, 17), (2827, 19
    ), (2846, 12), (2858, 40), (2898, 40), (2938, 12), (2950, 48), (2998, 
    25), (3023, 12), None, (3035, 8), (3043, 20), (3063, 19), (3082, 6), (
    3088, 23), None, (3111, 30), (3141, 33), (3174, 14), (3188, 12), (3200,
    27), None, (3227, 26), (3253, 41), (3294, 50), (3344, 15), (3359, 20),
    (3379, 15), (3394, 21), (3415, 32), (3447, 24), (3471, 20), (3491, 13),
    (3504, 60), (3564, 19), (3583, 9), (3592, 12), (3604, 12), (3616, 11),
    (3627, 10), (3637, 48), (3685, 32), None, (3717, 25), (3742, 12), None,
    (3754, 8), (3762, 8), (3770, 7), None, (3777, 25), (3802, 17), None, (
    3819, 21), (3840, 35), (3875, 12), (3887, 10), (3897, 36), (3933, 20),
    (3953, 22), (3975, 23), (3998, 19), (4017, 12), (4029, 5), (4034, 30),
    (4064, 24), (4088, 14), (4102, 14), (4116, 47), (4163, 46), None, None,
    (4209, 51), (4260, 42), None, (4302, 14), None, (4316, 15), (4331, 8),
    (4339, 21), (4360, 6), (4366, 16), (4382, 17)], [(4399, 6384), (10783, 
    6864), (17647, 7203), (24850, 6155), (31005, 6437), (37442, 6221), (
    43663, 7069), (50732, 6418), (57150, 6930), (64080, 6214), (70294, 7294
    ), (77588, 6574), (84162, 6882), (91044, 7307), (98351, 6627), (104978,
    6887), (111865, 7208), (119073, 6010), (125083, 6338), (131421, 6630),
    (138051, 7042), (145093, 6644), (151737, 7116), (158853, 6218), (165071,
    6495), (171566, 6756), (178322, 6745), (185067, 7107), (192174, 6330),
    (198504, 6855), (205359, 6947), (212306, 6603), (218909, 6637), (225546,
    7101), (232647, 6311), (238958, 6912), (245870, 6310), (252180, 7209),
    (259389, 6866), (266255, 7034), (273289, 7664), (280953, 6501), (287454,
    6487), (293941, 6274), (300215, 6446), (306661, 6299), (312960, 6515),
    (319475, 7139), (326614, 6491), (333105, 6008), (339113, 6513), (345626,
    6746), (352372, 6726), (359098, 6882), (365980, 7002), (372982, 6932),
    (379914, 6974), (386888, 6106), (392994, 7036), (400030, 5952), (405982,
    6781), (412763, 6549), (419312, 6445), (425757, 6960), (432717, 6738),
    (439455, 6809), (446264, 6353), (452617, 7244), (459861, 6915), (466776,
    6899), (473675, 6602), (480277, 6654), (486931, 5775), (492706, 7126),
    (499832, 7149), (506981, 7198), (514179, 6107), (520286, 7300), (527586,
    7099), (534685, 6204), (540889, 6941), (547830, 5861), (553691, 6520),
    (560211, 6814), (567025, 6554), (573579, 6503), (580082, 6758), (586840,
    6715), (593555, 6923), (600478, 6825), (607303, 7423), (614726, 6101),
    (620827, 6407), (627234, 6654), (633888, 6593), (640481, 7220), (647701,
    7164), (654865, 6516), (661381, 6342), (667723, 6321), (674044, 6400),
    (680444, 6804), (687248, 6315), (693563, 6622), (700185, 6332), (706517,
    6965), (713482, 6868), (720350, 7178), (727528, 8203), (735731, 7233),
    (742964, 7109), (750073, 6688), (756761, 6467), (763228, 6785), (770013,
    7016), (777029, 6818), (783847, 6315), (790162, 6465), (796627, 6484),
    (803111, 7241), (810352, 7042), (817394, 7118), (824512, 7106), (831618,
    7076), (838694, 7942), (846636, 6519), (853155, 5956), (859111, 7075),
    (866186, 6671), (872857, 8222), (881079, 7251), (888330, 6175), (894505,
    6912), (901417, 6965), (908382, 6396), (914778, 6910), (921688, 6261),
    (927949, 6845), (934794, 6609), (941403, 6651), (948054, 6684), (954738,
    7370), (962108, 6406), (968514, 6368), (974882, 6759), (981641, 6660),
    (988301, 6671), (994972, 6957), (1001929, 6408), (1008337, 7283), (
    1015620, 6706), (1022326, 6866), (1029192, 7098), (1036290, 6578), (
    1042868, 6818), (1049686, 6747), (1056433, 6548), (1062981, 6608), (
    1069589, 6394), (1075983, 6116), (1082099, 6377), (1088476, 6799), (
    1095275, 7349), (1102624, 6253), (1108877, 6689), (1115566, 7007), (
    1122573, 6423), (1128996, 6421), (1135417, 7090), (1142507, 6660), (
    1149167, 6068), (1155235, 6636), (1161871, 7840), (1169711, 6257), (
    1175968, 6446), (1182414, 6948), (1189362, 6496), (1195858, 6822), (
    1202680, 6508), (1209188, 6171), (1215359, 7671), (1223030, 6868), (
    1229898, 6660), (1236558, 7109), (1243667, 7511), (1251178, 7458), (
    1258636, 6230), (1264866, 7144), (1272010, 6415), (1278425, 6680), (
    1285105, 6959), (1292064, 6387), (1298451, 7016), (1305467, 7192), (
    1312659, 6709), (1319368, 6817), (1326185, 6584), (1332769, 6564), (
    1339333, 6832), (1346165, 6428), (1352593, 6861), (1359454, 6182), (
    1365636, 7137), (1372773, 6966), (1379739, 6692), (1386431, 7204), (
    1393635, 5911), (1399546, 6830), (1406376, 6614), (1412990, 6961), (
    1419951, 6952), (1426903, 7170), (1434073, 6779), (1440852, 6975), (
    1447827, 6971), (1454798, 6490), (1461288, 6704), (1467992, 6757), (
    1474749, 6738), (1481487, 6549), (1488036, 6652), (1494688, 6172), (
    1500860, 7634), (1508494, 6775), (1515269, 6421), (1521690, 6734), (
    1528424, 6846), (1535270, 6065), (1541335, 6943), (1548278, 6644), (
    1554922, 7606), (1562528, 6572), (1569100, 6174), (1575274, 7121), (
    1582395, 6478), (1588873, 7294), (1596167, 6357), (1602524, 6461), (
    1608985, 5864), (1614849, 6846), (1621695, 6597), (1628292, 6964), (
    1635256, 6459), (1641715, 6673), (1648388, 6616), (1655004, 7192), (
    1662196, 6514), (1668710, 5950), (1674660, 6708), (1681368, 6404), (
    1687772, 6842), (1694614, 7089), (1701703, 7208), (1708911, 6348), (
    1715259, 6369), (1721628, 6795)], [(1728423, 716), (1729139, 669), (
    1729808, 665), (1730473, 757), (1731230, 553), (1731783, 670), (1732453,
    698), (1733151, 836), (1733987, 640), (1734627, 667), (1735294, 536), (
    1735830, 574), (1736404, 792), (1737196, 853), (1738049, 1020), (
    1739069, 850), (1739919, 1242), (1741161, 669), (1741830, 875), (
    1742705, 696), (1743401, 757), (1744158, 765), (1744923, 865), (1745788,
    731), (1746519, 717), (1747236, 695), (1747931, 955), (1748886, 1131),
    (1750017, 807), (1750824, 734), (1751558, 922), (1752480, 787), (
    1753267, 586), (1753853, 733), (1754586, 748), (1755334, 800), (1756134,
    678), (1756812, 746), (1757558, 724), (1758282, 1119), (1759401, 695),
    (1760096, 812), (1760908, 748), (1761656, 719), (1762375, 728), (
    1763103, 396), (1763499, 942), (1764441, 870), (1765311, 735), (1766046,
    592), (1766638, 834), (1767472, 692), (1768164, 780), (1768944, 1012),
    (1769956, 944), (1770900, 558), (1771458, 661), (1772119, 550), (
    1772669, 578), (1773247, 771), (1774018, 772), (1774790, 776), (1775566,
    1054), (1776620, 927), (1777547, 725), (1778272, 719), (1778991, 767),
    (1779758, 494), (1780252, 595), (1780847, 592), (1781439, 692), (
    1782131, 877), (1783008, 596), (1783604, 725), (1784329, 650), (1784979,
    685), (1785664, 573), (1786237, 711), (1786948, 787), (1787735, 496), (
    1788231, 814), (1789045, 629), (1789674, 828), (1790502, 646), (1791148,
    603), (1791751, 425), (1792176, 597), (1792773, 746), (1793519, 804), (
    1794323, 782), (1795105, 853), (1795958, 1092), (1797050, 839), (
    1797889, 856), (1798745, 725), (1799470, 436), (1799906, 955), (1800861,
    857), (1801718, 580), (1802298, 671), (1802969, 728), (1803697, 885), (
    1804582, 903), (1805485, 571), (1806056, 632), (1806688, 772), (1807460,
    419), (1807879, 466), (1808345, 924), (1809269, 963), (1810232, 851), (
    1811083, 793), (1811876, 654), (1812530, 792), (1813322, 672), (1813994,
    699), (1814693, 709), (1815402, 505), (1815907, 722), (1816629, 710), (
    1817339, 930), (1818269, 700), (1818969, 804), (1819773, 483), (1820256,
    691), (1820947, 780), (1821727, 835), (1822562, 926), (1823488, 806), (
    1824294, 942), (1825236, 802), (1826038, 524), (1826562, 815), (1827377,
    651), (1828028, 803), (1828831, 779), (1829610, 737), (1830347, 681), (
    1831028, 635), (1831663, 673), (1832336, 621), (1832957, 674), (1833631,
    694), (1834325, 648), (1834973, 494), (1835467, 603), (1836070, 661), (
    1836731, 597), (1837328, 729), (1838057, 594), (1838651, 773), (1839424,
    514), (1839938, 550), (1840488, 701), (1841189, 642), (1841831, 657), (
    1842488, 639), (1843127, 870), (1843997, 610), (1844607, 622), (1845229,
    903), (1846132, 870), (1847002, 583), (1847585, 695), (1848280, 873), (
    1849153, 659), (1849812, 692), (1850504, 455), (1850959, 609), (1851568,
    681), (1852249, 810), (1853059, 619), (1853678, 932), (1854610, 760), (
    1855370, 807), (1856177, 721), (1856898, 668), (1857566, 582), (1858148,
    664), (1858812, 706), (1859518, 1412), (1860930, 575), (1861505, 662),
    (1862167, 650), (1862817, 1027), (1863844, 800), (1864644, 798), (
    1865442, 546), (1865988, 609), (1866597, 823), (1867420, 601), (1868021,
    589), (1868610, 814), (1869424, 720), (1870144, 892), (1871036, 810), (
    1871846, 764), (1872610, 710), (1873320, 868), (1874188, 637), (1874825,
    947), (1875772, 662), (1876434, 819), (1877253, 630), (1877883, 742), (
    1878625, 510), (1879135, 828), (1879963, 826), (1880789, 665), (1881454,
    916), (1882370, 787), (1883157, 868), (1884025, 954), (1884979, 1077),
    (1886056, 887), (1886943, 669), (1887612, 895), (1888507, 731), (
    1889238, 533), (1889771, 443), (1890214, 794), (1891008, 823), (1891831,
    455), (1892286, 1026), (1893312, 513), (1893825, 778), (1894603, 881),
    (1895484, 792), (1896276, 806), (1897082, 696), (1897778, 826), (
    1898604, 751), (1899355, 784), (1900139, 607), (1900746, 579), (1901325,
    445), (1901770, 666), (1902436, 484), (1902920, 816), (1903736, 880), (
    1904616, 764), (1905380, 718), (1906098, 658), (1906756, 604), (1907360,
    848), (1908208, 495), (1908703, 606), (1909309, 780), (1910089, 494), (
    1910583, 870), (1911453, 2090), (1913543, 548), (1914091, 707), (
    1914798, 890), (1915688, 912), (1916600, 539)], [(1917139, 48), None, (
    1917187, 35), (1917222, 42), None, None, None, None, None, None, None,
    None, None, None, None, None, None, (1917264, 42), None, (1917306, 25),
    (1917331, 44), (1917375, 22), (1917397, 18), None, None, None, None, (
    1917415, 26), None, None, None, None, (1917441, 21), (1917462, 25),
    None, None, (1917487, 26), None, None, None, None, (1917513, 44), (
    1917557, 21), (1917578, 23), None, None, None, None, (1917601, 48),
    None, None, None, None, None, (1917649, 31), None, None, None, None, (
    1917680, 42), None, (1917722, 22), None, (1917744, 21), None, (1917765,
    26), (1917791, 42), None, None, (1917833, 77), None, None, None, None,
    None, (1917910, 21), (1917931, 21), None, None, (1917952, 34), (1917986,
    42), None, None, None, (1918028, 25), None, None, (1918053, 21), None,
    None, None, None, None, (1918074, 24), (1918098, 21), None, None, (
    1918119, 26), None, (1918145, 18), None, (1918163, 54), None, None,
    None, None, None, None, (1918217, 26), None, (1918243, 19), None, (
    1918262, 20), None, None, (1918282, 42), (1918324, 42), (1918366, 17),
    None, (1918383, 26), None, (1918409, 26), None, None, None, (1918435, 
    26), (1918461, 20), (1918481, 26), None, (1918507, 42), (1918549, 63),
    None, None, None, (1918612, 40), (1918652, 48), None, None, None, (
    1918700, 47), None, None, None, None, None, None, None, (1918747, 42),
    None, (1918789, 55), None, (1918844, 9), None, (1918853, 21), (1918874,
    42), None, None, (1918916, 42), (1918958, 82), None, None, (1919040, 42
    ), None, None, None, None, None, None, None, None, None, (1919082, 42),
    (1919124, 21), (1919145, 21), None, (1919166, 42), (1919208, 25), None,
    None, (1919233, 21), (1919254, 42), None, None, (1919296, 21), (1919317,
    19), (1919336, 26), None, None, None, (1919362, 21), None, None, (
    1919383, 38), None, (1919421, 22), (1919443, 21), (1919464, 21), None,
    None, (1919485, 63), None, (1919548, 21), (1919569, 42), None, (1919611,
    17), None, None, None, None, (1919628, 21), (1919649, 21), None, None,
    (1919670, 21), None, None, (1919691, 21), None, (1919712, 26), None, (
    1919738, 50), None, None, None, (1919788, 50), (1919838, 26), (1919864,
    21), (1919885, 21), (1919906, 19), None, (1919925, 35), (1919960, 26),
    (1919986, 23), (1920009, 21), (1920030, 42), None, None, None, None,
    None, None, (1920072, 21), None, None, None, (1920093, 21), None, None,
    (1920114, 90), None, (1920204, 239), (1920443, 38), None, None, None, None]
    ]
_CRC8_TABLE = [0, 7, 14, 9, 28, 27, 18, 21, 56, 63, 54, 49, 36, 35, 42, 45,
    112, 119, 126, 121, 108, 107, 98, 101, 72, 79, 70, 65, 84, 83, 90, 93, 
    224, 231, 238, 233, 252, 251, 242, 245, 216, 223, 214, 209, 196, 195, 
    202, 205, 144, 151, 158, 153, 140, 139, 130, 133, 168, 175, 166, 161, 
    180, 179, 186, 189, 199, 192, 201, 206, 219, 220, 213, 210, 255, 248, 
    241, 246, 227, 228, 237, 234, 183, 176, 185, 190, 171, 172, 165, 162, 
    143, 136, 129, 134, 147, 148, 157, 154, 39, 32, 41, 46, 59, 60, 53, 50,
    31, 24, 17, 22, 3, 4, 13, 10, 87, 80, 89, 94, 75, 76, 69, 66, 111, 104,
    97, 102, 115, 116, 125, 122, 137, 142, 135, 128, 149, 146, 155, 156, 
    177, 182, 191, 184, 173, 170, 163, 164, 249, 254, 247, 240, 229, 226, 
    235, 236, 193, 198, 207, 200, 221, 218, 211, 212, 105, 110, 103, 96, 
    117, 114, 123, 124, 81, 86, 95, 88, 77, 74, 67, 68, 25, 30, 23, 16, 5, 
    2, 11, 12, 33, 38, 47, 40, 61, 58, 51, 52, 78, 73, 64, 71, 82, 85, 92, 
    91, 118, 113, 120, 127, 106, 109, 100, 99, 62, 57, 48, 55, 34, 37, 44, 
    43, 6, 1, 8, 15, 26, 29, 20, 19, 174, 169, 160, 167, 178, 181, 188, 187,
    150, 145, 152, 159, 138, 141, 132, 131, 222, 217, 208, 215, 194, 197, 
    204, 203, 230, 225, 232, 239, 250, 253, 244, 243]
_IS_LEAF = 128
_INCLUDE_SUBDOMAINS = 64
try:
    from importlib.resources import open_binary

    def open_pkg_binary(path: str) ->typing.BinaryIO:
        return open_binary('hstspreload', path)
except ImportError:

    def open_pkg_binary(path: str) ->typing.BinaryIO:
        return open(os.path.join(os.path.dirname(os.path.abspath(__file__)),
            path), 'rb')


@functools.lru_cache(maxsize=1024)
def in_hsts_preload(host: typing.AnyStr) ->bool:
    """Determines if an IDNA-encoded host is on the HSTS preload list"""
    if isinstance(host, str):
        host = host.encode('ascii')
    labels = host.lower().split(b'.')
    if labels[-1] in _GTLD_INCLUDE_SUBDOMAINS:
        return True
    with open_pkg_binary('hstspreload.bin') as f:
        for layer, label in enumerate(labels[::-1]):
            if layer > 3:
                return False
            jump_info = _JUMPTABLE[layer][_crc8(label)]
            if jump_info is None:
                return False
            f.seek(jump_info[0])
            data = bytearray(jump_info[1])
            f.readinto(data)
            for is_leaf, include_subdomains, ent_label in _iter_entries(data):
                if is_leaf:
                    if ent_label == host:
                        return True
                    if include_subdomains and host.endswith(b'.' + ent_label):
                        return True
                elif label == ent_label:
                    break
            else:
                return False
    return False


def _iter_entries(data: bytes) ->typing.Iterable[typing.Tuple[int, int, bytes]
    ]:
    while data:
        flags = data[0]
        size = data[1]
        label = bytes(data[2:2 + size])
        yield flags & _IS_LEAF, flags & _INCLUDE_SUBDOMAINS, label
        data = data[2 + size:]


def _crc8(value: bytes) ->int:
    checksum = 0
    for byte in value:
        checksum = _CRC8_TABLE[checksum ^ byte]
    return checksum

"""Check if a host is in the Google Chrome HSTS Preload list"""

import functools
import os
import typing

__version__ = "2020.9.29"
__checksum__ = "598603b7530346ce511693a60ae92537ab62fa66528dfd0ad68a711418ec3877"
__all__ = ["in_hsts_preload"]

# fmt: off
_GTLD_INCLUDE_SUBDOMAINS = {b'android', b'app', b'bank', b'chrome', b'dev', b'foo', b'gle', b'gmail', b'google', b'hangout', b'insurance', b'meet', b'new', b'page', b'play', b'search', b'youtube'}  # noqa: E501
_JUMPTABLE = [[(0, 11), (11, 5), None, (16, 57), (73, 26), (99, 12), None, (111, 19), (130, 22), (152, 7), (159, 20), (179, 18), None, (197, 22), (219, 45), (264, 7), (271, 9), (280, 36), (316, 10), (326, 10), (336, 21), None, (357, 50), (407, 8), (415, 9), (424, 19), (443, 13), (456, 14), (470, 14), None, None, (484, 29), (513, 16), (529, 35), (564, 14), (578, 24), (602, 9), None, (611, 25), (636, 20), (656, 8), (664, 13), (677, 10), None, (687, 17), (704, 6), (710, 26), (736, 5), (741, 5), (746, 10), (756, 10), (766, 11), (777, 12), (789, 27), None, (816, 11), (827, 11), (838, 7), (845, 29), (874, 18), (892, 27), (919, 46), (965, 25), (990, 16), (1006, 8), (1014, 5), (1019, 22), (1041, 18), None, (1059, 36), (1095, 15), (1110, 8), (1118, 11), None, (1129, 5), (1134, 16), (1150, 14), (1164, 18), None, (1182, 14), (1196, 18), (1214, 48), (1262, 19), (1281, 5), (1286, 46), (1332, 14), (1346, 14), (1360, 20), None, (1380, 10), (1390, 13), (1403, 10), (1413, 19), None, (1432, 13), (1445, 19), (1464, 5), (1469, 4), (1473, 22), (1495, 10), (1505, 7), (1512, 14), (1526, 21), (1547, 11), (1558, 10), (1568, 12), (1580, 32), None, (1612, 10), (1622, 14), (1636, 12), (1648, 45), (1693, 15), None, (1708, 11), (1719, 23), (1742, 21), (1763, 26), (1789, 6), (1795, 6), (1801, 7), (1808, 5), (1813, 20), (1833, 23), (1856, 24), (1880, 13), (1893, 15), (1908, 19), (1927, 6), (1933, 61), (1994, 44), (2038, 12), (2050, 23), (2073, 16), (2089, 38), (2127, 6), (2133, 12), (2145, 44), (2189, 6), (2195, 41), (2236, 13), (2249, 23), (2272, 30), (2302, 16), (2318, 8), (2326, 15), (2341, 12), (2353, 19), (2372, 21), (2393, 15), None, (2408, 35), (2443, 21), (2464, 17), (2481, 19), (2500, 26), (2526, 5), (2531, 37), (2568, 26), (2594, 16), (2610, 10), (2620, 17), (2637, 23), (2660, 14), (2674, 17), (2691, 8), (2699, 4), (2703, 7), (2710, 29), (2739, 6), (2745, 18), (2763, 27), (2790, 20), (2810, 17), (2827, 19), (2846, 12), (2858, 40), (2898, 40), (2938, 12), (2950, 48), (2998, 25), (3023, 12), None, (3035, 8), (3043, 20), (3063, 19), (3082, 6), (3088, 23), None, (3111, 30), (3141, 33), (3174, 14), (3188, 12), (3200, 27), None, (3227, 26), (3253, 41), (3294, 50), (3344, 15), (3359, 20), (3379, 15), (3394, 21), (3415, 32), (3447, 24), (3471, 20), (3491, 13), (3504, 60), (3564, 19), (3583, 9), (3592, 12), (3604, 12), (3616, 11), (3627, 10), (3637, 48), (3685, 32), None, (3717, 25), (3742, 12), None, (3754, 8), (3762, 8), (3770, 7), None, (3777, 25), (3802, 17), None, (3819, 21), (3840, 35), (3875, 12), (3887, 10), (3897, 36), (3933, 20), (3953, 22), (3975, 23), (3998, 19), (4017, 12), (4029, 5), (4034, 30), (4064, 24), (4088, 14), (4102, 14), (4116, 47), (4163, 46), None, None, (4209, 51), (4260, 42), None, (4302, 14), None, (4316, 15), (4331, 8), (4339, 21), (4360, 6), (4366, 16), (4382, 17)], [(4399, 6384), (10783, 6864), (17647, 7203), (24850, 6155), (31005, 6437), (37442, 6221), (43663, 7069), (50732, 6418), (57150, 6930), (64080, 6214), (70294, 7294), (77588, 6574), (84162, 6882), (91044, 7307), (98351, 6627), (104978, 6887), (111865, 7208), (119073, 6010), (125083, 6338), (131421, 6630), (138051, 7042), (145093, 6644), (151737, 7116), (158853, 6218), (165071, 6495), (171566, 6756), (178322, 6745), (185067, 7107), (192174, 6330), (198504, 6855), (205359, 6947), (212306, 6603), (218909, 6637), (225546, 7101), (232647, 6311), (238958, 6912), (245870, 6310), (252180, 7209), (259389, 6866), (266255, 7034), (273289, 7664), (280953, 6501), (287454, 6487), (293941, 6274), (300215, 6446), (306661, 6299), (312960, 6515), (319475, 7139), (326614, 6491), (333105, 6008), (339113, 6513), (345626, 6746), (352372, 6726), (359098, 6882), (365980, 7002), (372982, 6932), (379914, 6974), (386888, 6106), (392994, 7036), (400030, 5952), (405982, 6781), (412763, 6549), (419312, 6445), (425757, 6960), (432717, 6738), (439455, 6809), (446264, 6353), (452617, 7244), (459861, 6915), (466776, 6899), (473675, 6602), (480277, 6654), (486931, 5775), (492706, 7126), (499832, 7149), (506981, 7198), (514179, 6107), (520286, 7300), (527586, 7099), (534685, 6204), (540889, 6941), (547830, 5861), (553691, 6520), (560211, 6814), (567025, 6554), (573579, 6503), (580082, 6758), (586840, 6715), (593555, 6923), (600478, 6825), (607303, 7423), (614726, 6101), (620827, 6407), (627234, 6654), (633888, 6593), (640481, 7220), (647701, 7164), (654865, 6516), (661381, 6342), (667723, 6321), (674044, 6400), (680444, 6804), (687248, 6315), (693563, 6622), (700185, 6332), (706517, 6965), (713482, 6868), (720350, 7178), (727528, 8203), (735731, 7233), (742964, 7109), (750073, 6688), (756761, 6467), (763228, 6785), (770013, 7016), (777029, 6818), (783847, 6315), (790162, 6465), (796627, 6484), (803111, 7241), (810352, 7042), (817394, 7118), (824512, 7106), (831618, 7076), (838694, 7942), (846636, 6519), (853155, 5956), (859111, 7075), (866186, 6671), (872857, 8222), (881079, 7251), (888330, 6175), (894505, 6912), (901417, 6965), (908382, 6396), (914778, 6910), (921688, 6261), (927949, 6845), (934794, 6609), (941403, 6651), (948054, 6684), (954738, 7370), (962108, 6406), (968514, 6368), (974882, 6759), (981641, 6660), (988301, 6671), (994972, 6957), (1001929, 6408), (1008337, 7283), (1015620, 6706), (1022326, 6866), (1029192, 7098), (1036290, 6578), (1042868, 6818), (1049686, 6747), (1056433, 6548), (1062981, 6608), (1069589, 6394), (1075983, 6116), (1082099, 6377), (1088476, 6799), (1095275, 7349), (1102624, 6253), (1108877, 6689), (1115566, 7007), (1122573, 6423), (1128996, 6421), (1135417, 7090), (1142507, 6660), (1149167, 6068), (1155235, 6636), (1161871, 7840), (1169711, 6257), (1175968, 6446), (1182414, 6948), (1189362, 6496), (1195858, 6822), (1202680, 6508), (1209188, 6171), (1215359, 7671), (1223030, 6868), (1229898, 6660), (1236558, 7109), (1243667, 7511), (1251178, 7458), (1258636, 6230), (1264866, 7144), (1272010, 6415), (1278425, 6680), (1285105, 6959), (1292064, 6387), (1298451, 7016), (1305467, 7192), (1312659, 6709), (1319368, 6817), (1326185, 6584), (1332769, 6564), (1339333, 6832), (1346165, 6428), (1352593, 6861), (1359454, 6182), (1365636, 7137), (1372773, 6966), (1379739, 6692), (1386431, 7204), (1393635, 5911), (1399546, 6830), (1406376, 6614), (1412990, 6961), (1419951, 6952), (1426903, 7170), (1434073, 6779), (1440852, 6975), (1447827, 6971), (1454798, 6490), (1461288, 6704), (1467992, 6757), (1474749, 6738), (1481487, 6549), (1488036, 6652), (1494688, 6172), (1500860, 7634), (1508494, 6775), (1515269, 6421), (1521690, 6734), (1528424, 6846), (1535270, 6065), (1541335, 6943), (1548278, 6644), (1554922, 7606), (1562528, 6572), (1569100, 6174), (1575274, 7121), (1582395, 6478), (1588873, 7294), (1596167, 6357), (1602524, 6461), (1608985, 5864), (1614849, 6846), (1621695, 6597), (1628292, 6964), (1635256, 6459), (1641715, 6673), (1648388, 6616), (1655004, 7192), (1662196, 6514), (1668710, 5950), (1674660, 6708), (1681368, 6404), (1687772, 6842), (1694614, 7089), (1701703, 7208), (1708911, 6348), (1715259, 6369), (1721628, 6795)], [(1728423, 716), (1729139, 669), (1729808, 665), (1730473, 757), (1731230, 553), (1731783, 670), (1732453, 698), (1733151, 836), (1733987, 640), (1734627, 667), (1735294, 536), (1735830, 574), (1736404, 792), (1737196, 853), (1738049, 1020), (1739069, 850), (1739919, 1242), (1741161, 669), (1741830, 875), (1742705, 696), (1743401, 757), (1744158, 765), (1744923, 865), (1745788, 731), (1746519, 717), (1747236, 695), (1747931, 955), (1748886, 1131), (1750017, 807), (1750824, 734), (1751558, 922), (1752480, 787), (1753267, 586), (1753853, 733), (1754586, 748), (1755334, 800), (1756134, 678), (1756812, 746), (1757558, 724), (1758282, 1119), (1759401, 695), (1760096, 812), (1760908, 748), (1761656, 719), (1762375, 728), (1763103, 396), (1763499, 942), (1764441, 870), (1765311, 735), (1766046, 592), (1766638, 834), (1767472, 692), (1768164, 780), (1768944, 1012), (1769956, 944), (1770900, 558), (1771458, 661), (1772119, 550), (1772669, 578), (1773247, 771), (1774018, 772), (1774790, 776), (1775566, 1054), (1776620, 927), (1777547, 725), (1778272, 719), (1778991, 767), (1779758, 494), (1780252, 595), (1780847, 592), (1781439, 692), (1782131, 877), (1783008, 596), (1783604, 725), (1784329, 650), (1784979, 685), (1785664, 573), (1786237, 711), (1786948, 787), (1787735, 496), (1788231, 814), (1789045, 629), (1789674, 828), (1790502, 646), (1791148, 603), (1791751, 425), (1792176, 597), (1792773, 746), (1793519, 804), (1794323, 782), (1795105, 853), (1795958, 1092), (1797050, 839), (1797889, 856), (1798745, 725), (1799470, 436), (1799906, 955), (1800861, 857), (1801718, 580), (1802298, 671), (1802969, 728), (1803697, 885), (1804582, 903), (1805485, 571), (1806056, 632), (1806688, 772), (1807460, 419), (1807879, 466), (1808345, 924), (1809269, 963), (1810232, 851), (1811083, 793), (1811876, 654), (1812530, 792), (1813322, 672), (1813994, 699), (1814693, 709), (1815402, 505), (1815907, 722), (1816629, 710), (1817339, 930), (1818269, 700), (1818969, 804), (1819773, 483), (1820256, 691), (1820947, 780), (1821727, 835), (1822562, 926), (1823488, 806), (1824294, 942), (1825236, 802), (1826038, 524), (1826562, 815), (1827377, 651), (1828028, 803), (1828831, 779), (1829610, 737), (1830347, 681), (1831028, 635), (1831663, 673), (1832336, 621), (1832957, 674), (1833631, 694), (1834325, 648), (1834973, 494), (1835467, 603), (1836070, 661), (1836731, 597), (1837328, 729), (1838057, 594), (1838651, 773), (1839424, 514), (1839938, 550), (1840488, 701), (1841189, 642), (1841831, 657), (1842488, 639), (1843127, 870), (1843997, 610), (1844607, 622), (1845229, 903), (1846132, 870), (1847002, 583), (1847585, 695), (1848280, 873), (1849153, 659), (1849812, 692), (1850504, 455), (1850959, 609), (1851568, 681), (1852249, 810), (1853059, 619), (1853678, 932), (1854610, 760), (1855370, 807), (1856177, 721), (1856898, 668), (1857566, 582), (1858148, 664), (1858812, 706), (1859518, 1412), (1860930, 575), (1861505, 662), (1862167, 650), (1862817, 1027), (1863844, 800), (1864644, 798), (1865442, 546), (1865988, 609), (1866597, 823), (1867420, 601), (1868021, 589), (1868610, 814), (1869424, 720), (1870144, 892), (1871036, 810), (1871846, 764), (1872610, 710), (1873320, 868), (1874188, 637), (1874825, 947), (1875772, 662), (1876434, 819), (1877253, 630), (1877883, 742), (1878625, 510), (1879135, 828), (1879963, 826), (1880789, 665), (1881454, 916), (1882370, 787), (1883157, 868), (1884025, 954), (1884979, 1077), (1886056, 887), (1886943, 669), (1887612, 895), (1888507, 731), (1889238, 533), (1889771, 443), (1890214, 794), (1891008, 823), (1891831, 455), (1892286, 1026), (1893312, 513), (1893825, 778), (1894603, 881), (1895484, 792), (1896276, 806), (1897082, 696), (1897778, 826), (1898604, 751), (1899355, 784), (1900139, 607), (1900746, 579), (1901325, 445), (1901770, 666), (1902436, 484), (1902920, 816), (1903736, 880), (1904616, 764), (1905380, 718), (1906098, 658), (1906756, 604), (1907360, 848), (1908208, 495), (1908703, 606), (1909309, 780), (1910089, 494), (1910583, 870), (1911453, 2090), (1913543, 548), (1914091, 707), (1914798, 890), (1915688, 912), (1916600, 539)], [(1917139, 48), None, (1917187, 35), (1917222, 42), None, None, None, None, None, None, None, None, None, None, None, None, None, (1917264, 42), None, (1917306, 25), (1917331, 44), (1917375, 22), (1917397, 18), None, None, None, None, (1917415, 26), None, None, None, None, (1917441, 21), (1917462, 25), None, None, (1917487, 26), None, None, None, None, (1917513, 44), (1917557, 21), (1917578, 23), None, None, None, None, (1917601, 48), None, None, None, None, None, (1917649, 31), None, None, None, None, (1917680, 42), None, (1917722, 22), None, (1917744, 21), None, (1917765, 26), (1917791, 42), None, None, (1917833, 77), None, None, None, None, None, (1917910, 21), (1917931, 21), None, None, (1917952, 34), (1917986, 42), None, None, None, (1918028, 25), None, None, (1918053, 21), None, None, None, None, None, (1918074, 24), (1918098, 21), None, None, (1918119, 26), None, (1918145, 18), None, (1918163, 54), None, None, None, None, None, None, (1918217, 26), None, (1918243, 19), None, (1918262, 20), None, None, (1918282, 42), (1918324, 42), (1918366, 17), None, (1918383, 26), None, (1918409, 26), None, None, None, (1918435, 26), (1918461, 20), (1918481, 26), None, (1918507, 42), (1918549, 63), None, None, None, (1918612, 40), (1918652, 48), None, None, None, (1918700, 47), None, None, None, None, None, None, None, (1918747, 42), None, (1918789, 55), None, (1918844, 9), None, (1918853, 21), (1918874, 42), None, None, (1918916, 42), (1918958, 82), None, None, (1919040, 42), None, None, None, None, None, None, None, None, None, (1919082, 42), (1919124, 21), (1919145, 21), None, (1919166, 42), (1919208, 25), None, None, (1919233, 21), (1919254, 42), None, None, (1919296, 21), (1919317, 19), (1919336, 26), None, None, None, (1919362, 21), None, None, (1919383, 38), None, (1919421, 22), (1919443, 21), (1919464, 21), None, None, (1919485, 63), None, (1919548, 21), (1919569, 42), None, (1919611, 17), None, None, None, None, (1919628, 21), (1919649, 21), None, None, (1919670, 21), None, None, (1919691, 21), None, (1919712, 26), None, (1919738, 50), None, None, None, (1919788, 50), (1919838, 26), (1919864, 21), (1919885, 21), (1919906, 19), None, (1919925, 35), (1919960, 26), (1919986, 23), (1920009, 21), (1920030, 42), None, None, None, None, None, None, (1920072, 21), None, None, None, (1920093, 21), None, None, (1920114, 90), None, (1920204, 239), (1920443, 38), None, None, None, None]]  # noqa: E501
_CRC8_TABLE = [
    0x00, 0x07, 0x0e, 0x09, 0x1c, 0x1b, 0x12, 0x15,
    0x38, 0x3f, 0x36, 0x31, 0x24, 0x23, 0x2a, 0x2d,
    0x70, 0x77, 0x7e, 0x79, 0x6c, 0x6b, 0x62, 0x65,
    0x48, 0x4f, 0x46, 0x41, 0x54, 0x53, 0x5a, 0x5d,
    0xe0, 0xe7, 0xee, 0xe9, 0xfc, 0xfb, 0xf2, 0xf5,
    0xd8, 0xdf, 0xd6, 0xd1, 0xc4, 0xc3, 0xca, 0xcd,
    0x90, 0x97, 0x9e, 0x99, 0x8c, 0x8b, 0x82, 0x85,
    0xa8, 0xaf, 0xa6, 0xa1, 0xb4, 0xb3, 0xba, 0xbd,
    0xc7, 0xc0, 0xc9, 0xce, 0xdb, 0xdc, 0xd5, 0xd2,
    0xff, 0xf8, 0xf1, 0xf6, 0xe3, 0xe4, 0xed, 0xea,
    0xb7, 0xb0, 0xb9, 0xbe, 0xab, 0xac, 0xa5, 0xa2,
    0x8f, 0x88, 0x81, 0x86, 0x93, 0x94, 0x9d, 0x9a,
    0x27, 0x20, 0x29, 0x2e, 0x3b, 0x3c, 0x35, 0x32,
    0x1f, 0x18, 0x11, 0x16, 0x03, 0x04, 0x0d, 0x0a,
    0x57, 0x50, 0x59, 0x5e, 0x4b, 0x4c, 0x45, 0x42,
    0x6f, 0x68, 0x61, 0x66, 0x73, 0x74, 0x7d, 0x7a,
    0x89, 0x8e, 0x87, 0x80, 0x95, 0x92, 0x9b, 0x9c,
    0xb1, 0xb6, 0xbf, 0xb8, 0xad, 0xaa, 0xa3, 0xa4,
    0xf9, 0xfe, 0xf7, 0xf0, 0xe5, 0xe2, 0xeb, 0xec,
    0xc1, 0xc6, 0xcf, 0xc8, 0xdd, 0xda, 0xd3, 0xd4,
    0x69, 0x6e, 0x67, 0x60, 0x75, 0x72, 0x7b, 0x7c,
    0x51, 0x56, 0x5f, 0x58, 0x4d, 0x4a, 0x43, 0x44,
    0x19, 0x1e, 0x17, 0x10, 0x05, 0x02, 0x0b, 0x0c,
    0x21, 0x26, 0x2f, 0x28, 0x3d, 0x3a, 0x33, 0x34,
    0x4e, 0x49, 0x40, 0x47, 0x52, 0x55, 0x5c, 0x5b,
    0x76, 0x71, 0x78, 0x7f, 0x6a, 0x6d, 0x64, 0x63,
    0x3e, 0x39, 0x30, 0x37, 0x22, 0x25, 0x2c, 0x2b,
    0x06, 0x01, 0x08, 0x0f, 0x1a, 0x1d, 0x14, 0x13,
    0xae, 0xa9, 0xa0, 0xa7, 0xb2, 0xb5, 0xbc, 0xbb,
    0x96, 0x91, 0x98, 0x9f, 0x8a, 0x8d, 0x84, 0x83,
    0xde, 0xd9, 0xd0, 0xd7, 0xc2, 0xc5, 0xcc, 0xcb,
    0xe6, 0xe1, 0xe8, 0xef, 0xfa, 0xfd, 0xf4, 0xf3
]
# fmt: on

_IS_LEAF = 0x80
_INCLUDE_SUBDOMAINS = 0x40


try:
    from importlib.resources import open_binary

    def open_pkg_binary(path: str) -> typing.BinaryIO:
        return open_binary("hstspreload", path)


except ImportError:

    def open_pkg_binary(path: str) -> typing.BinaryIO:
        return open(
            os.path.join(os.path.dirname(os.path.abspath(__file__)), path),
            "rb",
        )


@functools.lru_cache(maxsize=1024)
def in_hsts_preload(host: typing.AnyStr) -> bool:
    """Determines if an IDNA-encoded host is on the HSTS preload list"""

    if isinstance(host, str):
        host = host.encode("ascii")
    labels = host.lower().split(b".")

    # Fast-branch for gTLDs that are registered to preload all sub-domains.
    if labels[-1] in _GTLD_INCLUDE_SUBDOMAINS:
        return True

    with open_pkg_binary("hstspreload.bin") as f:
        for layer, label in enumerate(labels[::-1]):
            # None of our layers are greater than 4 deep.
            if layer > 3:
                return False

            # Read the jump table for the layer and label
            jump_info = _JUMPTABLE[layer][_crc8(label)]
            if jump_info is None:
                # No entry: host is not preloaded
                return False

            # Read the set of entries for that layer and label
            f.seek(jump_info[0])
            data = bytearray(jump_info[1])
            f.readinto(data)

            for is_leaf, include_subdomains, ent_label in _iter_entries(data):
                # We found a potential leaf
                if is_leaf:
                    if ent_label == host:
                        return True
                    if include_subdomains and host.endswith(b"." + ent_label):
                        return True

                # Continue traversing as we're not at a leaf.
                elif label == ent_label:
                    break
            else:
                return False
    return False


def _iter_entries(data: bytes) -> typing.Iterable[typing.Tuple[int, int, bytes]]:
    while data:
        flags = data[0]
        size = data[1]
        label = bytes(data[2 : 2 + size])
        yield (flags & _IS_LEAF, flags & _INCLUDE_SUBDOMAINS, label)
        data = data[2 + size :]


def _crc8(value: bytes) -> int:
    # CRC8 reference implementation: https://github.com/niccokunzmann/crc8
    checksum = 0x00
    for byte in value:
        checksum = _CRC8_TABLE[checksum ^ byte]
    return checksum
