Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
replace basestring by six.string_types
Browse files Browse the repository at this point in the history
  • Loading branch information
a-andre committed May 25, 2015
1 parent 86787f2 commit 002892e
Show file tree
Hide file tree
Showing 30 changed files with 80 additions and 53 deletions.
3 changes: 2 additions & 1 deletion src/sage/algebras/commutative_dga.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
# http://www.gnu.org/licenses/
#*****************************************************************************

import six
from sage.structure.unique_representation import UniqueRepresentation
from sage.structure.sage_object import SageObject
from sage.misc.cachefunc import cached_method
Expand Down Expand Up @@ -832,7 +833,7 @@ def __classcall__(cls, base, names=None, degrees=None, R=None, I=None):
else:
n = len(degrees)
names = tuple('x{}'.format(i) for i in range(n))
elif isinstance(names, basestring):
elif isinstance(names, six.string_types):
names = tuple(names.split(','))
n = len(names)
else:
Expand Down
3 changes: 2 additions & 1 deletion src/sage/algebras/free_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
# http://www.gnu.org/licenses/
#*****************************************************************************

import six
from sage.categories.rings import Rings

from sage.monoids.free_monoid import FreeMonoid
Expand Down Expand Up @@ -594,7 +595,7 @@ def exp_to_monomial(T):
return M(out)
return self.element_class(self, dict([(exp_to_monomial(T),c) for T,c in x.letterplace_polynomial().dict().iteritems()]))
# ok, not a free algebra element (or should not be viewed as one).
if isinstance(x, basestring):
if isinstance(x, six.string_types):
from sage.all import sage_eval
G = self.gens()
d = {str(v): G[i] for i,v in enumerate(self.variable_names())}
Expand Down
3 changes: 2 additions & 1 deletion src/sage/algebras/shuffle_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# http://www.gnu.org/licenses/
#*****************************************************************************

import six
from sage.categories.rings import Rings
from sage.categories.algebras_with_basis import AlgebrasWithBasis
from sage.categories.commutative_algebras import CommutativeAlgebras
Expand Down Expand Up @@ -379,7 +380,7 @@ def _element_constructor_(self, x):
if isinstance(P, DualPBWBasis):
return self(P.expansion(x))
# ok, not a shuffle algebra element (or should not be viewed as one).
if isinstance(x, basestring):
if isinstance(x, six.string_types):
from sage.misc.sage_eval import sage_eval
return sage_eval(x,locals=self.gens_dict())
R = self.base_ring()
Expand Down
7 changes: 4 additions & 3 deletions src/sage/categories/pushout.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Coercion via Construction Functors
"""
import six
from functor import Functor
from basic import *

Expand Down Expand Up @@ -1431,10 +1432,10 @@ def __init__(self, var, multi_variate=False):
"""
Functor.__init__(self, Rings(), Rings())
if not isinstance(var, (basestring,tuple,list)):
if not isinstance(var, (six.string_types,tuple,list)):
raise TypeError("variable name or list of variable names expected")
self.var = var
self.multi_variate = multi_variate or not isinstance(var, basestring)
self.multi_variate = multi_variate or not isinstance(var, six.string_types)

def _apply_functor(self, R):
"""
Expand Down Expand Up @@ -2367,7 +2368,7 @@ def __init__(self, I, names=None, as_field=False):
self.I = I
if names is None:
self.names = None
elif isinstance(names, basestring):
elif isinstance(names, six.string_types):
self.names = (names,)
else:
self.names = tuple(names)
Expand Down
3 changes: 2 additions & 1 deletion src/sage/coding/source_coding/huffman.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
# http://www.gnu.org/licenses/
###########################################################################

import six
from sage.structure.sage_object import SageObject

###########################################################################
Expand Down Expand Up @@ -245,7 +246,7 @@ def __init__(self, source):
# index of each alphabetic symbol
self._index = None

if isinstance(source,basestring):
if isinstance(source, six.string_types):
self._build_code(frequency_table(source))
elif isinstance(source, dict):
self._build_code(source)
Expand Down
5 changes: 3 additions & 2 deletions src/sage/combinat/root_system/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,7 @@
# http://www.gnu.org/licenses/
#*****************************************************************************

import six
from sage.misc.cachefunc import cached_method, cached_function
from sage.misc.latex import latex
from sage.misc.lazy_import import lazy_import
Expand Down Expand Up @@ -741,13 +742,13 @@ def text(self, label, position, rgbcolor=(0,0,0)):
"""
if self.labels:
if self.dimension <= 2:
if not isinstance(label, basestring):
if not isinstance(label, six.string_types):
label = "$"+str(latex(label))+"$"
from sage.plot.text import text
return text(label, position, fontsize=15, rgbcolor=rgbcolor)
elif self.dimension == 3:
# LaTeX labels not yet supported in 3D
if isinstance(label, basestring):
if isinstance(label, six.string_types):
label = label.replace("{","").replace("}","").replace("$","").replace("_","")
else:
label = str(label)
Expand Down
4 changes: 3 additions & 1 deletion src/sage/dev/user_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
# http://www.gnu.org/licenses/
#*****************************************************************************

