mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Remove duplicated code
This commit is contained in:
parent
40d0e6bed2
commit
77f1c44638
1 changed files with 11 additions and 18 deletions
|
@ -95,24 +95,17 @@ Python 2: If ``s`` is an instance of ``text_type``, return
|
|||
'''
|
||||
|
||||
|
||||
if PY3:
|
||||
def native_(s, encoding='latin-1', errors='strict'):
|
||||
'''
|
||||
If ``s`` is an instance of ``text_type``, return
|
||||
``s``, otherwise return ``str(s, encoding, errors)``
|
||||
'''
|
||||
if isinstance(s, text_type):
|
||||
return s
|
||||
return str(s, encoding, errors)
|
||||
else:
|
||||
def native_(s, encoding='latin-1', errors='strict'):
|
||||
'''
|
||||
If ``s`` is an instance of ``text_type``, return
|
||||
``s.encode(encoding, errors)``, otherwise return ``str(s)``
|
||||
'''
|
||||
if isinstance(s, text_type):
|
||||
return s.encode(encoding, errors)
|
||||
return str(s)
|
||||
def native_(s, encoding='latin-1', errors='strict'):
|
||||
'''
|
||||
If ``s`` is an instance of ``text_type``, return
|
||||
``s``, otherwise return ``str(s, encoding, errors)``
|
||||
'''
|
||||
if PY3:
|
||||
out = s if isinstance(s, text_type) else str(s, encoding, errors)
|
||||
else:
|
||||
out = s.encode(encoding, errors) if isinstance(s, text_type) else str(s)
|
||||
|
||||
return out
|
||||
|
||||
native_.__doc__ = '''
|
||||
Python 3: If ``s`` is an instance of ``text_type``, return ``s``, otherwise
|
||||
|
|
Loading…
Add table
Reference in a new issue