Move encoding detection inside if condition.

This commit is contained in:
Umair Khan
2016-07-19 09:44:40 +05:00
parent e61f0a68c4
commit 911efd1db4

View File

@@ -47,8 +47,8 @@ def to_unicode(str_or_unicode, precise=False):
u'привет' u'привет'
If `precise` flag is True, tries to guess the correct encoding first. If `precise` flag is True, tries to guess the correct encoding first.
""" """
encoding = quick_detect_encoding(str_or_unicode) if precise else 'utf-8'
if not isinstance(str_or_unicode, six.text_type): if not isinstance(str_or_unicode, six.text_type):
encoding = quick_detect_encoding(str_or_unicode) if precise else 'utf-8'
return six.text_type(str_or_unicode, encoding, 'replace') return six.text_type(str_or_unicode, encoding, 'replace')
return str_or_unicode return str_or_unicode