Remove fix_basestring.

This commit is contained in:
Valentin Lorentz 2015-08-10 20:24:11 +02:00
parent 2c380a4c3a
commit f305ff3c02
18 changed files with 41 additions and 34 deletions

View File

@ -99,7 +99,7 @@ class FilterTest(ChannelPluginTestCase):
self.assertResponse('rot13 [rot13 %s]' % s, s) self.assertResponse('rot13 [rot13 %s]' % s, s)
def testRot13HandlesNonAsciiStuff(self): def testRot13HandlesNonAsciiStuff(self):
self.assertNotError(u('rot13 é')) self.assertNotError('rot13 é')
def testHexlifyUnhexlify(self): def testHexlifyUnhexlify(self):
for s in map(str, range(1000, 1010)): for s in map(str, range(1000, 1010)):

View File

@ -127,7 +127,7 @@ class Google(callbacks.PluginRegexp):
return data return data
def formatData(self, data, bold=True, max=0, onetoone=False): def formatData(self, data, bold=True, max=0, onetoone=False):
if isinstance(data, basestring): if isinstance(data, minisix.string_types):
return data return data
results = [] results = []
if max: if max:

View File

@ -32,6 +32,7 @@ import supybot.dbi as dbi
import supybot.conf as conf import supybot.conf as conf
import supybot.utils as utils import supybot.utils as utils
from supybot.commands import * from supybot.commands import *
import supybot.minisix as minisix
import supybot.plugins as plugins import supybot.plugins as plugins
import supybot.ircmsgs as ircmsgs import supybot.ircmsgs as ircmsgs
import supybot.ircutils as ircutils import supybot.ircutils as ircutils
@ -114,7 +115,7 @@ class URL(callbacks.Plugin):
f = None f = None
nolimit = False nolimit = False
for (option, arg) in optlist: for (option, arg) in optlist:
if isinstance(arg, basestring): if isinstance(arg, minisix.string_types):
arg = arg.lower() arg = arg.lower()
if option == 'nolimit': if option == 'nolimit':
nolimit = True nolimit = True

View File

@ -26,7 +26,7 @@ def error(s):
def system(sh, errmsg=None, **kwargs): def system(sh, errmsg=None, **kwargs):
if errmsg is None: if errmsg is None:
if isinstance(sh, basestring): if isinstance(sh, minisix.string_types):
errmsg = repr(sh) errmsg = repr(sh)
else: else:
errmsg = repr(' '.join(sh)) errmsg = repr(' '.join(sh))

View File

@ -157,7 +157,7 @@ try:
def log_debug(self, msg, *args): def log_debug(self, msg, *args):
log.debug(msg, *args) log.debug(msg, *args)
fixer_names = ['fix_basestring', fixer_names = [
'fix_metaclass', 'fix_metaclass',
'fix_numliterals', 'fix_numliterals',
] ]

View File