import six

# log levels
ERROR = -2
WARNING = -1
Expand Down Expand Up @@ -180,7 +182,7 @@ def show(self, message, *args, **kwds):
raise ValueError('the only allowed keyword argument is "log_level"')
config_log_level = int(self._config.get("log_level", str(INFO)))
if config_log_level >= log_level:
if isinstance(message, basestring):
if isinstance(message, six.string_types):
self._show(message, log_level, *args)
else:
for msg in message:
Expand Down
5 changes: 3 additions & 2 deletions src/sage/doctest/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#*****************************************************************************

import random, os, sys, time, json, re, types
import six
import sage.misc.flatten
from sage.structure.sage_object import SageObject
from sage.env import DOT_SAGE, SAGE_LIB, SAGE_SRC
Expand Down Expand Up @@ -235,7 +236,7 @@ def __init__(self, options, args):
if options.verbose:
options.show_skipped = True

if isinstance(options.optional, basestring):
if isinstance(options.optional, six.string_types):
s = options.optional.lower()
if s in ['all', 'true']:
options.optional = True
Expand Down Expand Up @@ -1027,7 +1028,7 @@ def stringify(x):
return [base]
else:
return [os.path.join(base, file) + ext]
elif isinstance(x, basestring):
elif isinstance(x, six.string_types):
return [os.path.abspath(x)]
F = stringify(module)
if options is None:
Expand Down
3 changes: 2 additions & 1 deletion src/sage/games/sudoku.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# http://www.gnu.org/licenses/
######################################################################

import six
from sage.structure.sage_object import SageObject

def sudoku(m):
Expand Down Expand Up @@ -180,7 +181,7 @@ def __init__(self, puzzle, verify_input = True):
if verify_input and not(puzzle.is_square()):
raise ValueError('Sudoku puzzle must be a square matrix')
self.puzzle = tuple([int(x) for x in puzzle.list()])
elif isinstance(puzzle, basestring):
elif isinstance(puzzle, six.string_types):
puzzle_size = int(round(sqrt(len(puzzle))))
puzzle_numeric = []
for char in puzzle:
Expand Down
4 changes: 2 additions & 2 deletions src/sage/geometry/polyhedron/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# http://www.gnu.org/licenses/
########################################################################


import six
from sage.structure.element import Element, coerce_binop, is_Vector

from sage.misc.all import cached_method, prod
Expand Down Expand Up @@ -646,7 +646,7 @@ def merge_options(*opts):
continue
elif opt is False:
return False
elif isinstance(opt, (basestring, list, tuple)):
elif isinstance(opt, (six.string_types, list, tuple)):
merged['color'] = opt
else:
merged.update(opt)
Expand Down
4 changes: 2 additions & 2 deletions src/sage/groups/abelian_gps/abelian_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@
# http://www.gnu.org/licenses/
##########################################################################


