Skip to content

Commit 9850464

Browse files
committed
Simplify Base64
1 parent 7cdae67 commit 9850464

File tree

2 files changed

+5
-13
lines changed

2 files changed

+5
-13
lines changed

shotgun_api3/shotgun.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3030
"""
3131

32+
import base64
3233
import copy
3334
import datetime
3435
import json
@@ -59,11 +60,6 @@
5960
from .lib.httplib2 import Http, ProxyInfo, socks, ssl_error_classes
6061
from .lib.sgtimezone import SgTimezone
6162

62-
if six.PY3:
63-
from base64 import encodebytes as base64encode
64-
else:
65-
from base64 import encodestring as base64encode
66-
6763

6864
LOG = logging.getLogger("shotgun_api3")
6965
"""
@@ -709,11 +705,11 @@ def __init__(
709705
# and auth header
710706

711707
# Do NOT self._split_url(self.base_url) here, as it contains the lower
712-
# case version of the base_url argument. Doing so would base64encode
708+
# case version of the base_url argument. Doing so would base64.encodebytes
713709
# the lowercase version of the credentials.
714710
auth, self.config.server = self._split_url(base_url)
715711
if auth:
716-
auth = base64encode(
712+
auth = base64.encodebytes(
717713
urllib.parse.unquote(auth).encode("utf-8")
718714
).decode("utf-8")
719715
self.config.authorization = "Basic " + auth.strip()

tests/test_client.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
CRUD functions. These tests always use a mock http connection so not not
1313
need a live server to run against."""
1414

15+
import base64
1516
import datetime
1617
import json
1718
import os
@@ -32,17 +33,12 @@
3233
from shotgun_api3.shotgun import ServerCapabilities, SG_TIMEZONE
3334
from . import base
3435

35-
if six.PY3:
36-
from base64 import encodebytes as base64encode
37-
else:
38-
from base64 import encodestring as base64encode
39-
4036

4137
def b64encode(val):
4238
if isinstance(val, str):
4339
val = val.encode("utf-8")
4440

45-
return base64encode(val).decode("utf-8")
41+
return base64.encodebytes(val).decode("utf-8")
4642

4743

4844
class TestShotgunClient(base.MockTestBase):

0 commit comments

Comments
 (0)