@ -382,7 +382,7 @@ def formatCommand(command):
return ' '.join(command) return ' '.join(command)
def checkCommandCapability(msg, cb, commandName): def checkCommandCapability(msg, cb, commandName):
assert isinstance(commandName, basestring), commandName assert isinstance(commandName, minisix.string_types), commandName
plugin = cb.name().lower() plugin = cb.name().lower()
pluginCommand = '%s.%s' % (plugin, commandName) pluginCommand = '%s.%s' % (plugin, commandName)
def checkCapability(capability): def checkCapability(capability):
@ -458,9 +458,9 @@ class RichReplyMethods(object):
prefixer = '' prefixer = ''
if joiner is None: if joiner is None:
joiner = utils.str.commaAndify joiner = utils.str.commaAndify
if isinstance(prefixer, basestring): if isinstance(prefixer, minisix.string_types):
prefixer = prefixer.__add__ prefixer = prefixer.__add__
if isinstance(joiner, basestring): if isinstance(joiner, minisix.string_types):
joiner = joiner.join joiner = joiner.join
if oneToOne is None: # Can be True, False, or None if oneToOne is None: # Can be True, False, or None
if ircutils.isChannel(to): if ircutils.isChannel(to):
@ -495,7 +495,7 @@ class RichReplyMethods(object):
def errorNoCapability(self, capability, s='', **kwargs): def errorNoCapability(self, capability, s='', **kwargs):
if 'Raise' not in kwargs: if 'Raise' not in kwargs:
kwargs['Raise'] = True kwargs['Raise'] = True
if isinstance(capability, basestring): # checkCommandCapability! if isinstance(capability, minisix.string_types): # checkCommandCapability!
log.warning('Denying %s for lacking %q capability.', log.warning('Denying %s for lacking %q capability.',
self.msg.prefix, capability) self.msg.prefix, capability)
# noCapability means "don't send a specific capability error # noCapability means "don't send a specific capability error
@ -669,7 +669,7 @@ class NestedCommandsIrcProxy(ReplyIrcProxy):
def evalArgs(self): def evalArgs(self):
while self.counter < len(self.args): while self.counter < len(self.args):
self.repliedTo = False self.repliedTo = False
if isinstance(self.args[self.counter], basestring): if isinstance(self.args[self.counter], minisix.string_types):
# If it's a string, just go to the next arg. There is no # If it's a string, just go to the next arg. There is no
# evaluation to be done for strings. If, at some point, # evaluation to be done for strings. If, at some point,
# we decided to, say, convert every string using # we decided to, say, convert every string using
@ -692,7 +692,7 @@ class NestedCommandsIrcProxy(ReplyIrcProxy):
return return
# Once all the list args are evaluated, we then evaluate our own # Once all the list args are evaluated, we then evaluate our own
# list of args, since we're assured that they're all strings now. # list of args, since we're assured that they're all strings now.
assert all(lambda x: isinstance(x, basestring), self.args) assert all(lambda x: isinstance(x, minisix.string_types), self.args)
self.finalEval() self.finalEval()
def _callInvalidCommands(self): def _callInvalidCommands(self):
@ -873,7 +873,7 @@ class NestedCommandsIrcProxy(ReplyIrcProxy):
# action=True implies noLengthCheck=True and prefixNick=False # action=True implies noLengthCheck=True and prefixNick=False
self.noLengthCheck=noLengthCheck or self.noLengthCheck or self.action self.noLengthCheck=noLengthCheck or self.noLengthCheck or self.action
target = self.private and self.to or self.msg.args[0] target = self.private and self.to or self.msg.args[0]
if not isinstance(s, basestring): # avoid trying to str() unicode if not isinstance(s, minisix.string_types): # avoid trying to str() unicode
s = str(s) # Allow non-string esses. s = str(s) # Allow non-string esses.
if self.finalEvaled: if self.finalEvaled:
try: try:
@ -1184,7 +1184,7 @@ class Commands(BasePlugin):
def isCommand(self, command): def isCommand(self, command):
"""Convenience, backwards-compatibility, semi-deprecated.""" """Convenience, backwards-compatibility, semi-deprecated."""
if isinstance(command, basestring): if isinstance(command, minisix.string_types):
return self.isCommandMethod(command) return self.isCommandMethod(command)
else: else:
# Since we're doing a little type dispatching here, let's not be # Since we're doing a little type dispatching here, let's not be
@ -1210,7 +1210,7 @@ class Commands(BasePlugin):
def getCommandMethod(self, command): def getCommandMethod(self, command):
"""Gets the given command from this plugin.""" """Gets the given command from this plugin."""
#print '*** %s.getCommandMethod(%r)' % (self.name(), command) #print '*** %s.getCommandMethod(%r)' % (self.name(), command)
assert not isinstance(command, basestring) assert not isinstance(command, minisix.string_types)
assert command == list(map(canonicalName, command)) assert command == list(map(canonicalName, command))
assert self.getCommand(command) == command assert self.getCommand(command) == command
for cb in self.cbs: for cb in self.cbs:

View File

@ -681,7 +681,7 @@ def getMatch(irc, msg, args, state, regexp, errmsg):
def getLiteral(irc, msg, args, state, literals, errmsg=None): def getLiteral(irc, msg, args, state, literals, errmsg=None):
# ??? Should we allow abbreviations? # ??? Should we allow abbreviations?
if isinstance(literals, basestring): if isinstance(literals, minisix.string_types):
literals = (literals,) literals = (literals,)
abbrevs = utils.abbrev(literals) abbrevs = utils.abbrev(literals)
if args[0] in abbrevs: if args[0] in abbrevs:
@ -827,7 +827,7 @@ class context(object):
self.converter = getConverter(spec[0]) self.converter = getConverter(spec[0])
elif spec is None: elif spec is None:
self.converter = getConverter('anything') self.converter = getConverter('anything')
elif isinstance(spec, basestring): elif isinstance(spec, minisix.string_types):
self.args = () self.args = ()
self.converter = getConverter(spec) self.converter = getConverter(spec)
else: else:

View File

@ -35,7 +35,7 @@ import os
import csv import csv
import math import math
from . import cdb, utils from . import cdb, minisix, utils
from .utils.iter import ilen from .utils.iter import ilen
class Error(Exception): class Error(Exception):
@ -329,7 +329,7 @@ class DB(object):
self.Record = Record self.Record = Record
if Mapping is not None: if Mapping is not None:
self.Mapping = Mapping self.Mapping = Mapping
if isinstance(self.Mapping, basestring): if isinstance(self.Mapping, minisix.string_types):
self.Mapping = Mappings[self.Mapping] self.Mapping = Mappings[self.Mapping]
self.map = self.Mapping(filename) self.map = self.Mapping(filename)

