[MQ-683] Fixed compatibility issues not covered by 2to3.

This commit is contained in:
Adamos Kyriakou 2021-03-04 08:43:25 +02:00
parent 81a289b788
commit 114c04b3b8
3 changed files with 24 additions and 20 deletions

View file

@ -9,6 +9,7 @@ from binascii import Error
import collections
import datetime
import hashlib
import base64
from ejson import loads, dumps
@ -72,15 +73,14 @@ def iter_auth_hashes(user, purpose, minutes_valid):
"""
now = timezone.now().replace(microsecond=0, second=0)
for minute in range(minutes_valid + 1):
yield hashlib.sha1(
'%s:%s:%s:%s:%s' % (
now - datetime.timedelta(minutes=minute),
user.password,
purpose,
user.pk,
settings.SECRET_KEY,
),
).hexdigest()
_content = '%s:%s:%s:%s:%s' % (
now - datetime.timedelta(minutes=minute),
user.password,
purpose,
user.pk,
settings.SECRET_KEY,
)
yield hashlib.sha1(_content.encode()).hexdigest()
def get_auth_hash(user, purpose):
@ -97,15 +97,19 @@ def calc_expiry_time(minutes_valid):
def get_user_token(user, purpose, minutes_valid):
"""Return login token info for given user."""
token = ''.join(
dumps([
user.get_username(),
get_auth_hash(user, purpose),
]).encode('base64').split('\n')
token_json = dumps([
user.get_username(),
get_auth_hash(user, purpose),
])
token_json_enc = token_json.encode()
token_json_enc_b64_multiline = base64.b64encode(token_json_enc)
token_json_enc_b64_singleline = "".join(
token_json_enc_b64_multiline.decode().split("\n")
)
return {
'id': get_meteor_id(user),
'token': token,
'token': token_json_enc_b64_singleline,
'tokenExpires': calc_expiry_time(minutes_valid),
}
@ -314,7 +318,7 @@ class Auth(APIMixin):
def validated_user(cls, token, purpose, minutes_valid):
"""Resolve and validate auth token, returns user object."""
try:
username, auth_hash = loads(token.decode('base64'))
username, auth_hash = loads(base64.b64decode(token))
except (ValueError, Error):
cls.auth_failed(token=token)
try:

View file

@ -1,6 +1,6 @@
"""Django DDP PostgreSQL Greenlet."""
from __future__ import absolute_import
import ejson
import gevent
@ -39,7 +39,7 @@ class PostgresGreenlet(gevent.Greenlet):
# http://www.postgresql.org/docs/current/static/libpq-connect.html
# section 31.1.2 (Parameter Key Words) for details on available params.
conn_params.update(
async=True,
async_=True,
application_name='{} pid={} django-ddp'.format(
socket.gethostname(), # hostname
os.getpid(), # PID

View file

@ -153,8 +153,8 @@ class DDPWebSocketApplication(geventwebsocket.WebSocketApplication):
# `_tx_buffer` collects outgoing messages which must be sent in order
self._tx_buffer = {}
# track the head of the queue (buffer) and the next msg to be sent
self._tx_buffer_id_gen = itertools.cycle(irange(sys.maxint))
self._tx_next_id_gen = itertools.cycle(irange(sys.maxint))
self._tx_buffer_id_gen = itertools.cycle(irange(sys.maxsize))
self._tx_next_id_gen = itertools.cycle(irange(sys.maxsize))
# start by waiting for the very first message
self._tx_next_id = next(self._tx_next_id_gen)