Use python-six when testing string types, start aiming for Python 3 compat
This commit is contained in:
parent
c3f8d5fea1
commit
54f036b36c
|
@ -1,4 +1,5 @@
|
|||
import sys
|
||||
import six
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
|
@ -9,7 +10,7 @@ class Setting(object):
|
|||
|
||||
def __init__(self, default=SENTINEL, definition='', names=None):
|
||||
self.names = names or []
|
||||
if isinstance(self.names, basestring):
|
||||
if isinstance(self.names, six.string_types):
|
||||
self.names = [self.names]
|
||||
self.names = set(self.names)
|
||||
self.default = default
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
import logging
|
||||
from operator import attrgetter, __or__
|
||||
import six
|
||||
|
||||
|
||||
from authentic2.attribute_aggregator.core import (get_profile_field_name_from_definition,
|
||||
|
@ -128,7 +129,7 @@ def get_attributes(user, definitions=None, source=None, auth_source=False, **kwa
|
|||
value = value.all()
|
||||
logger.debug('field %r has value %r', field_name, value)
|
||||
old = data.get(definition, [])
|
||||
if not isinstance(value, basestring) and hasattr(value,
|
||||
if not isinstance(value, six.string_types) and hasattr(value,
|
||||
'__iter__'):
|
||||
new = map(unicode, value)
|
||||
else:
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import six
|
||||
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
|
||||
from ...decorators import to_list
|
||||
|
@ -43,7 +45,7 @@ def get_instances(ctx):
|
|||
config_error(UNEXPECTED_KEYS_ERROR, unexpected)
|
||||
if 'name' not in keys or 'template' not in keys:
|
||||
config_error(BAD_CONFIG_ERROR)
|
||||
if not isinstance(d['template'], basestring):
|
||||
if not isinstance(d['template'], six.string_types):
|
||||
config_error(TYPE_ERROR)
|
||||
yield d
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import base64
|
||||
import six
|
||||
|
||||
from . import app_settings
|
||||
|
||||
|
@ -52,7 +53,7 @@ class SSLInfo(object):
|
|||
|
||||
def read_env(self, env):
|
||||
for attr, keys in X509_KEYS.iteritems():
|
||||
if isinstance(keys, basestring):
|
||||
if isinstance(keys, six.string_types):
|
||||
keys = [keys]
|
||||
for key in keys:
|
||||
if key in env and env[key]:
|
||||
|
|
|
@ -11,6 +11,7 @@ import pickle
|
|||
import base64
|
||||
import urllib
|
||||
import itertools
|
||||
import six
|
||||
|
||||
# code originaly copied from by now merely inspired by
|
||||
# http://www.amherst.k12.oh.us/django-ldap.html
|
||||
|
@ -248,8 +249,8 @@ class LDAPBackend(object):
|
|||
if d not in block:
|
||||
block[d] = _DEFAULTS[d]
|
||||
else:
|
||||
if isinstance(_DEFAULTS[d], basestring):
|
||||
if not isinstance(block[d], basestring):
|
||||
if isinstance(_DEFAULTS[d], six.string_types):
|
||||
if not isinstance(block[d], six.string_types):
|
||||
raise ImproperlyConfigured('LDAP_AUTH_SETTINGS: '
|
||||
'attribute %r must be a string' % d)
|
||||
try:
|
||||
|
@ -270,19 +271,19 @@ class LDAPBackend(object):
|
|||
raise ImproperlyConfigured('LDAP_AUTH_SETTINGS: '
|
||||
'attribute %r is required but is empty')
|
||||
for i in _TO_ITERABLE:
|
||||
if isinstance(block[i], basestring):
|
||||
if isinstance(block[i], six.string_types):
|
||||
block[i] = (block[i],)
|
||||
# lowercase LDAP attribute names
|
||||
block['external_id_tuples'] = map(lambda t: map(str.lower, map(str, t)), block['external_id_tuples'])
|
||||
block['attribute_mappings'] = map(lambda t: map(str.lower, map(str, t)), block['attribute_mappings'])
|
||||
for key in _TO_LOWERCASE:
|
||||
# we handle strings, list of strings and list of list or tuple whose first element is a string
|
||||
if isinstance(block[key], basestring):
|
||||
if isinstance(block[key], six.string_types):
|
||||
block[key] = str(block[key]).lower()
|
||||
elif isinstance(block[key], (list, tuple)):
|
||||
new_seq = []
|
||||
for elt in block[key]:
|
||||
if isinstance(elt, basestring):
|
||||
if isinstance(elt, six.string_types):
|
||||
elt = str(elt).lower()
|
||||
elif isinstance(elt, (list, tuple)):
|
||||
elt = list(elt)
|
||||
|
|
|
@ -2,6 +2,7 @@ try:
|
|||
import cPickle as pickle
|
||||
except ImportError:
|
||||
import pickle
|
||||
import six
|
||||
|
||||
from django import forms
|
||||
from django.db import models
|
||||
|
@ -136,7 +137,7 @@ class MultiSelectField(models.Field):
|
|||
return MultiSelectFormField(**defaults)
|
||||
|
||||
def get_db_prep_value(self, value, connection, prepared=False):
|
||||
if isinstance(value, basestring):
|
||||
if isinstance(value, six.string_types):
|
||||
return value
|
||||
elif isinstance(value, list):
|
||||
return ",".join(value)
|
||||
|
|
|
@ -2,6 +2,7 @@ import xml.etree.ElementTree as etree
|
|||
import hashlib
|
||||
import numbers
|
||||
import datetime
|
||||
import six
|
||||
|
||||
import requests
|
||||
from authentic2.compat import lasso
|
||||
|
@ -392,7 +393,7 @@ class SAMLAttribute(models.Model):
|
|||
if self.friendly_name:
|
||||
at.friendlyName = self.friendly_name.encode('utf-8')
|
||||
values = ctx.get(self.attribute_name)
|
||||
if isinstance(values, (basestring, numbers.Number, datetime.datetime, datetime.date)):
|
||||
if isinstance(values, tuple(six.string_types) + (numbers.Number, datetime.datetime, datetime.date)):
|
||||
values = [values]
|
||||
elif isinstance(values, (tuple, list)):
|
||||
pass
|
||||
|
|
|
@ -4,12 +4,13 @@ import tempfile
|
|||
import os
|
||||
import subprocess
|
||||
import stat
|
||||
import six
|
||||
|
||||
_openssl = 'openssl'
|
||||
|
||||
def decapsulate_pem_file(file_or_string):
|
||||
'''Remove PEM header lines'''
|
||||
if not isinstance(file_or_string, basestring):
|
||||
if not isinstance(file_or_string, six.string_types):
|
||||
content = file_or_string.read()
|
||||
else:
|
||||
content = file_or_string
|
||||
|
|
|
@ -3,6 +3,7 @@ import hashlib
|
|||
import datetime as dt
|
||||
import logging
|
||||
import urllib
|
||||
import six
|
||||
|
||||
from importlib import import_module
|
||||
|
||||
|
@ -110,7 +111,7 @@ def cache_and_validate(timeout, hashing=hashlib.md5):
|
|||
@condition(etag_func=get_etag, last_modified_func=get_last_modified)
|
||||
def replacement(request, *args, **kwargs):
|
||||
_, _, _, content_type, content = get_content(request, *args, **kwargs)
|
||||
if isinstance(content, basestring):
|
||||
if isinstance(content, six.string_types):
|
||||
return HttpResponse(content, content_type=content_type)
|
||||
else:
|
||||
return content
|
||||
|
@ -202,7 +203,7 @@ class Service(object):
|
|||
|
||||
def field_names(list_of_field_name_and_titles):
|
||||
for t in list_of_field_name_and_titles:
|
||||
if isinstance(t, basestring):
|
||||
if isinstance(t, six.string_types):
|
||||
yield t
|
||||
else:
|
||||
yield t[0]
|
||||
|
|
|
@ -13,3 +13,4 @@ django-tables2
|
|||
gadjo
|
||||
django-import-export
|
||||
django-sekizai
|
||||
six
|
||||
|
|
Loading…
Reference in New Issue