View File

@ -36,7 +36,7 @@ import sys
import time import time
import socket import socket
from .. import conf, ircmsgs, log as supylog, utils from .. import conf, ircmsgs, log as supylog, minisix, utils
_drivers = {} _drivers = {}
_deadDrivers = [] _deadDrivers = []
@ -154,7 +154,7 @@ class Log(object):
def reconnect(self, network, when=None): def reconnect(self, network, when=None):
s = 'Reconnecting to %s' % network s = 'Reconnecting to %s' % network
if when is not None: if when is not None:
if not isinstance(when, basestring): if not isinstance(when, minisix.string_types):
when = self.timestamp(when) when = self.timestamp(when)
s += ' at %s.' % when s += ' at %s.' % when
else: else:

View File

@ -33,7 +33,7 @@ import os
import time import time
import operator import operator
from . import conf, ircutils, log, registry, unpreserve, utils, world from . import conf, ircutils, log, minisix, registry, unpreserve, utils, world
def isCapability(capability): def isCapability(capability):
return len(capability.split(None, 1)) == 1 return len(capability.split(None, 1)) == 1
@ -303,7 +303,7 @@ class IrcUser(object):
def addNick(self, network, nick): def addNick(self, network, nick):
"""Adds a nick to the user's registered nicks on the network.""" """Adds a nick to the user's registered nicks on the network."""
global users global users
assert isinstance(network, basestring) assert isinstance(network, minisix.string_types)
assert ircutils.isNick(nick), 'got %s' % nick assert ircutils.isNick(nick), 'got %s' % nick
if users.getUserFromNick(network, nick) is not None: if users.getUserFromNick(network, nick) is not None:
raise KeyError raise KeyError
@ -314,7 +314,7 @@ class IrcUser(object):
def removeNick(self, network, nick): def removeNick(self, network, nick):
"""Removes a nick from the user's registered nicks on the network.""" """Removes a nick from the user's registered nicks on the network."""
assert isinstance(network, basestring) assert isinstance(network, minisix.string_types)
if nick not in self.nicks[network]: if nick not in self.nicks[network]:
raise KeyError raise KeyError
self.nicks[network].remove(nick) self.nicks[network].remove(nick)

View File

@ -809,7 +809,7 @@ def names(channel=None, prefix='', msg=None):
def mode(channel, args=(), prefix='', msg=None): def mode(channel, args=(), prefix='', msg=None):
if msg and not prefix: if msg and not prefix:
prefix = msg.prefix prefix = msg.prefix
if isinstance(args, basestring): if isinstance(args, minisix.string_types):
args = (args,) args = (args,)
else: else:
args = tuple(map(str, args)) args = tuple(map(str, args))

View File

@ -115,8 +115,8 @@ def toLower(s, casemapping=None):
def strEqual(nick1, nick2): def strEqual(nick1, nick2):
"""s1, s2 => bool """s1, s2 => bool
Returns True if nick1 == nick2 according to IRC case rules.""" Returns True if nick1 == nick2 according to IRC case rules."""
assert isinstance(nick1, basestring) assert isinstance(nick1, minisix.string_types)
assert isinstance(nick2, basestring) assert isinstance(nick2, minisix.string_types)
return toLower(nick1) == toLower(nick2) return toLower(nick1) == toLower(nick2)
nickEqual = strEqual nickEqual = strEqual
@ -609,7 +609,7 @@ def safeArgument(s):
"""If s is unsafe for IRC, returns a safe version.""" """If s is unsafe for IRC, returns a safe version."""
if minisix.PY2 and isinstance(s, unicode): if minisix.PY2 and isinstance(s, unicode):
s = s.encode('utf-8') s = s.encode('utf-8')
elif (minisix.PY2 and not isinstance(s, basestring)) or \ elif (minisix.PY2 and not isinstance(s, minisix.string_types)) or \
(minisix.PY3 and not isinstance(s, str)): (minisix.PY3 and not isinstance(s, str)):
debug('Got a non-string in safeArgument: %r', s) debug('Got a non-string in safeArgument: %r', s)
s = str(s) s = str(s)

View File

