Use python 3 in ./tools/localedata/extract_icu_data.py

Bug: 232747988
Test: ./tools/localedata/extract_icu_data.py $ANDROID_BUILD_TOP > libs/androidfw/LocaleDataTables.cpp
Change-Id: Id253c31f2d9437f7dd247e094c9ee1fa006e9cff
diff --git a/tools/localedata/extract_icu_data.py b/tools/localedata/extract_icu_data.py
index ca1847a..81ac897 100755
--- a/tools/localedata/extract_icu_data.py
+++ b/tools/localedata/extract_icu_data.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 # Copyright 2016 The Android Open Source Project. All Rights Reserved.
 #
@@ -61,7 +61,7 @@
                           # would be chosen.)
         }
         for line in input_file:
-            line = unicode(line, 'UTF-8').strip(u' \n\uFEFF').encode('UTF-8')
+            line = line.strip(u' \n\uFEFF')
             if line.startswith('//'):
                 continue
             if '{' in line and '}' in line:
@@ -118,26 +118,26 @@
 
 def dump_script_codes(all_scripts):
     """Dump the SCRIPT_CODES table."""
-    print 'const char SCRIPT_CODES[][4] = {'
+    print('const char SCRIPT_CODES[][4] = {')
     for index, script in enumerate(all_scripts):
-        print "    /* %-2d */ {'%c', '%c', '%c', '%c'}," % (
-            index, script[0], script[1], script[2], script[3])
-    print '};'
-    print
+        print("    /* %-2d */ {'%c', '%c', '%c', '%c'}," % (
+            index, script[0], script[1], script[2], script[3]))
+    print('};')
+    print()
 
 
 def dump_script_data(likely_script_dict, all_scripts):
     """Dump the script data."""
-    print
-    print 'const std::unordered_map<uint32_t, uint8_t> LIKELY_SCRIPTS({'
+    print()
+    print('const std::unordered_map<uint32_t, uint8_t> LIKELY_SCRIPTS({')
     for locale in sorted(likely_script_dict.keys()):
         script = likely_script_dict[locale]
-        print '    {0x%08Xu, %2du}, // %s -> %s' % (
+        print('    {0x%08Xu, %2du}, // %s -> %s' % (
             pack_to_uint32(locale),
             all_scripts.index(script),
             locale.replace('_', '-'),
-            script)
-    print '});'
+            script))
+    print('});')
 
 
 def pack_to_uint64(locale):
@@ -152,13 +152,13 @@
 
 def dump_representative_locales(representative_locales):
     """Dump the set of representative locales."""
-    print
-    print 'std::unordered_set<uint64_t> REPRESENTATIVE_LOCALES({'
+    print()
+    print('std::unordered_set<uint64_t> REPRESENTATIVE_LOCALES({')
     for locale in sorted(representative_locales):
-        print '    0x%08XLLU, // %s' % (
+        print('    0x%08XLLU, // %s' % (
             pack_to_uint64(locale),
-            locale)
-    print '});'
+            locale))
+    print('});')
 
 
 def read_and_dump_likely_data(icu_data_dir):
@@ -220,30 +220,30 @@
 def dump_parent_data(script_organized_dict):
     """Dump information for parents of locales."""
     sorted_scripts = sorted(script_organized_dict.keys())
-    print
+    print()
     for script in sorted_scripts:
         parent_dict = script_organized_dict[script]
         print ('const std::unordered_map<uint32_t, uint32_t> %s_PARENTS({'
             % escape_script_variable_name(script.upper()))
         for locale in sorted(parent_dict.keys()):
             parent = parent_dict[locale]
-            print '    {0x%08Xu, 0x%08Xu}, // %s -> %s' % (
+            print('    {0x%08Xu, 0x%08Xu}, // %s -> %s' % (
                 pack_to_uint32(locale),
                 pack_to_uint32(parent),
                 locale.replace('_', '-'),
-                parent.replace('_', '-'))
-        print '});'
-        print
+                parent.replace('_', '-')))
+        print('});')
+        print()
 
-    print 'const struct {'
-    print '    const char script[4];'
-    print '    const std::unordered_map<uint32_t, uint32_t>* map;'
-    print '} SCRIPT_PARENTS[] = {'
+    print('const struct {')
+    print('    const char script[4];')
+    print('    const std::unordered_map<uint32_t, uint32_t>* map;')
+    print('} SCRIPT_PARENTS[] = {')
     for script in sorted_scripts:
-        print "    {{'%c', '%c', '%c', '%c'}, &%s_PARENTS}," % (
+        print("    {{'%c', '%c', '%c', '%c'}, &%s_PARENTS}," % (
             script[0], script[1], script[2], script[3],
-            escape_script_variable_name(script.upper()))
-    print '};'
+            escape_script_variable_name(script.upper())))
+    print('};')
 
 
 def dump_parent_tree_depth(parent_dict):
@@ -256,8 +256,8 @@
             depth += 1
         max_depth = max(max_depth, depth)
     assert max_depth < 5 # Our algorithms assume small max_depth
-    print
-    print 'const size_t MAX_PARENT_DEPTH = %d;' % max_depth
+    print()
+    print('const size_t MAX_PARENT_DEPTH = %d;' % max_depth)
 
 
 def read_and_dump_parent_data(icu_data_dir, likely_script_dict):
@@ -281,8 +281,8 @@
         source_root,
         'external', 'icu', 'icu4c', 'source', 'data')
 
-    print '// Auto-generated by %s' % sys.argv[0]
-    print
+    print('// Auto-generated by %s' % sys.argv[0])
+    print()
     likely_script_dict = read_and_dump_likely_data(icu_data_dir)
     read_and_dump_parent_data(icu_data_dir, likely_script_dict)