misc: use six.string_types to check (str, unicode) (#36515)

This commit is contained in:
Frédéric Péters 2019-11-12 19:44:52 +01:00
parent 7d7cea05a6
commit ef77a23f79
4 changed files with 10 additions and 12 deletions

View File

@ -14,6 +14,7 @@
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
from django.utils import six
from django.utils.encoding import force_text
from quixote import get_publisher, get_response, get_request, get_session, redirect
@ -312,7 +313,7 @@ class UsersDirectory(Directory):
checked_roles = None
if get_request().form.get('filter'):
checked_roles = get_request().form.get('role', [])
if type(checked_roles) in (str, unicode):
if isinstance(checked_roles, six.string_types):
checked_roles = [checked_roles]
if checked_roles:

View File

@ -28,6 +28,7 @@ import collections
from quixote import get_request, get_publisher
from quixote.html import htmltext, TemplateIO
from django.utils import six
from django.utils.encoding import force_text, smart_text
from django.utils.formats import date_format as django_date_format
from django.utils.html import urlize
@ -254,11 +255,8 @@ class Field(object):
atname = 'item'
for v in val:
ET.SubElement(el, atname).text = force_text(v, charset, errors='replace')
elif type(val) in (str, unicode):
if type(val) is unicode:
el.text = val
else:
el.text = force_text(val, charset, errors='replace')
elif isinstance(val, six.string_types):
el.text = force_text(val, charset, errors='replace')
else:
el.text = str(val)
return field

View File

@ -45,6 +45,7 @@ import xml.etree.ElementTree as ET
from django.conf import settings
from django.http import Http404
from django.utils import six
from django.utils import translation
from django.utils.encoding import force_text, force_bytes
from django.utils.six import StringIO
@ -723,7 +724,7 @@ class QommonPublisher(Publisher, object):
for v in val:
ET.SubElement(elem, 'item').text = v
elif type(val) in (str, unicode):
elif isinstance(val, six.string_types):
elem.text = val
else:

View File

@ -25,6 +25,7 @@ import sys
import time
import uuid
from django.utils import six
from django.utils.encoding import force_text
from django.utils.six import StringIO
@ -854,11 +855,8 @@ class XmlSerialisable(object):
atname = 'item'
for v in val:
ET.SubElement(el, atname).text = force_text(str(v), charset, errors='replace')
elif type(val) in (str, unicode):
if type(val) is unicode:
el.text = val
else:
el.text = force_text(val, charset, errors='replace')
elif isinstance(val, six.string_types):
el.text = force_text(val, charset, errors='replace')
else:
el.text = str(val)
return node