@ -37,7 +37,7 @@ import operator
import textwrap import textwrap
import traceback import traceback
from . import ansi, conf, ircutils, registry, utils from . import ansi, conf, ircutils, minisix, registry, utils
deadlyExceptions = [KeyboardInterrupt, SystemExit] deadlyExceptions = [KeyboardInterrupt, SystemExit]
@ -95,7 +95,7 @@ class StdoutStreamHandler(logging.StreamHandler):
if record.levelname != 'ERROR' and conf.supybot.log.stdout.wrap(): if record.levelname != 'ERROR' and conf.supybot.log.stdout.wrap():
# We check for ERROR there because otherwise, tracebacks (which are # We check for ERROR there because otherwise, tracebacks (which are
# already wrapped by Python itself) wrap oddly. # already wrapped by Python itself) wrap oddly.
if not isinstance(record.levelname, basestring): if not isinstance(record.levelname, minisix.string_types):
print(record) print(record)
print(record.levelname) print(record.levelname)
print(utils.stackTrace()) print(utils.stackTrace())

View File

@ -36,6 +36,7 @@ if sys.version_info[0] >= 3:
PY3 = True PY3 = True
intern = sys.intern intern = sys.intern
integer_types = (int,) integer_types = (int,)
string_types = (str,)
long = int long = int
import io import io
@ -51,6 +52,7 @@ else:
else: else:
intern = __builtins__.intern intern = __builtins__.intern
integer_types = (int, long) integer_types = (int, long)
string_types = (basestring,)
long = long long = long
class io: class io:

View File

@ -517,7 +517,7 @@ class String(Value):
v = repr(v) v = repr(v)
try: try:
v = utils.safeEval(v) v = utils.safeEval(v)
if not isinstance(v, basestring): if not isinstance(v, minisix.string_types):
raise ValueError raise ValueError
self.setValue(v) self.setValue(v)
except ValueError: # This catches utils.safeEval(s) errors too. except ValueError: # This catches utils.safeEval(s) errors too.

View File

@ -7,6 +7,8 @@
import os.path import os.path
import sys import sys
from . import minisix
__all__ = ["shlex"] __all__ = ["shlex"]
class shlex: class shlex:
@ -190,7 +192,7 @@ class shlex:
if newfile[0] == '"': if newfile[0] == '"':
newfile = newfile[1:-1] newfile = newfile[1:-1]
# This implements cpp-like semantics for relative-path inclusion. # This implements cpp-like semantics for relative-path inclusion.
if isinstance(self.infile, basestring) and not os.path.isabs(newfile): if isinstance(self.infile, minisix.string_types) and not os.path.isabs(newfile):
newfile = os.path.join(os.path.dirname(self.infile), newfile) newfile = os.path.join(os.path.dirname(self.infile), newfile)
return (newfile, open(newfile, "r")) return (newfile, open(newfile, "r"))

View File

@ -34,6 +34,8 @@ import random
from itertools import * from itertools import *
from .. import minisix
# For old plugins # For old plugins
ifilter = filter ifilter = filter
def filterfalse(p, L): def filterfalse(p, L):
@ -102,7 +104,7 @@ def flatten(iterable, strings=False):
"""Flattens a list of lists into a single list. See the test for examples. """Flattens a list of lists into a single list. See the test for examples.
""" """
for elt in iterable: for elt in iterable:
if not strings and isinstance(elt, basestring): if not strings and isinstance(elt, minisix.string_types):
yield elt yield elt
else: else:
try: try:
@ -115,7 +117,7 @@ def split(isSeparator, iterable, maxsplit=-1, yieldEmpty=False):
"""split(isSeparator, iterable, maxsplit=-1, yieldEmpty=False) """split(isSeparator, iterable, maxsplit=-1, yieldEmpty=False)
Splits an iterator based on a predicate isSeparator.""" Splits an iterator based on a predicate isSeparator."""
if isinstance(isSeparator, basestring): if isinstance(isSeparator, minisix.string_types):
f = lambda s: s == isSeparator f = lambda s: s == isSeparator
else: else:
f = isSeparator f = isSeparator

View File

@ -539,7 +539,7 @@ def format(s, *args, **kwargs):
if isinstance(t, tuple) and len(t) == 2: if isinstance(t, tuple) and len(t) == 2:
if not isinstance(t[0], list): if not isinstance(t[0], list):
raise ValueError('Invalid list for %%L in format: %s' % t) raise ValueError('Invalid list for %%L in format: %s' % t)
if not isinstance(t[1], basestring): if not isinstance(t[1], minisix.string_types):
raise ValueError('Invalid string for %%L in format: %s' % t) raise ValueError('Invalid string for %%L in format: %s' % t)
return commaAndify(t[0], And=t[1]) return commaAndify(t[0], And=t[1])
elif hasattr(t, '__iter__'): elif hasattr(t, '__iter__'):