From 0a624ee7dc62a19d28651542f2c627b6de9a18d7 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 30 Jul 2022 13:29:26 +0200 Subject: gnulib-tool.py: Assume Python 3. * gnulib-tool.py: Don't allow 'bytes' as an alternative to 'str'. * pygnulib/*.py: Likewise. --- pygnulib/GLEmiter.py | 72 +++++++--------------------------------------------- 1 file changed, 9 insertions(+), 63 deletions(-) (limited to 'pygnulib/GLEmiter.py') diff --git a/pygnulib/GLEmiter.py b/pygnulib/GLEmiter.py index 64b58eb92a..1d81be84cd 100644 --- a/pygnulib/GLEmiter.py +++ b/pygnulib/GLEmiter.py @@ -47,7 +47,6 @@ __copyright__ = constants.__copyright__ NoneType = type(None) APP = constants.APP DIRS = constants.DIRS -ENCS = constants.ENCS UTILS = constants.UTILS MODES = constants.MODES TESTS = constants.TESTS @@ -108,8 +107,6 @@ class GLEmiter(object): # the same distribution terms as the rest of that program. # # Generated by gnulib-tool.\n""" - if type(emit) is bytes: - emit = emit.decode(ENCS['default']) return constants.nlconvert(emit) def autoconfSnippet(self, module, fileassistant, toplevel, @@ -148,10 +145,7 @@ class GLEmiter(object): if type(disable_gettext) is not bool: raise TypeError('disable_gettext must be a bool, not %s' % type(disable_gettext).__name__) - if type(indentation) is bytes or type(indentation) is str: - if type(indentation) is bytes: - indentation = indentation.decode(ENCS['default']) - else: # if indentation has not bytes or str type + if type(indentation) is not str: raise TypeError('indentation must be a string, not %s' % type(indentation).__name__) if not indentation.isspace(): @@ -208,8 +202,6 @@ add AM_GNU_GETTEXT([external]) or similar to configure.ac.') lines = [line for line in emit.split('\n') if line.strip()] emit = '%s\n' % '\n'.join(lines) emit = constants.nlconvert(emit) - if type(emit) is bytes: - emit = emit.decode(ENCS['default']) return emit def autoconfSnippets(self, modules, moduletable, fileassistant, @@ -366,8 +358,6 @@ add AM_GNU_GETTEXT([external]) or similar to configure.ac.') lines = [line for line in emit.split('\n') if line.strip()] emit = '%s\n' % '\n'.join(lines) emit = constants.nlconvert(emit) - if type(emit) is bytes: - emit = emit.decode(ENCS['default']) return emit def preEarlyMacros(self, require, indentation, modules): @@ -457,8 +447,6 @@ EXTRA_LOCALE_CATEGORIES = # package uses functions taking also a message context, like pgettext(), or # if in $(XGETTEXT_OPTIONS) you define keywords with a context argument. USE_MSGCTXT = no\n""" - if type(emit) is bytes: - emit = emit.decode(ENCS['default']) return constants.nlconvert(emit) def po_POTFILES_in(self, files): @@ -469,8 +457,6 @@ USE_MSGCTXT = no\n""" emit = '' sourcebase = self.config['sourcebase'] sourcebase = '%s%s' % (self.sourcebase, os.path.sep) - if type(sourcebase) is bytes: - sourcebase = sourcebase.decode(ENCS['default']) files = [substart('lib/', sourcebase, file) for file in files] files = [file for file in files if file.startswith(sourcebase)] emit += "## DO NOT EDIT! GENERATED AUTOMATICALLY!\n" @@ -478,8 +464,6 @@ USE_MSGCTXT = no\n""" emit += "# List of files which contain translatable strings.\n" emit += '\n'.join(files) emit += '\n' - if type(emit) is bytes: - emit = emit.decode(ENCS['default']) return constants.nlconvert(emit) def initmacro_start(self, macro_prefix_arg): @@ -487,10 +471,7 @@ USE_MSGCTXT = no\n""" Emit the first few statements of the gl_INIT macro.''' emit = '' - if type(macro_prefix_arg) is bytes or type(macro_prefix_arg) is str: - if type(macro_prefix_arg) is bytes: - macro_prefix_arg = macro_prefix_arg.decode(ENCS['default']) - else: # if macro_prefix_arg has not bytes or str type + if type(macro_prefix_arg) is not str: raise TypeError('macro_prefix_arg must be a string, not %s' % type(macro_prefix_arg).__name__) module_indicator_prefix = self.config.getModuleIndicatorPrefix() @@ -530,8 +511,6 @@ USE_MSGCTXT = no\n""" emit += " [" + module_indicator_prefix + "])" emit += " gl_COMMON\n" emit = emit.replace('%V1%', macro_prefix_arg) - if type(emit) is bytes: - emit = emit.decode(ENCS['default']) return constants.nlconvert(emit) def initmacro_end(self, macro_prefix_arg): @@ -539,10 +518,7 @@ USE_MSGCTXT = no\n""" Emit the last few statements of the gl_INIT macro.''' emit = '' - if type(macro_prefix_arg) is bytes or type(macro_prefix_arg) is str: - if type(macro_prefix_arg) is bytes: - macro_prefix_arg = macro_prefix_arg.decode(ENCS['default']) - else: # if macro_prefix_arg has not bytes or str type + if type(macro_prefix_arg) is not str: raise TypeError('macro_prefix_arg must be a string, not %s' % type(macro_prefix_arg).__name__) # Check the presence of files that are mentioned as AC_LIBSOURCES @@ -585,8 +561,6 @@ found])]) AC_SUBST([%V1%_LTLIBOBJS], [$%V1%_ltlibobjs]) ])\n""" emit = emit.replace('%V1%', macro_prefix_arg) - if type(emit) is bytes: - emit = emit.decode(ENCS['default']) return constants.nlconvert(emit) def initmacro_done(self, macro_prefix_arg, sourcebase_arg): @@ -595,16 +569,10 @@ found])]) Emit a few statements after the gl_INIT macro. GLConfig: sourcebase.''' emit = '' - if type(macro_prefix_arg) is bytes or type(macro_prefix_arg) is str: - if type(macro_prefix_arg) is bytes: - macro_prefix_arg = macro_prefix_arg.decode(ENCS['default']) - else: # if macro_prefix_arg has not bytes or str type + if type(macro_prefix_arg) is not str: raise TypeError('macro_prefix_arg must be a string, not %s' % type(macro_prefix_arg).__name__) - if type(sourcebase_arg) is bytes or type(sourcebase_arg) is str: - if type(sourcebase_arg) is bytes: - sourcebase_arg = sourcebase_arg.decode(ENCS['default']) - else: # if sourcebase_arg has not bytes or str type + if type(sourcebase_arg) is not str: raise TypeError('sourcebase_arg must be a string, not %s' % type(sourcebase_arg).__name__) emit += """\ @@ -637,8 +605,6 @@ AC_DEFUN([%V1%_LIBSOURCES], [ ])\n""" emit = emit.replace('%V1%', macro_prefix_arg) emit = emit.replace('%V2%', sourcebase_arg) - if type(emit) is bytes: - emit = emit.decode(ENCS['default']) return constants.nlconvert(emit) def lib_Makefile_am(self, destfile, modules, @@ -659,10 +625,7 @@ AC_DEFUN([%V1%_LIBSOURCES], [ an empty string e.g. when user wants to generate files for GLTestDir. for_test is a bool variable; it must be set to True if creating a package for testing, False otherwise.''' - if type(destfile) is bytes or type(destfile) is str: - if type(destfile) is bytes: - destfile = destfile.decode(ENCS['default']) - else: # if destfile has not bytes or str type + if type(destfile) is not str: raise TypeError('destfile must be a string, not %s' % type(destfile).__name__) for module in modules: @@ -674,10 +637,7 @@ AC_DEFUN([%V1%_LIBSOURCES], [ if type(makefiletable) is not GLMakefileTable: raise TypeError('makefiletable must be a GLMakefileTable, not %s' % type(makefiletable).__name__) - if type(actioncmd) is bytes or type(actioncmd) is str: - if type(actioncmd) is bytes: - actioncmd = actioncmd.decode(ENCS['default']) - else: # if actioncmd has not bytes or str type + if type(actioncmd) is not str: raise TypeError('actioncmd must be a string, not %s' % type(actioncmd).__name__) if type(for_test) is not bool: @@ -776,10 +736,6 @@ AC_DEFUN([%V1%_LIBSOURCES], [ (libname, libext), amsnippet2) amsnippet2 = amsnippet2.replace( '$(GNULIB_', '$(' + module_indicator_prefix + '_GNULIB_') - if type(amsnippet1) is bytes: - amsnippet1 = amsnippet1.decode(ENCS['default']) - if type(amsnippet2) is bytes: - amsnippet2 = amsnippet1.decode(ENCS['default']) if not (amsnippet1 + amsnippet2).isspace(): allsnippets += '## begin gnulib module %s\n' % str(module) if conddeps: @@ -928,8 +884,6 @@ AC_DEFUN([%V1%_LIBSOURCES], [ emit += '\tdone; \\\n' emit += '\t:\n' emit = constants.nlconvert(emit) - if type(emit) is bytes: - emit = emit.decode(ENCS['default']) result = tuple([emit, uses_subdirs]) return result @@ -953,10 +907,7 @@ AC_DEFUN([%V1%_LIBSOURCES], [ an empty string e.g. when user wants to generate files for GLTestDir. for_test is a bool variable; it must be set to True if creating a package for testing, False otherwise.''' - if type(destfile) is bytes or type(destfile) is str: - if type(destfile) is bytes: - destfile = destfile.decode(ENCS['default']) - else: # if destfile has not bytes or str type + if type(destfile) is not str: raise TypeError('destfile must be a string, not %s' % type(destfile).__name__) for module in modules: @@ -965,10 +916,7 @@ AC_DEFUN([%V1%_LIBSOURCES], [ if type(makefiletable) is not GLMakefileTable: raise TypeError('makefiletable must be a GLMakefileTable, not %s' % type(makefiletable).__name__) - if type(witness_macro) is bytes or type(witness_macro) is str: - if type(witness_macro) is bytes: - witness_macro = witness_macro.decode(ENCS['default']) - else: # if witness_macro has not bytes or str type + if type(witness_macro) is not str: raise TypeError('witness_macro must be a string, not %s' % type(witness_macro).__name__) if type(for_test) is not bool: @@ -1217,7 +1165,5 @@ AC_DEFUN([%V1%_LIBSOURCES], [ emit += '\tdone; \\\n' emit += '\t:\n' emit = constants.nlconvert(emit) - if type(emit) is bytes: - emit = emit.decode(ENCS['default']) result = tuple([emit, uses_subdirs]) return result -- cgit v1.2.1