From 7f79c6a465d9b4afe23de78b4ae2c240860e1817 Mon Sep 17 00:00:00 2001 From: Changaco Date: Fri, 25 Jan 2019 17:36:33 +0100 Subject: [PATCH 1/2] jump to python 3.6 --- Makefile | 4 ++-- README.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 2eb1426e05..c52473da7b 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -python := "$(shell { command -v python2.7 || command -v python; } 2>/dev/null)" +python := "$(shell { command -v python3.6 || command -v python; } 2>/dev/null)" install_where := $(shell $(python) -c "import sys; print('' if hasattr(sys, 'real_prefix') else '--user')") # Set the relative path to installed binaries under the project virtualenv. @@ -27,7 +27,7 @@ env: requirements*.txt rehash-requirements: for f in requirements*.txt; do \ - sed -r -e '/^ +--hash/d' -e 's/\\$$//' $$f | xargs ./env/bin/hashin -r $$f -p 2.7 -p 3.6; \ + sed -r -e '/^ +--hash/d' -e 's/\\$$//' $$f | xargs ./env/bin/hashin -r $$f -p 3.4 -p 3.6; \ done clean: diff --git a/README.md b/README.md index 0ad8c5eef7..8c495b3aed 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ The python code inside simplates is only for request-specific logic, common back Firstly, make sure you have the following dependencies installed: -- python ≥ 2.7.12 (the code is compatible with python 3, but production still runs on python 2 for now) +- python ≥ 3.6 - including the C headers of python and libffi, which are packaged separately in many Linux distributions - postgresql 9.6 (see [the official download & install docs](https://www.postgresql.org/download/)) - make @@ -178,7 +178,7 @@ All new dependencies need to be audited to check that they don't contain malicio We use [pip's Hash-Checking Mode](https://pip.pypa.io/en/stable/reference/pip_install/#hash-checking-mode) to protect ourselves from dependency tampering. Thus when adding or upgrading a dependency the new hashes need to computed and put in the requirements file. For that you can use [hashin](https://github.com/peterbe/hashin): pip install hashin - hashin package==x.y -r requirements_base.txt -p 2.7 -p 3.4 -p 3.6 + hashin package==x.y -r requirements_base.txt -p 3.4 -p 3.6 # note: we have several requirements files, use the right one If for some reason you need to rehash all requirements, run `make rehash-requirements`. From a51b9c06cec07858a6f07215648c3be8b447d893 Mon Sep 17 00:00:00 2001 From: Changaco Date: Fri, 25 Jan 2019 18:14:03 +0100 Subject: [PATCH 2/2] adapt the `Request.source` property to python 3 --- liberapay/main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/liberapay/main.py b/liberapay/main.py index 7236640d04..cc811715a9 100644 --- a/liberapay/main.py +++ b/liberapay/main.py @@ -235,7 +235,8 @@ def _Querystring_derive(self, **kw): raise Warning('pando.http.request.Request.source already exists') def _source(self): def f(): - addr = ip_address(self.environ[b'REMOTE_ADDR'].decode('ascii')) + addr = self.environ.get('REMOTE_ADDR') or self.environ[b'REMOTE_ADDR'] + addr = ip_address(addr.decode('ascii') if type(addr) is bytes else addr) trusted_proxies = getattr(self.website, 'trusted_proxies', None) forwarded_for = self.headers.get(b'X-Forwarded-For') self.__dict__['bypasses_proxy'] = bool(trusted_proxies)