Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python 2to3 migration tool fix_basestring #23452

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
64 changes: 32 additions & 32 deletions Alignment/MuonAlignment/python/svgfig.py
Expand Up @@ -256,7 +256,7 @@ def items(self, sub=True, attr=True, text=True):
for ti, s in self:
show = False
if isinstance(ti[-1], (int, long)):
if isinstance(s, basestring): show = text
if isinstance(s, str): show = text
else: show = sub
else: show = attr

Expand Down Expand Up @@ -306,7 +306,7 @@ def tree(self, depth_limit=None, sub=True, attr=True, text=True, tree_width=20,
for ti, s in self.depth_first(depth_limit):
show = False
if isinstance(ti[-1], (int, long)):
if isinstance(s, basestring): show = text
if isinstance(s, str): show = text
else: show = sub
else: show = attr

Expand Down Expand Up @@ -568,18 +568,18 @@ def startElement(self, name, attr):
self.stack.append(s)

def characters(self, ch):
if not isinstance(ch, basestring) or self.all_whitespace.match(ch) == None:
if not isinstance(ch, str) or self.all_whitespace.match(ch) == None:
if len(self.stack) > 0:
last = self.stack[-1]
if len(last.sub) > 0 and isinstance(last.sub[-1], basestring):
if len(last.sub) > 0 and isinstance(last.sub[-1], str):
last.sub[-1] = last.sub[-1] + "\n" + ch
else:
last.sub.append(ch)

def endElement(self, name):
if len(self.stack) > 0:
last = self.stack[-1]
if isinstance(last, SVG) and last.t == "style" and "type" in last.attr and last.attr["type"] == "text/css" and len(last.sub) == 1 and isinstance(last.sub[0], basestring):
if isinstance(last, SVG) and last.t == "style" and "type" in last.attr and last.attr["type"] == "text/css" and len(last.sub) == 1 and isinstance(last.sub[0], str):
last.sub[0] = "<![CDATA[\n" + last.sub[0] + "]]>"

self.output = self.stack.pop()
Expand Down Expand Up @@ -733,7 +733,7 @@ class Fig:
def __repr__(self):
if self.trans == None:
return "<Fig (%d items)>" % len(self.d)
elif isinstance(self.trans, basestring):
elif isinstance(self.trans, str):
return "<Fig (%d items) x,y -> %s>" % (len(self.d), self.trans)
else:
return "<Fig (%d items) %s>" % (len(self.d), self.trans.__name__)
Expand All @@ -755,7 +755,7 @@ def SVG(self, trans=None):
"""

if trans == None: trans = self.trans
if isinstance(trans, basestring): trans = totrans(trans)
if isinstance(trans, str): trans = totrans(trans)

output = SVG("g")
for s in self.d:
Expand All @@ -764,7 +764,7 @@ def SVG(self, trans=None):

elif isinstance(s, Fig):
strans = s.trans
if isinstance(strans, basestring): strans = totrans(strans)
if isinstance(strans, str): strans = totrans(strans)

if trans == None: subtrans = strans
elif strans == None: subtrans = trans
Expand Down Expand Up @@ -856,7 +856,7 @@ def __init__(self, xmin, xmax, ymin, ymax, *d, **kwds):
def SVG(self, trans=None):
"""Apply the transformation "trans" and return an SVG object."""
if trans == None: trans = self.trans
if isinstance(trans, basestring): trans = totrans(trans)
if isinstance(trans, str): trans = totrans(trans)

self.last_window = window(self.xmin, self.xmax, self.ymin, self.ymax, x=self.x, y=self.y, width=self.width, height=self.height, \
xlogbase=self.xlogbase, ylogbase=self.ylogbase, minusInfinity=self.minusInfinity, flipx=self.flipx, flipy=self.flipy)
Expand Down Expand Up @@ -1060,7 +1060,7 @@ def __repr__(self):
return "<Path (%d nodes) %s>" % (len(self.d), self.attr)

def __init__(self, d=[], **attr):
if isinstance(d, basestring): self.d = self.parse(d)
if isinstance(d, str): self.d = self.parse(d)
else: self.d = list(d)

self.attr = dict(self.defaults)
Expand Down Expand Up @@ -1225,7 +1225,7 @@ def parse(self, pathdata):

def SVG(self, trans=None):
"""Apply the transformation "trans" and return an SVG object."""
if isinstance(trans, basestring): trans = totrans(trans)
if isinstance(trans, str): trans = totrans(trans)

x, y, X, Y = None, None, None, None
output = []
Expand Down Expand Up @@ -1655,8 +1655,8 @@ def Path(self, trans=None, local=False):
global coordinates. If local=True, return a Path in local coordinates
(which must be transformed again)."""

if isinstance(trans, basestring): trans = totrans(trans)
if isinstance(self.f, basestring): self.f = funcRtoR2(self.f)
if isinstance(trans, str): trans = totrans(trans)
if isinstance(self.f, str): self.f = funcRtoR2(self.f)

self.sample(trans)

Expand Down Expand Up @@ -1734,7 +1734,7 @@ def Path(self, trans=None, local=False):
"""Apply the transformation "trans" and return a Path object in
global coordinates. If local=True, return a Path in local coordinates
(which must be transformed again)."""
if isinstance(trans, basestring): trans = totrans(trans)
if isinstance(trans, str): trans = totrans(trans)

if self.mode[0] == "L" or self.mode[0] == "l": mode = "L"
elif self.mode[0] == "B" or self.mode[0] == "b": mode = "B"
Expand Down Expand Up @@ -1853,7 +1853,7 @@ def __init__(self, x, y, d, **attr):

def SVG(self, trans=None):
"""Apply the transformation "trans" and return an SVG object."""
if isinstance(trans, basestring): trans = totrans(trans)
if isinstance(trans, str): trans = totrans(trans)

X, Y = self.x, self.y
if trans != None: X, Y = trans(X, Y)
Expand Down Expand Up @@ -1937,7 +1937,7 @@ def __init__(self, d=[], symbol=None, width=1., height=1., **attr):

def SVG(self, trans=None):
"""Apply the transformation "trans" and return an SVG object."""
if isinstance(trans, basestring): trans = totrans(trans)
if isinstance(trans, str): trans = totrans(trans)

output = SVG("g", SVG("defs", self.symbol))
id = "#%s" % self.symbol["id"]
Expand Down Expand Up @@ -2011,7 +2011,7 @@ def SVG(self, trans=None):
if isinstance(self.arrow_start, SVG):
defs.append(self.arrow_start)
line.attr["marker-start"] = "url(#%s)" % self.arrow_start["id"]
elif isinstance(self.arrow_start, basestring):
elif isinstance(self.arrow_start, str):
defs.append(make_marker(self.arrow_start, "arrow_start"))
line.attr["marker-start"] = "url(#%s)" % self.arrow_start
else:
Expand All @@ -2021,7 +2021,7 @@ def SVG(self, trans=None):
if isinstance(self.arrow_end, SVG):
defs.append(self.arrow_end)
line.attr["marker-end"] = "url(#%s)" % self.arrow_end["id"]
elif isinstance(self.arrow_end, basestring):
elif isinstance(self.arrow_end, str):
defs.append(make_marker(self.arrow_end, "arrow_end"))
line.attr["marker-end"] = "url(#%s)" % self.arrow_end
else:
Expand Down Expand Up @@ -2083,7 +2083,7 @@ def __init__(self, x1, y1, x2, y2, local1=False, local2=False, arrow_start=None,

def SVG(self, trans=None):
"""Apply the transformation "trans" and return an SVG object."""
if isinstance(trans, basestring): trans = totrans(trans)
if isinstance(trans, str): trans = totrans(trans)

X1, Y1, X2, Y2 = self.x1, self.y1, self.x2, self.y2

Expand All @@ -2099,7 +2099,7 @@ def SVG(self, trans=None):
if isinstance(self.arrow_start, SVG):
defs.append(self.arrow_start)
line.attr["marker-start"] = "url(#%s)" % self.arrow_start["id"]
elif isinstance(self.arrow_start, basestring):
elif isinstance(self.arrow_start, str):
defs.append(make_marker(self.arrow_start, "arrow_start"))
line.attr["marker-start"] = "url(#%s)" % self.arrow_start
else:
Expand All @@ -2109,7 +2109,7 @@ def SVG(self, trans=None):
if isinstance(self.arrow_end, SVG):
defs.append(self.arrow_end)
line.attr["marker-end"] = "url(#%s)" % self.arrow_end["id"]
elif isinstance(self.arrow_end, basestring):
elif isinstance(self.arrow_end, str):
defs.append(make_marker(self.arrow_end, "arrow_end"))
line.attr["marker-end"] = "url(#%s)" % self.arrow_end
else:
Expand Down Expand Up @@ -2411,7 +2411,7 @@ def orient_tickmark(self, t, trans=None):

Normally only used internally.
"""
if isinstance(trans, basestring): trans = totrans(trans)
if isinstance(trans, str): trans = totrans(trans)
if trans == None:
f = self.f
else:
Expand All @@ -2434,7 +2434,7 @@ def orient_tickmark(self, t, trans=None):

def SVG(self, trans=None):
"""Apply the transformation "trans" and return an SVG object."""
if isinstance(trans, basestring): trans = totrans(trans)
if isinstance(trans, str): trans = totrans(trans)

self.last_ticks, self.last_miniticks = self.interpret()
tickmarks = Path([], **self.attr)
Expand All @@ -2447,15 +2447,15 @@ def SVG(self, trans=None):
if self.arrow_start != False and self.arrow_start != None:
if isinstance(self.arrow_start, SVG):
defs.append(self.arrow_start)
elif isinstance(self.arrow_start, basestring):
elif isinstance(self.arrow_start, str):
defs.append(make_marker(self.arrow_start, "arrow_start"))
else:
raise TypeError("arrow_start must be False/None or an id string for the new marker")

if self.arrow_end != False and self.arrow_end != None:
if isinstance(self.arrow_end, SVG):
defs.append(self.arrow_end)
elif isinstance(self.arrow_end, basestring):
elif isinstance(self.arrow_end, str):
defs.append(make_marker(self.arrow_end, "arrow_end"))
else:
raise TypeError("arrow_end must be False/None or an id string for the new marker")
Expand Down Expand Up @@ -2517,7 +2517,7 @@ def interpret(self):
elif self.labels == True:
format = unumber

elif isinstance(self.labels, basestring):
elif isinstance(self.labels, str):
format = lambda x: (self.labels % x)

elif callable(self.labels):
Expand Down Expand Up @@ -2834,13 +2834,13 @@ def SVG(self, trans=None):
ticks = Ticks.SVG(self, trans) # returns a <g />

if self.arrow_start != False and self.arrow_start != None:
if isinstance(self.arrow_start, basestring):
if isinstance(self.arrow_start, str):
func.attr["marker-start"] = "url(#%s)" % self.arrow_start
else:
func.attr["marker-start"] = "url(#%s)" % self.arrow_start.id

if self.arrow_end != False and self.arrow_end != None:
if isinstance(self.arrow_end, basestring):
if isinstance(self.arrow_end, str):
func.attr["marker-end"] = "url(#%s)" % self.arrow_end
else:
func.attr["marker-end"] = "url(#%s)" % self.arrow_end.id
Expand Down Expand Up @@ -2918,13 +2918,13 @@ def SVG(self, trans=None):
self.high = self.end

if self.arrow_start != False and self.arrow_start != None:
if isinstance(self.arrow_start, basestring):
if isinstance(self.arrow_start, str):
line.attr["marker-start"] = "url(#%s)" % self.arrow_start
else:
line.attr["marker-start"] = "url(#%s)" % self.arrow_start.id

if self.arrow_end != False and self.arrow_end != None:
if isinstance(self.arrow_end, basestring):
if isinstance(self.arrow_end, str):
line.attr["marker-end"] = "url(#%s)" % self.arrow_end
else:
line.attr["marker-end"] = "url(#%s)" % self.arrow_end.id
Expand Down Expand Up @@ -3308,7 +3308,7 @@ def __init__(self, d=[], **attr):

def SVG(self, trans=None):
"""Apply the transformation "trans" and return an SVG object."""
if isinstance(trans, basestring): trans = totrans(trans) # only once
if isinstance(trans, str): trans = totrans(trans) # only once

output = SVG("g")
for p in self.d:
Expand Down Expand Up @@ -3354,7 +3354,7 @@ def __init__(self, d=[], **attr):

def SVG(self, trans=None):
"""Apply the transformation "trans" and return an SVG object."""
if isinstance(trans, basestring): trans = totrans(trans) # only once
if isinstance(trans, str): trans = totrans(trans) # only once

output = SVG("g")
for p in self.d:
Expand Down
Expand Up @@ -51,7 +51,7 @@ def getSectionLines(self,section):
sectionLines.append('\nconfig.section_("%s")'%section)
configItems = self.items(section)
for configItem in configItems:
if not isinstance(configItem[1], basestring):
if not isinstance(configItem[1], str):
sectionLines.append('config.%s.%s = %s'%(section,configItem[0],configItem[1]))
elif "True" in configItem[1] or "False" in configItem[1]:
sectionLines.append('config.%s.%s = %s'%(section,configItem[0],configItem[1]))
Expand Down
2 changes: 1 addition & 1 deletion Configuration/AlCa/python/GlobalTag.py
Expand Up @@ -104,7 +104,7 @@ def GlobalTag(essource = None, globaltag = None, conditions = None):
# add any explicitly requested conditions, possibly overriding those from autoCond.py
if conditions is not None:
# TODO backward compatible code: to be removed after migrating ConfigBuilder.py and confdb.py to use a map for custom conditions
if isinstance(conditions, basestring):
if isinstance(conditions, str):
if conditions:
map = {}
for entry in conditions.split('+'):
Expand Down
2 changes: 1 addition & 1 deletion Configuration/PyReleaseValidation/python/relval_machine.py
Expand Up @@ -36,7 +36,7 @@ def convert_keys_to_string(dictionary):
Utility to help deal with unicode keys in dictionaries created from json requests.
In order to pass dict to function as **kwarg we should transform key/value to str.
"""
if isinstance(dictionary, basestring):
if isinstance(dictionary, str):
return str(dictionary)
elif isinstance(dictionary, collections.Mapping):
return dict(map(convert_keys_to_string, dictionary.iteritems()))
Expand Down
14 changes: 7 additions & 7 deletions Documentation/ReferenceManualScripts/python/BeautifulSoup.py
Expand Up @@ -202,7 +202,7 @@ def _lastRecursiveChild(self):
return lastChild

def insert(self, position, newChild):
if isinstance(newChild, basestring) \
if isinstance(newChild, str) \
and not isinstance(newChild, NavigableString):
newChild = NavigableString(newChild)

Expand Down Expand Up @@ -357,7 +357,7 @@ def _findAll(self, name, attrs, text, limit, generator, **kwargs):
return [element for element in generator()
if isinstance(element, Tag)]
# findAll*('tag-name')
elif isinstance(name, basestring):
elif isinstance(name, str):
return [element for element in generator()
if isinstance(element, Tag) and
element.name == name]
Expand Down Expand Up @@ -708,7 +708,7 @@ def __str__(self, encoding=DEFAULT_OUTPUT_ENCODING,
if self.attrs:
for key, val in self.attrs:
fmt = '%s="%s"'
if isinstance(val, basestring):
if isinstance(val, str):
if self.containsSubstitutions and '%SOUP-ENCODING%' in val:
val = self.substituteEncoding(val, encoding)

Expand Down Expand Up @@ -892,7 +892,7 @@ class SoupStrainer:

def __init__(self, name=None, attrs={}, text=None, **kwargs):
self.name = name
if isinstance(attrs, basestring):
if isinstance(attrs, str):
kwargs['class'] = _match_css_class(attrs)
attrs = None
if kwargs:
Expand Down Expand Up @@ -966,7 +966,7 @@ def search(self, markup):
found = self.searchTag(markup)
# If it's text, make sure the text matches.
elif isinstance(markup, NavigableString) or \
isinstance(markup, basestring):
isinstance(markup, str):
if self._matches(markup, self.text):
found = markup
else:
Expand All @@ -986,7 +986,7 @@ def _matches(self, markup, matchAgainst):
#other ways of matching match the tag name as a string.
if isinstance(markup, Tag):
markup = markup.name
if markup and not isinstance(markup, basestring):
if markup and not isinstance(markup, str):
markup = unicode(markup)
#Now we know that chunk is either a string, or None.
if hasattr(matchAgainst, 'match'):
Expand All @@ -996,7 +996,7 @@ def _matches(self, markup, matchAgainst):
result = markup in matchAgainst
elif hasattr(matchAgainst, 'items'):
result = matchAgainst in markup
elif matchAgainst and isinstance(markup, basestring):
elif matchAgainst and isinstance(markup, str):
if isinstance(markup, unicode):
matchAgainst = unicode(matchAgainst)
else:
Expand Down