diff options
author | svidyuk <svidyuk@yandex-team.com> | 2022-12-16 07:54:23 +0300 |
---|---|---|
committer | svidyuk <svidyuk@yandex-team.com> | 2022-12-16 07:54:23 +0300 |
commit | fa371e5210e9cdda3fd6fc33af87a2458b69ab84 (patch) | |
tree | dd9dc9c6faa345bfa22c596f348d18846f81bd81 /library/cpp/tld/gen_tld.py | |
parent | a94445ea23010c0fccb3a231251d33cb69ac63d8 (diff) | |
download | ydb-fa371e5210e9cdda3fd6fc33af87a2458b69ab84.tar.gz |
Port gen_tld to py3
Diffstat (limited to 'library/cpp/tld/gen_tld.py')
-rwxr-xr-x | library/cpp/tld/gen_tld.py | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/library/cpp/tld/gen_tld.py b/library/cpp/tld/gen_tld.py index 882b701e1d..48a8f815d9 100755 --- a/library/cpp/tld/gen_tld.py +++ b/library/cpp/tld/gen_tld.py @@ -11,47 +11,47 @@ def main(): tlds[s] = list() tlds['xn--'] = list() - tld_file = open(sys.argv[1], 'r') + tld_file = open(sys.argv[1], 'rb') for line in tld_file.readlines(): domain = line.strip().lower() for label in tlds: - if domain.startswith('xn--'): + if domain.startswith(b'xn--'): tlds['xn--'].append(domain) break - elif domain.startswith('x'): + elif domain.startswith(b'x'): tlds['x'].append(domain) break else: - if domain.startswith(label): + if domain.startswith(label.encode('utf-8')): tlds[label].append(domain) break - print '// actual list can be found at http://data.iana.org/TLD/tlds-alpha-by-domain.txt' - print 'static const char* const TopLevelDomains[] = {' + print('// actual list can be found at http://data.iana.org/TLD/tlds-alpha-by-domain.txt') + print('static const char* const TopLevelDomains[] = {') - for label, value in sorted(tlds.iteritems()): + for label, value in sorted(tlds.items()): if label == 'xn--': sys.stdout.write(' /* ') str = '' for n in value: - unicode_domain = n.decode('idna').encode('utf-8') + unicode_domain = n.decode('idna') str += ('%s, ' % unicode_domain) sys.stdout.write('%s*/\n' % str.rstrip()) sys.stdout.write(' ') str = '' for n in value: - str += ('"%s", ' % n) + str += ('"%s", ' % n.decode('utf-8')) sys.stdout.write('%s\n' % str.rstrip()) else: sys.stdout.write(' ') str = '' for n in value: - str += ('"%s", ' % n) + str += ('"%s", ' % n.decode('utf-8')) sys.stdout.write('%s\n' % str.rstrip()) - print ' 0' - print '};' + print(' 0') + print('};') if __name__ == '__main__': main() |