Skip to content
Snippets Groups Projects
Commit 7350bc19 authored by jkerdreu's avatar jkerdreu
Browse files

Fix the Py3/Py2 long() issue.

git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/Python/branches/fork@1683 b32b6428-25c9-4566-ad07-03861ab6144f
parent 3afe7fd2
No related branches found
No related tags found
No related merge requests found
......@@ -31,6 +31,7 @@ import datetime
import pysodium
import base64
import struct
import sys
import logging
logger = logging.getLogger(__name__)
......@@ -359,8 +360,18 @@ def build_nonce(data):
nonce = struct.pack('>QL', data[0], data[1])
return nonce
def build_timestamp():
"""Return array [seconds since epoch, microseconds since last seconds] Time = UTC+0000"""
epoch = datetime.datetime.utcfromtimestamp(0)
timestamp = datetime.datetime.utcnow() - epoch
return [long(timestamp.total_seconds()), int(timestamp.microseconds)]
return _packtimestamp(timestamp.total_seconds(), timestamp.microseconds)
# for better performance, I choose to use this trick to fix the change in size for Py3.
# only test once.
if sys.version_info.major == 2:
_packtimestamp = lambda t1,t2: [long(t1),int(t2)]
else:
_packtimestamp = lambda t1,t2: [int(t1),int(t2)]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment