py3: Replace basestring with six.string_types

The builtin basestring type was removed in Python 3. Replace it with
six.string_types which works on Python 2 and Python 3.

Change-Id: Ib92a729682322cc65b41050ae169167be2899e2c
This commit is contained in:
Victor Stinner 2015-10-08 15:42:27 +02:00
parent 2447e0cf6e
commit 84f0a54445
4 changed files with 8 additions and 4 deletions

View File

@ -133,7 +133,9 @@ def check_metadata(req, target_type):
meta_count = 0
meta_size = 0
for key, value in req.headers.items():
if isinstance(value, basestring) and len(value) > MAX_HEADER_SIZE:
if (isinstance(value, six.string_types)
and len(value) > MAX_HEADER_SIZE):
return HTTPBadRequest(body='Header value too long: %s' %
key[:MAX_META_NAME_LENGTH],
request=req, content_type='text/plain')

View File

@ -23,6 +23,7 @@ import socket
from time import time
from eventlet import sleep, Timeout
import six
from six.moves.http_client import HTTPException
from swift.common.bufferedhttp import http_connect
@ -399,7 +400,7 @@ def direct_put_object(node, part, account, container, name, contents,
headers['Content-Type'] = 'application/octet-stream'
if not contents:
headers['Content-Length'] = '0'
if isinstance(contents, basestring):
if isinstance(contents, six.string_types):
contents = [contents]
# Incase the caller want to insert an object with specific age
add_ts = 'X-Timestamp' not in headers

View File

@ -23,6 +23,7 @@ import hmac
import base64
from eventlet import Timeout
import six
from six.moves.urllib.parse import unquote
from swift.common.swob import Response, Request
from swift.common.swob import HTTPBadRequest, HTTPForbidden, HTTPNotFound, \
@ -460,7 +461,7 @@ class TempAuth(object):
if not isinstance(result[key], list):
return "Value for key '%s' must be a list" % key
for grantee in result[key]:
if not isinstance(grantee, basestring):
if not isinstance(grantee, six.string_types):
return "Elements of '%s' list must be strings" % key
# Everything looks fine, no errors found

View File

@ -30,7 +30,7 @@ from swift.common.ring import RingBuilder
class RunSwiftRingBuilderMixin(object):
def run_srb(self, *argv):
if len(argv) == 1 and isinstance(argv[0], basestring):
if len(argv) == 1 and isinstance(argv[0], six.string_types):
# convert a single string to a list
argv = shlex.split(argv[0])
mock_stdout = six.StringIO()