11from bs4 
import BeautifulSoup
 
   12from bs4 
import element
 
   14intro = 
'''/* This file is auto generated from 
   16 * https://docs.microsoft.com/en-us/windows/win32/intl/language-identifier-constants-and-strings 
   18 * please do not edit but use ./scripts/fetch_language_identifiers.py to regenerate! 
   24    soup = BeautifulSoup(text, 
'html.parser')
 
   25    table = soup.find(
"table")
 
   26    head = table.find(
'thead').find(
'tr')
 
   29        if type(th) == element.Tag:
 
   32    body = table.find(
'tbody')
 
   36        if type(tr) == element.Tag:
 
   39                if type(th) == element.Tag:
 
   45    return [headers, languages]
 
   47def is_base(num, base):
 
   56    return '0x' + s[2:].zfill(8)
 
   58def write_struct(fp, struct, name, url, base, inv = False, typemap = None):
 
   59    li = requests.get(url)
 
   60    if li.status_code != requests.codes.ok:
 
   61        print(
'Could not fetch ' + str(url) + 
', response code ' + str(li.status_code))
 
   63    headers, languages = parse_html(li.text)
 
   65    fp.write(
'const ' + str(struct) + 
' ' + str(name) + 
'[] =\n')
 
   74    for language 
in languages:
 
   88                h = str(switcher.get(base))
 
   92                  line = h + 
', ' + line
 
   96                if typemap 
and typemap[pos] != str:
 
   97                    line += str(last[pos]) + 
',\t' 
  100                      line += 
'"' + str(last[pos]) + 
'",\t' 
  102                      line += 
'"' + e + 
'",\t' 
  106        fp.write(line[:-2] + 
'},\n')
 
  110def update_lang_identifiers(fp):
 
  112    write_struct(fp, 
'LanguageIdentifier', 
'language_identifiers', 
'https://docs.microsoft.com/en-us/windows/win32/intl/language-identifier-constants-and-strings', 16, 
False, [int, str, int, str, str, int, str])
 
  114def update_code_pages(fp):
 
  115    write_struct(fp, 
'CodePage', 
'code_pages', 
'https://docs.microsoft.com/en-us/windows/win32/intl/code-page-identifiers', 10)
 
  117def update_input_locales(fp):
 
  118    write_struct(fp, 
'KeyboardIdentifier', 
'keyboard_identifiers', 
'https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-vista/cc766503(v=ws.10)', 0)
 
  119    write_struct(fp, 
'RDP_KEYBOARD_LAYOUT', 
'RDP_KEYBOARD_LAYOUT_TABLE', 
'https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/windows-language-pack-default-values', 16, 
True)
 
  122    with open(
'language_identifiers.c', 
'w') 
as fp:
 
  124        update_lang_identifiers(fp)
 
  125        update_code_pages(fp)
 
  126        update_input_locales(fp)
 
  128    print(
'exception cought')
 
  129    traceback.print_exc()