components/language/content/browser/ulp_language_code_locator/ulp_serialized_to_static_c.py
def ReadSerializedData(input_path):
  """Read serialized ULP language quad tree"""

  with open(input_path, 'rb') as input_file:
    data = input_file.read()

  linebreak = data.index(b'\n')
  # First line is comma-separated list of languages.
  language_codes = data[:linebreak].strip().decode(encoding="utf-8").split(',')
  # Rest of the file is the serialized tree.
  tree_bytes = data[linebreak+1:]

  # Strings are read in Python 2 so we need to use ord() to convert to bytes.
  to_bytes = ord if sys.version_info.major == 2 else lambda x: x

  # We group the bytes in the string into 32 bits integers.
  tree_serialized = [
    sum((to_bytes(tree_bytes[i+b]) << (8*b)) if i+b < len(tree_bytes) else 0
    for b in range(4))
    for i in range(0, len(tree_bytes), 4)
  ]
  return language_codes, tree_serialized
Read serialized ULP language quad tree
Read serialized ULP language quad tree
Read serialized ULP language quad tree
def ReadSerializedData(input_path):
  with open(input_path, 'rb') as input_file:
    data = input_file.read()
  linebreak = data.index(b'\n')
  language_codes = data[:linebreak].strip().decode(encoding="utf-8").split(',')
  tree_bytes = data[linebreak+1:]
  to_bytes = ord if sys.version_info.major == 2 else lambda x: x
  tree_serialized = [
    sum((to_bytes(tree_bytes[i+b]) << (8*b)) if i+b < len(tree_bytes) else 0
    for b in range(4))
    for i in range(0, len(tree_bytes), 4)
  ]
  return language_codes, tree_serialized
def ReadSerializedData ( input_path ) : with open ( input_path , 'rb' ) as input_file : data = input_file . read ( ) linebreak = data . index ( b'\n' ) language_codes = data [ : linebreak ] . strip ( ) . decode ( encoding = "utf-8" ) . split ( ',' ) tree_bytes = data [ linebreak + 1 : ] to_bytes = ord if sys . version_info . major == 2 else lambda x : x tree_serialized = [ sum ( ( to_bytes ( tree_bytes [ i + b ] ) << ( 8 * b ) ) if i + b < len ( tree_bytes ) else 0 for b in range ( 4 ) ) for i in range ( 0 , len ( tree_bytes ) , 4 ) ] return language_codes , tree_serialized
Read serialized ULP language quad tree
Read serialized ULP language quad tree
"""Read serialized ULP language quad tree""" # First line is comma-separated list of languages. # Rest of the file is the serialized tree. # Strings are read in Python 2 so we need to use ord() to convert to bytes. # We group the bytes in the string into 32 bits integers.
input_path