use six types when calling isinstance() (#39533)
This commit is contained in:
parent
90bdb52e90
commit
37534c6980
|
@ -478,13 +478,13 @@ class AtrealOpenads(BaseResource, HTTPResource, BaseModel):
|
|||
# get its content
|
||||
file_content = dict_file[content_key]
|
||||
|
||||
if not isinstance(file_content, basestring):
|
||||
if not isinstance(file_content, (six.string_types, six.binary_type)):
|
||||
raise APIError(
|
||||
u"Expecting '%s' value in JSON %s in file dict to be a %s (not a %s)" %
|
||||
('file.%s' % content_key, title, 'string', type(file_content)))
|
||||
|
||||
# check filename
|
||||
if 'filename' in dict_file and not isinstance(dict_file['filename'], basestring):
|
||||
if 'filename' in dict_file and not isinstance(dict_file['filename'], six.string_types):
|
||||
raise APIError(
|
||||
u"Expecting '%s' value in JSON %s in file dict to be a %s (not a %s)" %
|
||||
('file.filename', title, 'string', type(dict_file['filename'])))
|
||||
|
@ -577,7 +577,7 @@ class AtrealOpenads(BaseResource, HTTPResource, BaseModel):
|
|||
now_fmt = '%Y-%m-%d %H:%M:%S'
|
||||
if not now:
|
||||
now = datetime.datetime.now()
|
||||
elif isinstance(now, basestring):
|
||||
elif isinstance(now, six.string_types):
|
||||
now = datetime.datetime.strptime(now, now_fmt)
|
||||
elif not isinstance(now, datetime.datetime):
|
||||
raise APIError(
|
||||
|
@ -810,7 +810,7 @@ class AtrealOpenads(BaseResource, HTTPResource, BaseModel):
|
|||
|
||||
numero_dossier = result.get('numero_dossier')
|
||||
|
||||
if not isinstance(numero_dossier, basestring):
|
||||
if not isinstance(numero_dossier, six.string_types):
|
||||
raise APIError(
|
||||
u"Expecting '%s' value in JSON response to be a %s (not a %s)" %
|
||||
('numero_dossier', 'string', type(numero_dossier)))
|
||||
|
@ -1103,7 +1103,7 @@ class AtrealOpenads(BaseResource, HTTPResource, BaseModel):
|
|||
if file_ids:
|
||||
|
||||
# if file_ids is a string
|
||||
if isinstance(file_ids, basestring):
|
||||
if isinstance(file_ids, six.string_types):
|
||||
file_ids = [int(fid) for fid in file_ids.split(',')]
|
||||
|
||||
# invalid input
|
||||
|
|
|
@ -89,8 +89,8 @@ def normalize(value):
|
|||
"""Normalize a value to be send to openADS.API."""
|
||||
if value is None:
|
||||
return ''
|
||||
if not isinstance(value, unicode):
|
||||
value = unicode(value)
|
||||
if not isinstance(value, six.text_type):
|
||||
value = force_text(value)
|
||||
return clean_spaces(value)
|
||||
|
||||
|
||||
|
@ -152,7 +152,7 @@ def trunc_str_values(value, limit, visited=None, truncate_text=u'…'):
|
|||
if visited is None:
|
||||
visited = []
|
||||
if value not in visited:
|
||||
if isinstance(value, basestring) and len(value) > limit:
|
||||
if isinstance(value, six.string_types) and len(value) > limit:
|
||||
value = value[:limit] + truncate_text
|
||||
elif isinstance(value, (dict, list, tuple)):
|
||||
visited.append(value)
|
||||
|
|
Reference in New Issue