2017-01-22 06:21:03 +01:00
|
|
|
import os
|
|
|
|
import shutil
|
2017-01-24 09:25:52 +01:00
|
|
|
import sys
|
2017-01-22 06:21:03 +01:00
|
|
|
|
|
|
|
from elodie import constants
|
|
|
|
|
2017-01-22 09:19:44 +01:00
|
|
|
|
2017-01-24 09:25:52 +01:00
|
|
|
def _decode(string, encoding=sys.getfilesystemencoding()):
|
2017-01-08 23:43:01 +01:00
|
|
|
"""Return a utf8 encoded unicode string.
|
|
|
|
|
|
|
|
Python2 and Python3 differ in how they handle strings.
|
|
|
|
So we do a few checks to see if the string is ascii or unicode.
|
|
|
|
Then we decode it if needed.
|
|
|
|
"""
|
2016-12-26 17:20:12 +01:00
|
|
|
if hasattr(string, 'decode'):
|
2017-01-08 23:43:01 +01:00
|
|
|
# If the string is already unicode we return it.
|
|
|
|
try:
|
|
|
|
if isinstance(string, unicode):
|
|
|
|
return string
|
|
|
|
except NameError:
|
|
|
|
pass
|
|
|
|
|
2016-12-26 17:20:12 +01:00
|
|
|
return string.decode(encoding)
|
|
|
|
|
|
|
|
return string
|
|
|
|
|
2019-07-12 09:40:38 +02:00
|
|
|
def _bytes(string):
|
|
|
|
if constants.python_version == 3:
|
|
|
|
return bytes(string, 'utf8')
|
|
|
|
else:
|
|
|
|
return bytes(string)
|
2017-01-22 09:19:44 +01:00
|
|
|
|