Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Python 3+ support #354

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ FROM node

# Install pip
RUN apt-get update && apt-get install -y \
python-pip
python python-dev && \
curl https://bootstrap.pypa.io/pip/2.7/get-pip.py -o get-pip.py && \
python get-pip.py && \
rm get-pip.py


# Create app dir
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ in the project root
Before you can run the application, make sure that you have the following software installed:

- Node.js (at least version 8, as the `async` `await` syntax is used)
- Python 2.7 with the following `pip` packages installed:
- Python 2.7 or Python 3+ with the following `pip` packages installed:
- `websocket-client` and `git+https://github.com/dpallot/simple-websocket-server.git` for acting as WebSocket server and client.
- `curve25519-donna` and `pycrypto` for the encryption stuff.
- `curve25519-donna` and `pycryptodome` for the encryption stuff.
- `pyqrcode` for QR code generation.
- `protobuf` for reading and writing the binary conversation format.
- Note: On Windows `curve25519-donna` requires [Microsoft Visual C++ 9.0](http://aka.ms/vcpython27) and you need to copy [`stdint.h`](windows) into `C:\Users\YOUR USERNAME\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\include`.
Expand Down
65 changes: 34 additions & 31 deletions backend/utilities.py
Original file line number Diff line number Diff line change
@@ -1,54 +1,57 @@
from __future__ import print_function;
from __future__ import print_function
import sys
import time

import sys;
import time;

def eprint(*args, **kwargs): # from https://stackoverflow.com/a/14981125
print(*args, file=sys.stderr, **kwargs)


def eprint(*args, **kwargs): # from https://stackoverflow.com/a/14981125
print(*args, file=sys.stderr, **kwargs);

def getTimestamp():
return int(time.time());
return int(time.time())


def getTimestampMs():
return int(round(time.time() * 1000));
return int(round(time.time() * 1000))


def mergeDicts(x, y): # from https://stackoverflow.com/a/26853961
if x is None and y is None:
return
z = (y if x is None else x).copy()
if x is not None and y is not None:
z.update(y)
return z

def mergeDicts(x, y): # from https://stackoverflow.com/a/26853961
if x is None and y is None:
return;
z = (y if x is None else x).copy();
if x is not None and y is not None:
z.update(y);
return z;

def getAttr(obj, key, alt=None):
return obj[key] if isinstance(obj, dict) and key in obj else alt;
return obj[key] if isinstance(obj, dict) and key in obj else alt


def filterNone(obj):
if isinstance(obj, dict):
return dict((k, filterNone(v)) for k, v in obj.iteritems() if v is not None);
elif isinstance(obj, list):
return [filterNone(entry) for entry in obj];
else:
return obj;
if isinstance(obj, dict):
return dict((k, filterNone(v)) for k, v in obj.iteritems() if v is not None)
elif isinstance(obj, list):
return [filterNone(entry) for entry in obj]
else:
return obj


def getNumValidKeys(obj):
return len(filter(lambda x: obj[x] is not None, list(obj.keys())));
return len(filter(lambda x: obj[x] is not None, list(obj.keys())))


def encodeUTF8(s):
if not isinstance(s, str):
s = strng.encode("utf-8");
return s;
if not isinstance(s, str):
s = s.encode("utf-8")
return s


def ceil(n): # from https://stackoverflow.com/a/32559239
res = int(n)
return res if res == n or n < 0 else res + 1

def ceil(n): # from https://stackoverflow.com/a/32559239
res = int(n);
return res if res == n or n < 0 else res+1;

def floor(n):
res = int(n);
return res if res == 0 or n >= 0 else res-1;
res = int(n)
return res if res == 0 or n >= 0 else res - 1
Loading