mirror of
https://github.com/spiral-project/ihatemoney.git
synced 2025-04-29 09:52:36 +02:00
Use propper base64 encoding version for py3
Removes py3-only warning (this alias might be removed in future py3 version): > DeprecationWarning: encodestring() is a deprecated alias, use encodebytes() > ('%s:%s' % (username, password)).encode('utf-8')).decode('utf-8').replace('\n', '') py2-compatible change.
This commit is contained in:
parent
f6236b43ca
commit
95d0c71827
2 changed files with 6 additions and 2 deletions
|
@ -5,7 +5,6 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import unittest # NOQA
|
import unittest # NOQA
|
||||||
|
|
||||||
import base64
|
|
||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
@ -17,6 +16,7 @@ from flask import session
|
||||||
|
|
||||||
import run
|
import run
|
||||||
import models
|
import models
|
||||||
|
import utils
|
||||||
|
|
||||||
|
|
||||||
class TestCase(unittest.TestCase):
|
class TestCase(unittest.TestCase):
|
||||||
|
@ -759,7 +759,7 @@ class APITestCase(TestCase):
|
||||||
|
|
||||||
def get_auth(self, username, password=None):
|
def get_auth(self, username, password=None):
|
||||||
password = password or username
|
password = password or username
|
||||||
base64string = base64.encodestring(
|
base64string = utils.base64_encode(
|
||||||
('%s:%s' % (username, password)).encode('utf-8')).decode('utf-8').replace('\n', '')
|
('%s:%s' % (username, password)).encode('utf-8')).decode('utf-8').replace('\n', '')
|
||||||
return {"Authorization": "Basic %s" % base64string}
|
return {"Authorization": "Basic %s" % base64string}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import base64
|
||||||
import re
|
import re
|
||||||
import inspect
|
import inspect
|
||||||
|
|
||||||
|
@ -120,3 +121,6 @@ def list_of_dicts2csv(dict_to_convert):
|
||||||
if six.PY3:
|
if six.PY3:
|
||||||
csv_file = BytesIO(csv_file.getvalue().encode('utf-8'))
|
csv_file = BytesIO(csv_file.getvalue().encode('utf-8'))
|
||||||
return csv_file
|
return csv_file
|
||||||
|
|
||||||
|
# base64 encoding that works with both py2 and py3 and yield no warning
|
||||||
|
base64_encode = base64.encodestring if six.PY2 else base64.encodebytes
|
||||||
|
|
Loading…
Reference in a new issue