Skip to content

Commit

Permalink
Remove six dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
hbldh committed May 7, 2023
1 parent ba592d4 commit 52e33f7
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions bankid/jsonclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
Created on 2018-02-19 by hbldh
"""
import os
import six
import base64
from urllib import parse as urlparse

Expand All @@ -18,6 +16,13 @@
from bankid.exceptions import get_json_error_class


def _encode_user_data(user_data):
if isinstance(user_data, str):
return base64.b64encode(user_data.encode("utf-8")).decode("ascii")
else:
return base64.b64encode(user_data).decode("ascii")


class BankIDJSONClient(object):
"""The client to use for communicating with BankID servers via the v.5 API.
Expand Down Expand Up @@ -114,7 +119,7 @@ def sign(
user_non_visible_data=None,
**kwargs
):
"""Request an signing order. The :py:meth:`collect` method
"""Request a signing order. The :py:meth:`collect` method
is used to query the status of the order.
Note that personal number is not needed when signing is to be done
Expand Down Expand Up @@ -157,9 +162,9 @@ def sign(
data = {"endUserIp": end_user_ip}
if personal_number:
data["personalNumber"] = personal_number
data["userVisibleData"] = self._encode_user_data(user_visible_data)
data["userVisibleData"] = _encode_user_data(user_visible_data)
if user_non_visible_data:
data["userNonVisibleData"] = self._encode_user_data(user_non_visible_data)
data["userNonVisibleData"] = _encode_user_data(user_non_visible_data)
if requirement and isinstance(requirement, dict):
data["requirement"] = requirement
# Handling potentially changed optional in-parameters.
Expand Down Expand Up @@ -266,9 +271,3 @@ def cancel(self, order_ref):
return response.json() == {}
else:
raise get_json_error_class(response)

def _encode_user_data(self, user_data):
if isinstance(user_data, six.text_type):
return base64.b64encode(user_data.encode("utf-8")).decode("ascii")
else:
return base64.b64encode(user_data).decode("ascii")

0 comments on commit 52e33f7

Please sign in to comment.