>From 0a624ee7dc62a19d28651542f2c627b6de9a18d7 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 30 Jul 2022 13:29:26 +0200 Subject: [PATCH 3/4] gnulib-tool.py: Assume Python 3. * gnulib-tool.py: Don't allow 'bytes' as an alternative to 'str'. * pygnulib/*.py: Likewise. --- ChangeLog | 4 ++ gnulib-tool.py | 4 -- pygnulib/GLConfig.py | 125 ++++++++++++------------------------ pygnulib/GLEmiter.py | 72 +++------------------ pygnulib/GLError.py | 1 - pygnulib/GLFileSystem.py | 33 ++-------- pygnulib/GLImport.py | 19 ------ pygnulib/GLInfo.py | 1 - pygnulib/GLMakefileTable.py | 16 +---- pygnulib/GLModuleSystem.py | 31 ++------- pygnulib/GLTestDir.py | 31 ++------- pygnulib/constants.py | 32 +-------- 12 files changed, 74 insertions(+), 295 deletions(-) diff --git a/ChangeLog b/ChangeLog index bb5f09a1c4..f065ed9d4d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2022-07-30 Bruno Haible + gnulib-tool.py: Assume Python 3. + * gnulib-tool.py: Don't allow 'bytes' as an alternative to 'str'. + * pygnulib/*.py: Likewise. + gnulib-tool.py: Assume Python 3. * gnulib-tool.py: Don't set PYTHON3, string. Use str instead of string. * pygnulib/*.py: Likewise. diff --git a/gnulib-tool.py b/gnulib-tool.py index ae4a839da9..e36f84b6ab 100755 --- a/gnulib-tool.py +++ b/gnulib-tool.py @@ -867,10 +867,6 @@ def main(): dest = files[1] else: # if len(files) != 2 dest = '.' - if type(srcpath) is bytes: - srcpath = srcpath.decode(ENCS['default']) - if type(dest) is bytes: - dest = dest.decode(ENCS['default']) if not auxdir: auxdir = 'build-aux' if not sourcebase: diff --git a/pygnulib/GLConfig.py b/pygnulib/GLConfig.py index 8f6ca80be4..6f314be865 100644 --- a/pygnulib/GLConfig.py +++ b/pygnulib/GLConfig.py @@ -41,7 +41,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 @@ -394,12 +393,10 @@ class GLConfig(object): def setDestDir(self, destdir): '''Specify the target directory. For --import, this specifies where your configure.ac can be found. Defaults to current directory.''' - if type(destdir) is bytes or type(destdir) is str: - if type(destdir) is bytes: - destdir = str(destdir, ENCS['system']) + if type(destdir) is str: if destdir: self.table['destdir'] = os.path.normpath(destdir) - else: # if destdir has not bytes/str type + else: # if destdir has not str type raise TypeError('destdir must be a string, not %s' % type(destdir).__name__) @@ -417,12 +414,10 @@ class GLConfig(object): def setLocalDir(self, localdir): '''Specify a local override directory where to look up files before looking in gnulib's directory.''' - if type(localdir) is bytes or type(localdir) is str: - if type(localdir) is bytes: - localdir = str(localdir, ENCS['system']) + if type(localdir) is str: if localdir: self.table['localdir'] = localdir - else: # if localdir has not bytes/str type + else: # if localdir has not str type raise TypeError('localdir must be a string, not %s' % type(localdir).__name__) @@ -442,12 +437,10 @@ class GLConfig(object): def setAuxDir(self, auxdir): '''Specify directory relative to --dir where auxiliary build tools are placed. Default comes from configure.ac or configure.in.''' - if type(auxdir) is bytes or type(auxdir) is str: - if type(auxdir) is bytes: - auxdir = str(auxdir, ENCS['system']) + if type(auxdir) is str: if auxdir: self.table['auxdir'] = auxdir - else: # if type of auxdir is not bytes or str + else: # if type of auxdir is not str raise TypeError('auxdir must be a string, not %s' % type(auxdir).__name__) @@ -463,12 +456,10 @@ class GLConfig(object): def setSourceBase(self, sourcebase): '''Specify directory relative to destdir where source code is placed.''' - if type(sourcebase) is bytes or type(sourcebase) is str: - if type(sourcebase) is bytes: - sourcebase = str(sourcebase, ENCS['system']) + if type(sourcebase) is str: if sourcebase: self.table['sourcebase'] = sourcebase - else: # if type of sourcebase is not bytes or str + else: # if type of sourcebase is not str raise TypeError('sourcebase must be a string, not %s' % type(sourcebase).__name__) @@ -483,12 +474,10 @@ class GLConfig(object): def setM4Base(self, m4base): '''Specify directory relative to destdir where *.m4 macros are placed.''' - if type(m4base) is bytes or type(m4base) is str: - if type(m4base) is bytes: - m4base = str(m4base, ENCS['system']) + if type(m4base) is str: if m4base: self.table['m4base'] = m4base - else: # if type of m4base is not bytes or str + else: # if type of m4base is not str raise TypeError('m4base must be a string, not %s' % type(m4base).__name__) @@ -503,12 +492,10 @@ class GLConfig(object): def setPoBase(self, pobase): '''Specify directory relative to destdir where *.po files are placed.''' - if type(pobase) is bytes or type(pobase) is str: - if type(pobase) is bytes: - pobase = str(pobase, ENCS['system']) + if type(pobase) is str: if pobase: self.table['pobase'] = pobase - else: # if type of pobase is not bytes or str + else: # if type of pobase is not str raise TypeError('pobase must be a string, not %s' % type(pobase).__name__) @@ -525,12 +512,10 @@ class GLConfig(object): def setDocBase(self, docbase): '''Specify directory relative to destdir where doc files are placed. Default value for this variable is 'doc').''' - if type(docbase) is bytes or type(docbase) is str: - if type(docbase) is bytes: - docbase = str(docbase, ENCS['system']) + if type(docbase) is str: if docbase: self.table['docbase'] = docbase - else: # if type of docbase is not bytes or str + else: # if type of docbase is not str raise TypeError('docbase must be a string, not %s' % type(docbase).__name__) @@ -548,12 +533,10 @@ class GLConfig(object): def setTestsBase(self, testsbase): '''Specify directory relative to destdir where unit tests are placed. Default value for this variable is 'tests').''' - if type(testsbase) is bytes or type(testsbase) is str: - if type(testsbase) is bytes: - testsbase = str(testsbase, ENCS['system']) + if type(testsbase) is str: if testsbase: self.table['testsbase'] = testsbase - else: # if type of testsbase is not bytes or str + else: # if type of testsbase is not str raise TypeError('testsbase must be a string, not %s' % type(testsbase).__name__) @@ -565,23 +548,19 @@ class GLConfig(object): # Define modules methods. def addModule(self, module): '''Add the module to the modules list.''' - if type(module) is bytes or type(module) is str: - if type(module) is bytes: - module = module.decode(ENCS['default']) + if type(module) is str: if module not in self.table['modules']: self.table['modules'] += [module] - else: # if module has not bytes or str type + else: # if module has not str type raise TypeError('module must be a string, not %s' % type(module).__name__) def removeModule(self, module): '''Remove the module from the modules list.''' - if type(module) is bytes or type(module) is str: - if type(module) is bytes: - module = module.decode(ENCS['default']) + if type(module) is str: if module in self.table['modules']: self.table['modules'].remove(module) - else: # if module has not bytes or str type + else: # if module has not str type raise TypeError('module must be a string, not %s' % type(module).__name__) @@ -615,23 +594,19 @@ class GLConfig(object): def addAvoid(self, module): '''Avoid including the given module. Useful if you have code that provides equivalent functionality.''' - if type(module) is bytes or type(module) is str: - if type(module) is bytes: - module = module.decode(ENCS['default']) + if type(module) is str: if module not in self.table['avoids']: self.table['avoids'].append(module) - else: # if module has not bytes or str type + else: # if module has not str type raise TypeError('avoid must be a string, not %s' % type(module).__name__) def removeAvoid(self, module): '''Remove the given module from the list of avoided modules.''' - if type(module) is bytes or type(module) is str: - if type(module) is bytes: - module = module.decode(ENCS['default']) + if type(module) is str: if module in self.table['avoids']: self.table['avoids'].remove(module) - else: # if module has not bytes or str type + else: # if module has not str type raise TypeError('avoid must be a string, not %s' % type(module).__name__) @@ -664,23 +639,19 @@ class GLConfig(object): # Define files methods. def addFile(self, file): '''Add file to the list of files.''' - if type(file) is bytes or type(file) is str: - if type(file) is bytes: - file = file.decode(ENCS['default']) + if type(file) is str: if file not in self.table['files']: self.table['files'].append(file) - else: # if file has not bytes or str type + else: # if file has not str type raise TypeError('file must be a string, not %s' % type(file).__name__) def removeFile(self, file): '''Remove the given file from the list of files.''' - if type(file) is bytes or type(file) is str: - if type(file) is bytes: - file = file.decode(ENCS['default']) + if type(file) is str: if file in self.table['files']: self.table['files'].remove(file) - else: # if file has not bytes or str type + else: # if file has not str type raise TypeError('file must be a string, not %s' % type(file).__name__) @@ -765,12 +736,10 @@ class GLConfig(object): def setLibName(self, libname): '''Specify the library name.''' - if type(libname) is bytes or type(libname) is str: - if type(libname) is bytes: - libname = str(libname, ENCS['system']) + if type(libname) is str: if libname: self.table['libname'] = libname - else: # if type of libname is not bytes or str + else: # if type of libname is not str raise TypeError('libname must be a string, not %s' % type(module).__name__) @@ -848,20 +817,16 @@ class GLConfig(object): def setMacroPrefix(self, macro_prefix): '''Specify the prefix of the macros 'gl_EARLY' and 'gl_INIT'. Default macro_prefix is 'gl'.''' - if type(macro_prefix) is bytes or type(macro_prefix) is str: - if type(macro_prefix) is bytes: - macro_prefix = str(macro_prefix, ENCS['system']) + if type(macro_prefix) is str: if macro_prefix: self.table['macro_prefix'] = macro_prefix - else: # if type of macro_prefix is not bytes or str + else: # if type of macro_prefix is not str raise TypeError('macro_prefix must be a string, not %s' % type(macro_prefix).__name__) if macro_prefix == 'gl': include_guard_prefix = 'GL' else: # macro_prefix != 'gl' include_guard_prefix = 'GL_%s' % macro_prefix.upper() - if type(include_guard_prefix) is bytes: - include_guard_prefix = include_guard_prefix.decode(ENCS['default']) self.table['include_guard_prefix'] = include_guard_prefix def resetMacroPrefix(self): @@ -869,8 +834,6 @@ class GLConfig(object): Default macro_prefix is 'gl'.''' self.table['macro_prefix'] = 'gl' include_guard_prefix = 'GL' - if type(include_guard_prefix) is bytes: - include_guard_prefix = include_guard_prefix.decode(ENCS['default']) self.table['include_guard_prefix'] = include_guard_prefix # Define makefile methods. @@ -882,12 +845,10 @@ class GLConfig(object): def setMakefile(self, makefile): '''Specify the name of makefile in automake syntax in the source-base and tests-base directories. Default is 'Makefile.am'.''' - if type(makefile) is bytes or type(makefile) is str: - if type(makefile) is bytes: - makefile = str(makefile, ENCS['system']) + if type(makefile) is str: if makefile: self.table['makefile'] = makefile - else: # if type of makefile is not bytes or str + else: # if type of makefile is not str raise TypeError('makefile must be a string, not %s' % type(makefile).__name__) @@ -905,12 +866,10 @@ class GLConfig(object): def setPoDomain(self, podomain): '''Specify the prefix of the i18n domain. Usually use the package name. A suffix '-gnulib' is appended.''' - if type(podomain) is bytes or type(podomain) is str: - if type(podomain) is bytes: - podomain = str(podomain, ENCS['system']) + if type(podomain) is str: if podomain: self.table['podomain'] = podomain - else: # if type of podomain is not bytes or str + else: # if type of podomain is not str raise TypeError('podomain must be a string, not %s' % type(podomain).__name__) @@ -928,12 +887,10 @@ class GLConfig(object): def setWitnessCMacro(self, witness_c_macro): '''Specify the C macro that is defined when the sources in this directory are compiled or used.''' - if type(witness_c_macro) is bytes or type(witness_c_macro) is str: - if type(witness_c_macro) is bytes: - witness_c_macro = str(witness_c_macro, ENCS['system']) + if type(witness_c_macro) is str: if witness_c_macro: self.table['witness_c_macro'] = witness_c_macro - else: # if type of witness_c_macro is not bytes or str + else: # if type of witness_c_macro is not str raise TypeError('witness_c_macro must be a string, not %s' % type(witness_c_macro).__name__) @@ -983,13 +940,11 @@ class GLConfig(object): def setAutoconfFile(self, configure_ac): '''Specify path of autoconf file relative to destdir.''' - if type(configure_ac) is bytes or type(configure_ac) is str: - if type(configure_ac) is bytes: - configure_ac = str(configure_ac, ENCS['system']) + if type(configure_ac) is str: if configure_ac: self.table['configure_ac'] = \ relpath(self.table['destdir'], configure_ac) - else: # if type of configure_ac is not bytes or str + else: # if type of configure_ac is not str raise TypeError('configure_ac must be a string, not %s' % type(configure_ac).__name__) 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 diff --git a/pygnulib/GLError.py b/pygnulib/GLError.py index 5c1f9a72c3..0382035427 100644 --- a/pygnulib/GLError.py +++ b/pygnulib/GLError.py @@ -38,7 +38,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 diff --git a/pygnulib/GLFileSystem.py b/pygnulib/GLFileSystem.py index 0aaf0e5965..4660dabdee 100644 --- a/pygnulib/GLFileSystem.py +++ b/pygnulib/GLFileSystem.py @@ -42,7 +42,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 @@ -86,10 +85,7 @@ class GLFileSystem(object): GLError telling that file was not found. Function also returns flag which indicates whether file is a temporary file. GLConfig: localdir.''' - if type(name) is bytes or type(name) is str: - if type(name) is bytes: - name = name.decode(ENCS['default']) - else: # if name has not bytes or str type + if type(name) is not str: raise TypeError( 'name must be a string, not %s' % type(module).__name__) # If name exists in localdir, then we use it @@ -141,10 +137,7 @@ class GLFileAssistant(object): transformers[key] = 's,x,x,' else: # if key in transformers value = transformers[key] - if type(value) is bytes or type(value) is str: - if type(value) is bytes: - transformers[key] = value.decode(ENCS['default']) - else: # if value has not bytes or str type + if type(value) is not str: raise TypeError('transformers[%s] must be a string, not %s' % (key, type(value).__name__)) self.original = None @@ -164,10 +157,7 @@ class GLFileAssistant(object): '''GLFileAssistant.tmpfilename() -> str Return the name of a temporary file (file is relative to destdir).''' - if type(path) is bytes or type(path) is str: - if type(path) is bytes: - path = path.decode(ENCS['default']) - else: # if path has not bytes or str type + if type(path) is not str: raise TypeError( 'path must be a string, not %s' % (type(path).__name__)) if not self.config['dryrun']: @@ -185,18 +175,13 @@ class GLFileAssistant(object): dirname = os.path.dirname(result) if not isdir(dirname): os.makedirs(dirname) - if type(result) is bytes: - result = bytes.decode(ENCS['default']) return result def setOriginal(self, original): '''GLFileAssistant.setOriginal(original) Set the name of the original file which will be used.''' - if type(original) is bytes or type(original) is str: - if type(original) is bytes: - original = original.decode(ENCS['default']) - else: # if original has not bytes or str type + if type(original) is not str: raise TypeError( 'original must be a string, not %s' % (type(original).__name__)) self.original = original @@ -205,10 +190,7 @@ class GLFileAssistant(object): '''GLFileAssistant.setRewritten(rewritten) Set the name of the rewritten file which will be used.''' - if type(rewritten) is bytes or type(rewritten) is str: - if type(rewritten) is bytes: - rewritten = rewritten.decode(ENCS['default']) - else: # if rewritten has not bytes or str type + if type(rewritten) is not str: raise TypeError( 'rewritten must be a string, not %s' % type(rewritten).__name__) self.rewritten = rewritten @@ -276,10 +258,7 @@ class GLFileAssistant(object): raise TypeError('original must be set before applying the method') elif rewritten == None: raise TypeError('rewritten must be set before applying the method') - if type(lookedup) is bytes or type(lookedup) is str: - if type(lookedup) is bytes: - lookedup = lookedup.decode(ENCS['default']) - else: # if lookedup has not bytes or str type + if type(lookedup) is not str: raise TypeError('lookedup must be a string, not %s' % type(lookedup).__name__) if type(already_present) is not bool: diff --git a/pygnulib/GLImport.py b/pygnulib/GLImport.py index 0a58a0833b..dd3b739571 100644 --- a/pygnulib/GLImport.py +++ b/pygnulib/GLImport.py @@ -50,7 +50,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 @@ -294,12 +293,6 @@ class GLImport(object): if type(files) is not list: raise TypeError( 'files argument must has list type, not %s' % type(files).__name__) - files = \ - [ # Begin to convert bytes to string - file.decode(ENCS['default']) \ - if type(file) is bytes else file \ - for file in files - ] # Finish to convert bytes to string for file in files: if type(file) is not str: raise TypeError('each file must be a string instance') @@ -341,12 +334,6 @@ class GLImport(object): if type(files) is not list: raise TypeError( 'files argument must has list type, not %s' % type(files).__name__) - files = \ - [ # Begin to convert bytes to string - file.decode(ENCS['default']) \ - if type(file) is bytes else file \ - for file in files - ] # Finish to convert bytes to string for file in files: if type(file) is not str: raise TypeError('each file must be a string instance') @@ -543,8 +530,6 @@ gnulib-tool.m4 macro invocations:\n''' % actioncmd emit += 'gl_WITNESS_C_MACRO([%s])\n' % witness_c_macro if vc_files: emit += 'gl_VC_FILES([%s])\n' % vc_files - if type(emit) is bytes: - emit = emit.decode(ENCS['default']) return constants.nlconvert(emit) def gnulib_comp(self, files): @@ -688,8 +673,6 @@ abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ | LC_ALL=C sed -e \ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix emit += ' %s\n' % '\n '.join(files) emit += '])\n' - if type(emit) is bytes: - emit = emit.decode(ENCS['default']) return emit def _done_dir_(self, directory, dirs_added, dirs_removed): @@ -1227,8 +1210,6 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix data = '# Set of available languages.\n' files = [constants.subend('.po', '', file) for file in os.listdir(joinpath(destdir, pobase))] - files = [file.decode(ENCS['default']) if type(file) is bytes - else file for file in files] data += '\n'.join(files) with codecs.open(tmpfile, 'wb', 'UTF-8') as file: file.write(data) diff --git a/pygnulib/GLInfo.py b/pygnulib/GLInfo.py index 347d7a4cc9..6ee1891886 100644 --- a/pygnulib/GLInfo.py +++ b/pygnulib/GLInfo.py @@ -39,7 +39,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 diff --git a/pygnulib/GLMakefileTable.py b/pygnulib/GLMakefileTable.py index c535180f1f..95ceeeee63 100644 --- a/pygnulib/GLMakefileTable.py +++ b/pygnulib/GLMakefileTable.py @@ -42,7 +42,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 @@ -87,22 +86,13 @@ class GLMakefileTable(object): This method is used to remember that ${dir}Makefile.am needs to be edited to that ${var} mentions ${val}.''' - if type(dir) is bytes or type(dir) is str: - if type(dir) is bytes: - dir = dir.decode(ENCS['default']) - else: # if dir has not bytes or str type + if type(dir) is not str: raise TypeError( 'dir must be a string, not %s' % (type(dir).__name__)) - if type(var) is bytes or type(var) is str: - if type(var) is bytes: - var = var.decode(ENCS['default']) - else: # if var has not bytes or str type + if type(var) is not str: raise TypeError( 'var must be a string, not %s' % (type(var).__name__)) - if type(val) is bytes or type(val) is str: - if type(val) is bytes: - val = val.decode(ENCS['default']) - else: # if val has not bytes or str type + if type(val) is not str: raise TypeError( 'val must be a string, not %s' % (type(val).__name__)) dictionary = {'dir': dir, 'var': var, 'val': val} diff --git a/pygnulib/GLModuleSystem.py b/pygnulib/GLModuleSystem.py index 150499eca1..f2b7a9cf0d 100644 --- a/pygnulib/GLModuleSystem.py +++ b/pygnulib/GLModuleSystem.py @@ -87,10 +87,7 @@ class GLModuleSystem(object): Check whether the given module exists. GLConfig: localdir.''' - if type(module) is bytes or str: - if type(module) is bytes: - module = module.decode(ENCS['default']) - else: # if module has not bytes or str type + if type(module) is not str: raise TypeError( 'module must be a string, not %s' % type(module).__name__) result = bool() @@ -111,10 +108,7 @@ class GLModuleSystem(object): '''GLModuleSystem.find(module) -> GLModule Find the given module.''' - if type(module) is bytes or str: - if type(module) is bytes: - module = module.decode(ENCS['default']) - else: # if module has not bytes or str type + if type(module) is not str: raise TypeError( 'module must be a string, not %s' % type(module).__name__) if self.exists(module): @@ -205,10 +199,7 @@ class GLModule(object): if type(config) is not GLConfig: raise TypeError('config must be a GLConfig, not %s' % type(config).__name__) - if type(module) is bytes or type(module) is str: - if type(module) is bytes: - module = module.decode(ENCS['default']) - else: # if module has not bytes or str type + if type(module) is not str: raise TypeError('module must be a string, not %s' % type(module).__name__) if type(patched) is not bool: @@ -350,8 +341,6 @@ Include:|Link:|License:|Maintainer:)' module = module.encode(ENCS['default']) module = hashlib.md5(module).hexdigest() result = 'func_%s_gnulib_m4code_%s' % (macro_prefix, module) - if type(result) is bytes: - result = result.decode(ENCS['default']) return result def getShellVar(self): @@ -373,8 +362,6 @@ Include:|Link:|License:|Maintainer:)' module = module.encode(ENCS['default']) module = hashlib.md5(module).hexdigest() result = '%s_gnulib_enabled_%s' % (macro_prefix, module) - if type(result) is bytes: - result = result.decode(ENCS['default']) return result def getConditionalName(self): @@ -394,8 +381,6 @@ Include:|Link:|License:|Maintainer:)' conditional = '%s_GNULIB_ENABLED_%s' % (macro_prefix, name) else: # if not nonascii result = '%s_GNULIB_ENABLED_%s' % (macro_prefix, name) - if type(result) is bytes: - result = result.decode(ENCS['default']) return result def getDescription(self): @@ -521,8 +506,6 @@ Include:|Link:|License:|Maintainer:)' result = 'tests' else: # if not self.getName().endswith('-tests') result = 'main' - if type(result) is bytes: - result = result.decode(ENCS['default']) result = result.strip() self.cache['applicability'] = result return self.cache['applicability'] @@ -597,8 +580,6 @@ Include:|Link:|License:|Maintainer:)' else: # if len(split) != 1 module = split[0] condition = split[1] - if type(condition) is bytes: - condition = condition.decode(ENCS['default']) result += [tuple([self.modulesystem.find(module), condition])] self.cache['dependencies'] = result return list(self.cache['dependencies']) @@ -950,11 +931,7 @@ class GLModuleTable(object): if type(module) is not GLModule: raise TypeError('module must be a GLModule, not %s' % type(module).__name__) - if type(condition) is bytes or type(condition) is str \ - or condition == True: - if type(condition) is bytes: - condition = condition.decode(ENCS['default']) - else: # if condition has not bytes or str type or is not True + if not (type(condition) is str or condition == True): raise TypeError('condition must be a string or True, not %s' % type(condition).__name__) if not str(module) in self.unconditionals: diff --git a/pygnulib/GLTestDir.py b/pygnulib/GLTestDir.py index b8a7df43ce..6b2d45a493 100644 --- a/pygnulib/GLTestDir.py +++ b/pygnulib/GLTestDir.py @@ -50,7 +50,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 @@ -78,9 +77,9 @@ class GLTestDir(object): if type(config) is not GLConfig: raise TypeError('config must be a GLConfig, not %s' % type(config).__name__) - if type(testdir) is bytes or type(testdir) is str: - if type(testdir) is bytes: - testdir = testdir.decode(ENCS['default']) + if type(testdir) is not str: + raise TypeError('testdir must be a string, not %s' % + type(testdir).__name__) self.config = config self.testdir = os.path.normpath(testdir) if not os.path.exists(self.testdir): @@ -114,12 +113,6 @@ class GLTestDir(object): if type(files) is not list: raise TypeError( 'files argument must has list type, not %s' % type(files).__name__) - files = \ - [ # Begin to convert bytes to string - file.decode(ENCS['default']) \ - if type(file) is bytes else file \ - for file in files - ] # Finish to convert bytes to string for file in files: if type(file) is not str: raise TypeError('each file must be a string instance') @@ -383,8 +376,6 @@ class GLTestDir(object): file = constants.substart('m4/', '', file) emit += 'EXTRA_DIST += %s\n' % file emit = constants.nlconvert(emit) - if type(emit) is bytes: - emit = emit.decode(ENCS['default']) with codecs.open(destfile, 'wb', 'UTF-8') as file: file.write(emit) @@ -513,8 +504,6 @@ class GLTestDir(object): emit += 'AC_CONFIG_FILES([Makefile])\n' emit += 'AC_OUTPUT\n' emit = constants.nlconvert(emit) - if type(emit) is bytes: - emit = emit.decode(ENCS['default']) path = joinpath(self.testdir, testsbase, 'configure.ac') with codecs.open(path, 'wb', 'UTF-8') as file: file.write(emit) @@ -533,8 +522,6 @@ class GLTestDir(object): emit += 'SUBDIRS = %s\n\n' % ' '.join(subdirs) emit += 'ACLOCAL_AMFLAGS = -I %s\n' % m4base emit = constants.nlconvert(emit) - if type(emit) is bytes: - emit = emit.decode(ENCS['default']) path = joinpath(self.testdir, 'Makefile.am') with codecs.open(path, 'wb', 'UTF-8') as file: file.write(emit) @@ -857,9 +844,9 @@ class GLMegaTestDir(object): if type(config) is not GLConfig: raise TypeError('config must be a GLConfig, not %s' % type(config).__name__) - if type(megatestdir) is bytes or type(megatestdir) is str: - if type(megatestdir) is bytes: - megatestdir = megatestdir.decode(ENCS['default']) + if type(megatestdir) is not str: + raise TypeError('megatestdir must be a string, not %s' % + type(megatestdir).__name__) self.config = config self.megatestdir = os.path.normpath(megatestdir) if not os.path.exists(self.megatestdir): @@ -947,8 +934,6 @@ class GLMegaTestDir(object): emit += 'sed -e "$AUTOBUILD_SUBST"; else cat; fi; } > logs/$safemodule\n' emit += 'done\n' emit = constants.nlconvert(emit) - if type(emit) is bytes: - emit = emit.decode(ENCS['default']) path = joinpath(self.megatestdir, 'do-autobuild') with codecs.open(path, 'wb', 'UTF-8') as file: file.write(emit) @@ -959,8 +944,6 @@ class GLMegaTestDir(object): emit += 'SUBDIRS = %s\n\n' % ' '.join(megasubdirs) emit += 'EXTRA_DIST = do-autobuild\n' emit = constants.nlconvert(emit) - if type(emit) is bytes: - emit = emit.decode(ENCS['default']) path = joinpath(self.megatestdir, 'Makefile.am') with codecs.open(path, 'wb', 'UTF-8') as file: file.write(emit) @@ -976,8 +959,6 @@ class GLMegaTestDir(object): emit += 'AC_CONFIG_FILES([Makefile])\n' emit += 'AC_OUTPUT\n' emit = constants.nlconvert(emit) - if type(emit) is bytes: - emit = emit.decode(ENCS['default']) path = joinpath(self.megatestdir, 'Makefile.am') with codecs.open(path, 'wb', 'UTF-8') as file: file.write(emit) diff --git a/pygnulib/constants.py b/pygnulib/constants.py index 8c3dfa4bd9..8fd982f7a7 100644 --- a/pygnulib/constants.py +++ b/pygnulib/constants.py @@ -77,10 +77,6 @@ APP['name'] = sys.argv[0] if not APP['name']: APP['name'] = 'gnulib-tool.py' APP['path'] = os.path.realpath(sys.argv[0]) -if type(APP['name']) is bytes: - APP['name'] = str(APP['name'], ENCS['system']) -if type(APP['path']) is bytes: - APP['path'] = str(APP['path'], ENCS['system']) # Set DIRS dictionary DIRS['root'] = os.path.dirname(APP['path']) @@ -223,8 +219,6 @@ def execute(args, verbose): # Commands like automake produce output to stderr even when they succeed. # Turn this output off if the command succeeds. temp = tempfile.mktemp() - if type(temp) is bytes: - temp = temp.decode(ENCS['system']) xargs = '%s > %s 2>&1' % (' '.join(args), temp) try: # Try to run retcode = sp.call(xargs, shell=True) @@ -271,25 +265,15 @@ def joinpath(head, *tail): component is an absolute path, all previous path components will be discarded. The second argument may be string or list of strings.''' newtail = list() - if type(head) is bytes: - head = head.decode(ENCS['default']) for item in tail: - if type(item) is bytes: - item = item.decode(ENCS['default']) newtail += [item] result = os.path.normpath(os.path.join(head, *tail)) - if type(result) is bytes: - result = result.decode(ENCS['default']) return result def relativize(dir1, dir2): '''Compute a relative pathname reldir such that dir1/reldir = dir2.''' dir0 = os.getcwd() - if type(dir1) is bytes: - dir1 = dir1.decode(ENCS['default']) - if type(dir2) is bytes: - dir2 = dir2.decode(ENCS['default']) while dir1: dir1 = '%s%s' % (os.path.normpath(dir1), os.path.sep) dir2 = '%s%s' % (os.path.normpath(dir2), os.path.sep) @@ -320,16 +304,10 @@ def relativize(dir1, dir2): def link_relative(src, dest): '''Like ln -s, except that src is given relative to the current directory (or absolute), not given relative to the directory of dest.''' - if type(src) is bytes or type(src) is str: - if type(src) is bytes: - src = src.decode(ENCS['default']) - else: # if src has not bytes or str type + if type(src) is not str: raise TypeError( 'src must be a string, not %s' % (type(src).__name__)) - if type(dest) is bytes or type(dest) is str: - if type(dest) is bytes: - dest = dest.decode(ENCS['default']) - else: # if dest has not bytes or str type + if type(dest) is not str: raise TypeError( 'dest must be a string, not %s' % (type(dest).__name__)) if src.startswith('/') or (len(src) >= 2 and src[1] == ':'): @@ -342,18 +320,12 @@ def link_relative(src, dest): destdir = os.path.dirname(dest) if not destdir: destdir = '.' - if type(destdir) is bytes: - destdir = destdir.decode(ENCS['default']) src = relativize(destdir, src) os.symlink(src, dest) def link_if_changed(src, dest): '''Create a symlink, but avoids munging timestamps if the link is correct.''' - if type(src) is bytes: - src = src.decode(ENCS['default']) - if type(dest) is bytes: - dest = dest.decode(ENCS['default']) ln_target = os.path.realpath(src) if not (os.path.islink(dest) and src == ln_target): os.remove(dest) -- 2.34.1