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 | |
parent | a94445ea23010c0fccb3a231251d33cb69ac63d8 (diff) | |
download | ydb-fa371e5210e9cdda3fd6fc33af87a2458b69ab84.tar.gz |
Port gen_tld to py3
Diffstat (limited to 'library/cpp/tld')
-rw-r--r-- | library/cpp/tld/CMakeLists.darwin.txt | 4 | ||||
-rw-r--r-- | library/cpp/tld/CMakeLists.linux-aarch64.txt | 4 | ||||
-rw-r--r-- | library/cpp/tld/CMakeLists.linux.txt | 4 | ||||
-rwxr-xr-x | library/cpp/tld/gen_tld.py | 24 |
4 files changed, 18 insertions, 18 deletions
diff --git a/library/cpp/tld/CMakeLists.darwin.txt b/library/cpp/tld/CMakeLists.darwin.txt index b741ac5298..a504a5819b 100644 --- a/library/cpp/tld/CMakeLists.darwin.txt +++ b/library/cpp/tld/CMakeLists.darwin.txt @@ -6,7 +6,7 @@ # original buildsystem will not be accepted. -find_package(Python2 REQUIRED) +find_package(Python3 REQUIRED) add_library(library-cpp-tld) target_link_libraries(library-cpp-tld PUBLIC @@ -25,7 +25,7 @@ add_custom_command( ${CMAKE_SOURCE_DIR}/library/cpp/tld/tlds-alpha-by-domain.txt ${CMAKE_SOURCE_DIR}/library/cpp/tld/gen_tld.py COMMAND - Python2::Interpreter + Python3::Interpreter ${CMAKE_SOURCE_DIR}/library/cpp/tld/gen_tld.py ${CMAKE_SOURCE_DIR}/library/cpp/tld/tlds-alpha-by-domain.txt > diff --git a/library/cpp/tld/CMakeLists.linux-aarch64.txt b/library/cpp/tld/CMakeLists.linux-aarch64.txt index 35b0b82159..511af10303 100644 --- a/library/cpp/tld/CMakeLists.linux-aarch64.txt +++ b/library/cpp/tld/CMakeLists.linux-aarch64.txt @@ -6,7 +6,7 @@ # original buildsystem will not be accepted. -find_package(Python2 REQUIRED) +find_package(Python3 REQUIRED) add_library(library-cpp-tld) target_link_libraries(library-cpp-tld PUBLIC @@ -26,7 +26,7 @@ add_custom_command( ${CMAKE_SOURCE_DIR}/library/cpp/tld/tlds-alpha-by-domain.txt ${CMAKE_SOURCE_DIR}/library/cpp/tld/gen_tld.py COMMAND - Python2::Interpreter + Python3::Interpreter ${CMAKE_SOURCE_DIR}/library/cpp/tld/gen_tld.py ${CMAKE_SOURCE_DIR}/library/cpp/tld/tlds-alpha-by-domain.txt > diff --git a/library/cpp/tld/CMakeLists.linux.txt b/library/cpp/tld/CMakeLists.linux.txt index 35b0b82159..511af10303 100644 --- a/library/cpp/tld/CMakeLists.linux.txt +++ b/library/cpp/tld/CMakeLists.linux.txt @@ -6,7 +6,7 @@ # original buildsystem will not be accepted. -find_package(Python2 REQUIRED) +find_package(Python3 REQUIRED) add_library(library-cpp-tld) target_link_libraries(library-cpp-tld PUBLIC @@ -26,7 +26,7 @@ add_custom_command( ${CMAKE_SOURCE_DIR}/library/cpp/tld/tlds-alpha-by-domain.txt ${CMAKE_SOURCE_DIR}/library/cpp/tld/gen_tld.py COMMAND - Python2::Interpreter + Python3::Interpreter ${CMAKE_SOURCE_DIR}/library/cpp/tld/gen_tld.py ${CMAKE_SOURCE_DIR}/library/cpp/tld/tlds-alpha-by-domain.txt > 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() |