import six
from sage.rings.integer import Integer
from sage.rings.integer_ring import ZZ
from sage.structure.unique_representation import UniqueRepresentation
Expand Down Expand Up @@ -536,7 +536,7 @@ def __init__(self, generator_orders, names):
sage: A.category()
Category of commutative groups
"""
assert isinstance(names, (basestring, tuple))
assert isinstance(names, (six.string_types, tuple))
assert isinstance(generator_orders, tuple)
assert all(isinstance(order,Integer) for order in generator_orders)
self._gens_orders = generator_orders
Expand Down
4 changes: 2 additions & 2 deletions src/sage/groups/braid.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
# http://www.gnu.org/licenses/
##############################################################################


import six
from sage.rings.integer import Integer
from sage.rings.integer_ring import IntegerRing
from sage.misc.cachefunc import cached_method
Expand Down Expand Up @@ -1197,7 +1197,7 @@ def BraidGroup(n=None, names='s'):
n = None
# derive n from counting names
if n is None:
if isinstance(names, basestring):
if isinstance(names, six.string_types):
n = len(names.split(','))
else:
names = list(names)
Expand Down
4 changes: 2 additions & 2 deletions src/sage/groups/free_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
# http://www.gnu.org/licenses/
##############################################################################


import six
from sage.groups.group import Group
from sage.groups.libgap_wrapper import ParentLibGAP, ElementLibGAP
from sage.structure.unique_representation import UniqueRepresentation
Expand Down Expand Up @@ -622,7 +622,7 @@ def FreeGroup(n=None, names='x', index_set=None, abelian=False, **kwds):
n = None
# derive n from counting names
if n is None:
if isinstance(names, basestring):
if isinstance(names, six.string_types):
n = len(names.split(','))
else:
names = list(names)
Expand Down
9 changes: 5 additions & 4 deletions src/sage/interfaces/expect.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import gc
import quit
import cleaner
import six
from random import randrange

########################################################
Expand Down Expand Up @@ -179,7 +180,7 @@ def __init__(self, name, prompt, command=None, server=None,
self.__max_startup_time = max_startup_time

#Handle the log file
if isinstance(logfile, basestring):
if isinstance(logfile, six.string_types):
self.__logfile = None
self.__logfilename = logfile
else:
Expand Down Expand Up @@ -849,7 +850,7 @@ def _eval_line(self, line, allow_use_file=True, wait_for_prompt=True, restart_if

if len(line)>0:
try:
if isinstance(wait_for_prompt, basestring):
if isinstance(wait_for_prompt, six.string_types):
E.expect(wait_for_prompt)
else:
E.expect(self._prompt)
Expand Down Expand Up @@ -1206,7 +1207,7 @@ def eval(self, code, strip=True, synchronize=False, locals=None, allow_use_file=
except AttributeError:
pass

if not isinstance(code, basestring):
if not isinstance(code, six.string_types):
raise TypeError('input code must be a string.')

#Remove extra whitespace
Expand Down Expand Up @@ -1294,7 +1295,7 @@ def __init__(self, parent, value, is_name=False, name=None):
# idea: Joe Wetherell -- try to find out if the output
# is too long and if so get it using file, otherwise
# don't.
if isinstance(value, basestring) and parent._eval_using_file_cutoff and \
if isinstance(value, six.string_types) and parent._eval_using_file_cutoff and \
parent._eval_using_file_cutoff < len(value):
self._get_using_file = True

Expand Down
3 changes: 2 additions & 1 deletion src/sage/interfaces/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#*****************************************************************************

import operator
import six

from sage.structure.sage_object import SageObject
from sage.structure.parent_base import ParentWithBase
Expand Down Expand Up @@ -166,7 +167,7 @@ def __call__(self, x, name=None):
except (NotImplementedError, TypeError):
pass

if isinstance(x, basestring):
if isinstance(x, six.string_types):
return cls(self, x, name=name)
try:
return self._coerce_from_special_method(x)
Expand Down
3 changes: 2 additions & 1 deletion src/sage/interfaces/r.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@
from expect import Expect, ExpectElement, ExpectFunction, FunctionElement
from sage.env import DOT_SAGE
import re
import six
import sage.rings.integer
from sage.structure.element import parent

Expand Down Expand Up @@ -1307,7 +1308,7 @@ def __getitem__(self, n):
[1] 1 3
"""
P = self._check_valid()
if isinstance(n, basestring):
if isinstance(n, six.string_types):
n = n.replace('self', self._name)
return P.new('%s[%s]'%(self._name, n))
elif parent(n) is P: # the key is RElement itself
Expand Down
7 changes: 4 additions & 3 deletions src/sage/matrix/operation_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# http://www.gnu.org/licenses/
#******************************************************************************

import six
from sage.structure.sage_object import SageObject

class OperationTable(SageObject):
Expand Down Expand Up @@ -519,7 +520,7 @@ def _name_maker(self, names):
raise ValueError('list of element names must be the same size as the set, %s != %s'%(len(names), self._n))
width = 0
for str in names:
if not isinstance(str, basestring):
if not isinstance(str, six.string_types):
raise ValueError('list of element names must only contain strings, not %s'%str)
if len(str) > width:
width = len(str)
Expand Down Expand Up @@ -693,9 +694,9 @@ def set_print_symbols(self, ascii, latex):
...
ValueError: ASCII symbol should be a single character, not 5
"""
if not isinstance(ascii, basestring) or not len(ascii)==1:
if not isinstance(ascii, six.string_types) or not len(ascii)==1:
raise ValueError('ASCII symbol should be a single character, not %s' % ascii)
if not isinstance(latex, basestring):
if not isinstance(latex, six.string_types):
raise ValueError('LaTeX symbol must be a string, not %s' % latex)
self._ascii_symbol = ascii
self._latex_symbol = latex
Expand Down
3 changes: 2 additions & 1 deletion src/sage/misc/gperftools.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,12 @@ def _pprof(self):
EXAMPLES::
sage: import six
sage: from sage.misc.gperftools import Profiler
sage: prof = Profiler()
sage: try:
....: pp = prof._pprof()
....: assert isinstance(pp, basestring)
....: assert isinstance(pp, six.string_types)
....: except OSError:
....: pass # not installed
"""
Expand Down
3 changes: 2 additions & 1 deletion src/sage/misc/sage_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# http://www.gnu.org/licenses/
#*****************************************************************************

import six
from copy import copy
import sage.repl.preparse as preparser

Expand Down Expand Up @@ -177,7 +178,7 @@ def sage_eval(source, locals=None, cmds='', preparse=True):
locals = copy(source[2])
source = source[1]

if not isinstance(source, basestring):
if not isinstance(source, six.string_types):
raise TypeError("source must be a string.")

if locals is None:
Expand Down

0 comments on commit 002892e

Please sign in to comment.