Skip to content

Commit f83960e

Browse files
authored
Merge pull request #9 from fcurella/py3
Drop Python 2
2 parents dccb2d3 + cf551f4 commit f83960e

5 files changed

Lines changed: 12 additions & 30 deletions

File tree

.travis.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@ branches:
44
only:
55
- master
66
python:
7-
- 2.7
8-
- 3.4
97
- 3.5
108
- 3.6
119
- 3.7
1210
- 3.8
13-
- "pypy"
11+
- 3.9
1412
- "pypy3"
1513
env:
1614
global:

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Parsing
3838
b'The quick brown fox jumped over the lazy dog.'
3939
4040
Note that ``DataURI.data`` will always return bytes, (which in Python 2 is the same as a string).
41-
Use ``DataURI.text`` to get the text type (``str`` on Python 3.x, ``unicode`` on Python 2.x).
41+
Use ``DataURI.text`` to get a string.
4242

4343
Creating from a string
4444
----------------------

datauri/__init__.py

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,10 @@
55
from base64 import b64decode as decode64
66
from base64 import b64encode as encode64
77

8-
try:
9-
from urllib.parse import quote, unquote
10-
BYTES = True
11-
except ImportError:
12-
from urllib import quote, unquote
13-
BYTES = False
14-
8+
from urllib.parse import quote, unquote
159

1610
from .exceptions import InvalidCharset, InvalidDataURI, InvalidMimeType
1711

18-
1912
MIMETYPE_REGEX = r'[\w]+\/[\w\-\+\.]+'
2013
_MIMETYPE_RE = re.compile('^{}$'.format(MIMETYPE_REGEX))
2114

@@ -47,15 +40,12 @@ def make(cls, mimetype, charset, base64, data):
4740
parts.extend([';charset=', charset])
4841
if base64:
4942
parts.append(';base64')
50-
if BYTES:
51-
_charset = charset or 'utf-8'
52-
if isinstance(data, bytes):
53-
_data = data
54-
else:
55-
_data = bytes(data, _charset)
56-
encoded_data = encode64(_data).decode(_charset).strip()
43+
_charset = charset or 'utf-8'
44+
if isinstance(data, bytes):
45+
_data = data
5746
else:
58-
encoded_data = encode64(data).strip()
47+
_data = bytes(data, _charset)
48+
encoded_data = encode64(_data).decode(_charset).strip()
5949
else:
6050
encoded_data = quote(data)
6151
parts.extend([',', encoded_data])
@@ -120,12 +110,9 @@ def _parse(self):
120110
charset = match.group('charset') or None
121111

122112
if match.group('base64'):
123-
if BYTES:
124-
_charset = charset or 'utf-8'
125-
_data = bytes(match.group('data'), _charset)
126-
data = decode64(_data)
127-
else:
128-
data = decode64(match.group('data'))
113+
_charset = charset or 'utf-8'
114+
_data = bytes(match.group('data'), _charset)
115+
data = decode64(_data)
129116
else:
130117
data = unquote(match.group('data'))
131118

setup.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,12 @@ def read(fname):
2929
'License :: OSI Approved :: MIT License',
3030
'Operating System :: OS Independent',
3131
'Programming Language :: Python',
32-
'Programming Language :: Python :: 2',
33-
'Programming Language :: Python :: 2.7',
3432
'Programming Language :: Python :: 3',
35-
'Programming Language :: Python :: 3.4',
3633
'Programming Language :: Python :: 3.5',
3734
'Programming Language :: Python :: 3.6',
3835
'Programming Language :: Python :: 3.7',
3936
'Programming Language :: Python :: 3.8',
37+
'Programming Language :: Python :: 3.9',
4038
],
4139
test_suite='tests',
4240
)

tests/test_parsing.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
from datauri import DataURI, exceptions
55

6-
76
TEST_DIR = os.path.dirname(__file__)
87

98

0 commit comments

Comments
 (0)