From 572aa2d073c161a7c52b81c629c2d4ea7b62e7be Mon Sep 17 00:00:00 2001 From: Marko Petric <marko.petric@cern.ch> Date: Thu, 25 Jul 2019 13:59:47 +0200 Subject: [PATCH] Replaces all references to basestring with six.string_types --- DDG4/python/DDSim/DD4hepSimulation.py | 8 ++++---- DDG4/python/DDSim/Helper/Action.py | 3 ++- DDG4/python/DDSim/Helper/ConfigHelper.py | 4 ++-- DDG4/python/DDSim/Helper/Filter.py | 2 +- DDG4/python/DDSim/Helper/Gun.py | 3 ++- DDG4/python/DDSim/Helper/Physics.py | 3 ++- 6 files changed, 13 insertions(+), 10 deletions(-) diff --git a/DDG4/python/DDSim/DD4hepSimulation.py b/DDG4/python/DDSim/DD4hepSimulation.py index 13b61196f..378d3ba87 100644 --- a/DDG4/python/DDSim/DD4hepSimulation.py +++ b/DDG4/python/DDSim/DD4hepSimulation.py @@ -505,7 +505,7 @@ class DD4hepSimulation(object): """check if the fileName is allowed, note that the filenames are case sensitive, and in case of hepevt we depend on this to identify short and long versions of the content """ - if isinstance( fileNames, basestring ): + if isinstance( fileNames, six.string_types ): fileNames = [fileNames] if not all( fileName.endswith( extensions ) for fileName in fileNames ): self._errorMessages.append("ERROR: Unknown fileformat for file: %s" % fileNames) @@ -607,10 +607,10 @@ SIM = DD4hepSimulation() if opt.startswith("_"): continue parValue = optionsDict['default'] - if isinstance(optionsDict.get('help'), basestring): + if isinstance(optionsDict.get('help'), six.string_types): steeringFileBase += "\n## %s\n" % "\n## ".join(optionsDict.get('help').splitlines()) ## add quotes if it is a string - if isinstance( parValue, basestring ): + if isinstance( parValue, six.string_types ): steeringFileBase += "SIM.%s.%s = \"%s\"\n" %(parName, opt, parValue) else: steeringFileBase += "SIM.%s.%s = %s\n" %(parName, opt, parValue) @@ -620,7 +620,7 @@ SIM = DD4hepSimulation() if isinstance(optionObj, argparse._StoreAction ): steeringFileBase += "## %s\n" % "\n## ".join(optionObj.help.splitlines()) ## add quotes if it is a string - if isinstance(parameter, basestring): + if isinstance(parameter, six.string_types): steeringFileBase += "SIM.%s = \"%s\"" %( parName, str(parameter)) else: steeringFileBase += "SIM.%s = %s" %( parName, str(parameter)) diff --git a/DDG4/python/DDSim/Helper/Action.py b/DDG4/python/DDSim/Helper/Action.py index bc4ac3123..c2ffa45e1 100644 --- a/DDG4/python/DDSim/Helper/Action.py +++ b/DDG4/python/DDSim/Helper/Action.py @@ -4,6 +4,7 @@ from __future__ import absolute_import, unicode_literals from DDSim.Helper.ConfigHelper import ConfigHelper from six.moves import range +import six class Action( ConfigHelper ): """Action holding sensitive detector actions @@ -62,7 +63,7 @@ class Action( ConfigHelper ): self._mapActions.update(val) return - if isinstance(val, basestring): + if isinstance(val, six.string_types): vals = val.split(" ") elif isinstance( val, list ): vals = val diff --git a/DDG4/python/DDSim/Helper/ConfigHelper.py b/DDG4/python/DDSim/Helper/ConfigHelper.py index c4eb04718..f7a458a96 100644 --- a/DDG4/python/DDSim/Helper/ConfigHelper.py +++ b/DDG4/python/DDSim/Helper/ConfigHelper.py @@ -99,7 +99,7 @@ class ConfigHelper( object ): myTuple = val if isinstance( val, list ): myTuple = tuple(val) - if isinstance( val, basestring ): + if isinstance( val, six.string_types ): sep = ',' if ',' in val else ' ' myTuple = tuple([ _.strip("(), ") for _ in val.split(sep) ]) if myTuple is None: @@ -111,7 +111,7 @@ class ConfigHelper( object ): """check if val is a bool or a string of true/false, otherwise raise exception""" if isinstance(val, bool): return val - elif isinstance(val, basestring): + elif isinstance(val, six.string_types): if val.lower() == 'true': return True elif val.lower() == 'false': diff --git a/DDG4/python/DDSim/Helper/Filter.py b/DDG4/python/DDSim/Helper/Filter.py index 1d8385ca2..333cc17db 100644 --- a/DDG4/python/DDSim/Helper/Filter.py +++ b/DDG4/python/DDSim/Helper/Filter.py @@ -84,7 +84,7 @@ class Filter( ConfigHelper ): self._mapDetFilter.update(val) return - if isinstance(val, basestring): + if isinstance(val, six.string_types): vals = val.split(" ") elif isinstance( val, list ): vals = val diff --git a/DDG4/python/DDSim/Helper/Gun.py b/DDG4/python/DDSim/Helper/Gun.py index 05616c7a3..fc334f69f 100644 --- a/DDG4/python/DDSim/Helper/Gun.py +++ b/DDG4/python/DDSim/Helper/Gun.py @@ -4,6 +4,7 @@ from __future__ import absolute_import, unicode_literals from DDSim.Helper.ConfigHelper import ConfigHelper from g4units import GeV import logging +import six logging.basicConfig(format='%(levelname)s: %(message)s') logger = logging.getLogger(__name__) @@ -51,7 +52,7 @@ class Gun( ConfigHelper ): if val is None: return possibleDistributions = ['uniform', 'cos(theta)', 'eta', 'pseudorapidity', 'ffbar'] ## (1+cos^2 theta) - if not isinstance( val, basestring): + if not isinstance( val, six.string_types): raise RuntimeError( "malformed input '%s' for gun.distribution. Need a string : %s " % (val, ",".join(possibleDistributions)) ) if val not in possibleDistributions: ## surround options by quots to be explicit diff --git a/DDG4/python/DDSim/Helper/Physics.py b/DDG4/python/DDSim/Helper/Physics.py index 897c9e382..fe6d61a23 100644 --- a/DDG4/python/DDSim/Helper/Physics.py +++ b/DDG4/python/DDSim/Helper/Physics.py @@ -5,6 +5,7 @@ import os from DDSim.Helper.ConfigHelper import ConfigHelper from g4units import mm +import six class Physics( ConfigHelper ): """Configuration for the PhysicsList""" @@ -56,7 +57,7 @@ class Physics( ConfigHelper ): if val is None: self._rangecut = None return - if isinstance( val, basestring): + if isinstance( val, six.string_types): if val == "None": self._rangecut = None return -- GitLab