Replace six dependancy by python3 code only
This commit is contained in:
@@ -1,6 +1,4 @@
|
|||||||
from __future__ import unicode_literals
|
import io
|
||||||
from six import BytesIO, binary_type
|
|
||||||
|
|
||||||
import re
|
import re
|
||||||
import email
|
import email
|
||||||
import base64
|
import base64
|
||||||
@@ -92,7 +90,7 @@ def parse_attachment(message_part):
|
|||||||
attachment = {
|
attachment = {
|
||||||
'content-type': message_part.get_content_type(),
|
'content-type': message_part.get_content_type(),
|
||||||
'size': len(file_data),
|
'size': len(file_data),
|
||||||
'content': BytesIO(file_data)
|
'content': io.BytesIO(file_data)
|
||||||
}
|
}
|
||||||
filename = message_part.get_param('name')
|
filename = message_part.get_param('name')
|
||||||
if filename:
|
if filename:
|
||||||
@@ -122,7 +120,7 @@ def decode_content(message):
|
|||||||
|
|
||||||
|
|
||||||
def parse_email(raw_email, policy=None):
|
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')
|
raw_email = str_encode(raw_email, 'utf-8')
|
||||||
if policy is not None:
|
if policy is not None:
|
||||||
email_parse_kwargs = dict(policy=policy)
|
email_parse_kwargs = dict(policy=policy)
|
||||||
|
|||||||
@@ -1,24 +1,16 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
from six import PY3
|
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
logger = logging.getLogger(__name__)
|
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))
|
||||||
logger.debug("Encode str {} with and errors {}".format(value, encoding, errors))
|
return str(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):
|
if isinstance(value, str):
|
||||||
return bytes(value, encoding, errors).decode('utf-8')
|
return bytes(value, encoding, errors).decode('utf-8')
|
||||||
elif isinstance(value, bytes):
|
elif isinstance(value, bytes):
|
||||||
return value.decode(encoding or 'utf-8', errors=errors)
|
return value.decode(encoding or 'utf-8', errors=errors)
|
||||||
else:
|
else:
|
||||||
raise TypeError( "Cannot decode '{}' object".format(value.__class__) )
|
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)
|
|
||||||
|
|||||||
1
setup.py
1
setup.py
@@ -20,7 +20,6 @@ setup(
|
|||||||
packages=['imbox'],
|
packages=['imbox'],
|
||||||
package_dir={'imbox': 'imbox'},
|
package_dir={'imbox': 'imbox'},
|
||||||
zip_safe=False,
|
zip_safe=False,
|
||||||
install_requires=['six'],
|
|
||||||
classifiers=(
|
classifiers=(
|
||||||
'Programming Language :: Python',
|
'Programming Language :: Python',
|
||||||
'Programming Language :: Python :: 3.2',
|
'Programming Language :: Python :: 3.2',
|
||||||
|
|||||||
Reference in New Issue
Block a user