Change unicode() --> six.text_type() for Python 3

This commit is contained in:
cclauss
2018-02-08 22:04:08 +01:00
parent 7e42c54868
commit 2e623ad80c
16 changed files with 68 additions and 48 deletions

View File

@@ -43,7 +43,7 @@ logger = logging.getLogger('awx.main.utils')
__all__ = ['get_object_or_400', 'get_object_or_403', 'camelcase_to_underscore', 'memoize', 'memoize_delete',
'get_ansible_version', 'get_ssh_version', 'get_licenser', 'get_awx_version', 'update_scm_url',
'get_type_for_model', 'get_model_for_type', 'copy_model_by_class',
'copy_m2m_relationships' ,'cache_list_capabilities', 'to_python_boolean',
'copy_m2m_relationships', 'cache_list_capabilities', 'to_python_boolean',
'ignore_inventory_computed_fields', 'ignore_inventory_group_removal',
'_inventory_updates', 'get_pk_from_dict', 'getattrd', 'NoDefaultProvided',
'get_current_apps', 'set_current_apps', 'OutputEventFilter',
@@ -84,7 +84,7 @@ def get_object_or_403(klass, *args, **kwargs):
def to_python_boolean(value, allow_none=False):
value = unicode(value)
value = six.text_type(value)
if value.lower() in ('true', '1', 't'):
return True
elif value.lower() in ('false', '0', 'f'):
@@ -92,7 +92,7 @@ def to_python_boolean(value, allow_none=False):
elif allow_none and value.lower() in ('none', 'null'):
return None
else:
raise ValueError(_(u'Unable to convert "%s" to boolean') % unicode(value))
raise ValueError(_(u'Unable to convert "%s" to boolean') % six.text_type(value))
def camelcase_to_underscore(s):
@@ -325,7 +325,7 @@ def update_scm_url(scm_type, url, username=True, password=True,
netloc = u''
netloc = u'@'.join(filter(None, [netloc, parts.hostname]))
if parts.port:
netloc = u':'.join([netloc, unicode(parts.port)])
netloc = u':'.join([netloc, six.text_type(parts.port)])
new_url = urlparse.urlunsplit([parts.scheme, netloc, parts.path,
parts.query, parts.fragment])
if scp_format and parts.scheme == 'git+ssh':

View File

@@ -8,6 +8,8 @@ from pyparsing import (
ParseException,
)
import six
import django
from awx.main.utils.common import get_search_fields
@@ -54,12 +56,12 @@ class SmartFilter(object):
self.result = Host.objects.filter(**kwargs)
def strip_quotes_traditional_logic(self, v):
if type(v) is unicode and v.startswith('"') and v.endswith('"'):
if type(v) is six.text_type and v.startswith('"') and v.endswith('"'):
return v[1:-1]
return v
def strip_quotes_json_logic(self, v):
if type(v) is unicode and v.startswith('"') and v.endswith('"') and v != u'"null"':
if type(v) is six.text_type and v.startswith('"') and v.endswith('"') and v != u'"null"':
return v[1:-1]
return v
@@ -138,7 +140,7 @@ class SmartFilter(object):
# value
# ="something"
if t_len > (v_offset + 2) and t[v_offset] == "\"" and t[v_offset + 2] == "\"":
v = u'"' + unicode(t[v_offset + 1]) + u'"'
v = u'"' + six.text_type(t[v_offset + 1]) + u'"'
#v = t[v_offset + 1]
# empty ""
elif t_len > (v_offset + 1):
@@ -207,9 +209,9 @@ class SmartFilter(object):
* handle key with __ in it
'''
filter_string_raw = filter_string
filter_string = unicode(filter_string)
filter_string = six.text_type(filter_string)
unicode_spaces = list(set(unicode(c) for c in filter_string if c.isspace()))
unicode_spaces = list(set(six.text_type(c) for c in filter_string if c.isspace()))
unicode_spaces_other = unicode_spaces + [u'(', u')', u'=', u'"']
atom = CharsNotIn(unicode_spaces_other)
atom_inside_quotes = CharsNotIn(u'"')