Replace six dependancy by python3 code only

This commit is contained in:
Stéphane Blondon
2017-09-15 14:38:27 +02:00
parent fd55ac54c5
commit 43dff01fa3
3 changed files with 13 additions and 24 deletions

View File

@@ -1,6 +1,4 @@
from __future__ import unicode_literals
from six import BytesIO, binary_type
import io
import re
import email
import base64
@@ -92,7 +90,7 @@ def parse_attachment(message_part):
attachment = {
'content-type': message_part.get_content_type(),
'size': len(file_data),
'content': BytesIO(file_data)
'content': io.BytesIO(file_data)
}
filename = message_part.get_param('name')
if filename:
@@ -122,7 +120,7 @@ def decode_content(message):
def parse_email(raw_email, policy=None):
if isinstance(raw_email, binary_type):
if isinstance(raw_email, bytes):
raw_email = str_encode(raw_email, 'utf-8')
if policy is not None:
email_parse_kwargs = dict(policy=policy)

View File

@@ -1,24 +1,16 @@
from __future__ import unicode_literals
from six import PY3
import logging
logger = logging.getLogger(__name__)
if PY3:
def str_encode(value='', encoding=None, errors='strict'):
def str_encode(value='', encoding=None, errors='strict'):
logger.debug("Encode str {} with and errors {}".format(value, encoding, errors))
return str(value, encoding, errors)
def str_decode(value='', encoding=None, errors='strict'):
def str_decode(value='', encoding=None, errors='strict'):
if isinstance(value, str):
return bytes(value, encoding, errors).decode('utf-8')
elif isinstance(value, bytes):
return value.decode(encoding or 'utf-8', errors=errors)
else:
raise TypeError( "Cannot decode '{}' object".format(value.__class__) )
else:
def str_encode(string='', encoding=None, errors='strict'):
return unicode(string, encoding, errors)
def str_decode(value='', encoding=None, errors='strict'):
return value.decode(encoding, errors)

View File

@@ -20,7 +20,6 @@ setup(
packages=['imbox'],
package_dir={'imbox': 'imbox'},
zip_safe=False,
install_requires=['six'],
classifiers=(
'Programming Language :: Python',
'Programming Language :: Python :: 3.2',