Move to Python 3.7 and update dependencies (#551)

* forms: replace re._pattern_type with re.Pattern

Python 3.7 removed re._pattern_type and replaced it with
re.Pattern.

* readme: update for Python 3.7

* Update requirements

Also remove some unused ones which were neither a direct dependency
nor a dependency of our dependencies.

* account: force ASCII usernames on login form

Our database doesn't like it when we check for unicode data in
a column that stores ASCII data, so let's stop it before it
gets that far.

* Move travis CI to Python 3.7

* travis: use xenial dist

* fix newer linter warnings

Apparently bare excepts are literally Hitler, and we have some
new import sorting rules. Hooray!

* requirements: remove six

This is a dependency for sqlalchemy-utils, but we ourselves don't
depend on it directly because we've never been on Python 2 ever.

* Update requirements.txt
This commit is contained in:
Nicolas F 2019-08-11 03:39:53 +02:00 committed by Arylide
parent 16814d6eb7
commit d8e796f3e0
7 changed files with 60 additions and 60 deletions

View File

@ -1,8 +1,8 @@
language: python language: python
python: "3.6" python: "3.7"
dist: trusty dist: xenial
sudo: required sudo: required
matrix: matrix:

View File

@ -1,7 +1,7 @@
# NyaaV2 [![Build Status](https://travis-ci.org/nyaadevs/nyaa.svg?branch=master)](https://travis-ci.org/nyaadevs/nyaa) # NyaaV2 [![Build Status](https://travis-ci.org/nyaadevs/nyaa.svg?branch=master)](https://travis-ci.org/nyaadevs/nyaa)
## Setting up for development ## Setting up for development
This project uses Python 3.6. There are features used that do not exist in 3.5, so make sure to use Python 3.6. This project uses Python 3.7. There are features used that do not exist in 3.6, so make sure to use Python 3.7.
This guide also assumes you 1) are using Linux and 2) are somewhat capable with the commandline. This guide also assumes you 1) are using Linux and 2) are somewhat capable with the commandline.
It's not impossible to run Nyaa on Windows, but this guide doesn't focus on that. It's not impossible to run Nyaa on Windows, but this guide doesn't focus on that.
@ -16,13 +16,13 @@ The `tests` folder contains tests for the the `nyaa` module and the webserver. T
- Run `./dev.py test` while in the repository directory. - Run `./dev.py test` while in the repository directory.
### Setting up Pyenv ### Setting up Pyenv
pyenv eases the use of different Python versions, and as not all Linux distros offer 3.6 packages, it's right up our alley. pyenv eases the use of different Python versions, and as not all Linux distros offer 3.7 packages, it's right up our alley.
- Install dependencies https://github.com/pyenv/pyenv/wiki/Common-build-problems - Install dependencies https://github.com/pyenv/pyenv/wiki/Common-build-problems
- Install `pyenv` https://github.com/pyenv/pyenv/blob/master/README.md#installation - Install `pyenv` https://github.com/pyenv/pyenv/blob/master/README.md#installation
- Install `pyenv-virtualenv` https://github.com/pyenv/pyenv-virtualenv/blob/master/README.md - Install `pyenv-virtualenv` https://github.com/pyenv/pyenv-virtualenv/blob/master/README.md
- Install Python 3.6.1 with `pyenv` and create a virtualenv for the project: - Install Python 3.7.2 with `pyenv` and create a virtualenv for the project:
- `pyenv install 3.6.1` - `pyenv install 3.7.2`
- `pyenv virtualenv 3.6.1 nyaa` - `pyenv virtualenv 3.7.2 nyaa`
- `pyenv activate nyaa` - `pyenv activate nyaa`
- Install dependencies with `pip install -r requirements.txt` - Install dependencies with `pip install -r requirements.txt`
- Copy `config.example.py` into `config.py` - Copy `config.example.py` into `config.py`

View File

@ -67,7 +67,7 @@ def _bencode_decode(file_object, decode_keys_as_utf8=True):
elif c == _B_END: elif c == _B_END:
try: try:
return int(int_bytes.decode('utf8')) return int(int_bytes.decode('utf8'))
except Exception as e: except Exception:
raise create_ex('Unable to parse int') raise create_ex('Unable to parse int')
# not a digit OR '-' in the middle of the int # not a digit OR '-' in the middle of the int
@ -109,7 +109,7 @@ def _bencode_decode(file_object, decode_keys_as_utf8=True):
raise create_ex('Unexpected input while reading string length: ' + repr(c)) raise create_ex('Unexpected input while reading string length: ' + repr(c))
try: try:
str_len = int(str_len_bytes.decode()) str_len = int(str_len_bytes.decode())
except Exception as e: except Exception:
raise create_ex('Unable to parse bytestring length') raise create_ex('Unable to parse bytestring length')
bytestring = file_object.read(str_len) bytestring = file_object.read(str_len)

View File

@ -11,8 +11,9 @@ from wtforms import (BooleanField, HiddenField, PasswordField, SelectField, Stri
SubmitField, TextAreaField) SubmitField, TextAreaField)
from wtforms.validators import (DataRequired, Email, EqualTo, Length, Optional, Regexp, from wtforms.validators import (DataRequired, Email, EqualTo, Length, Optional, Regexp,
StopValidation, ValidationError) StopValidation, ValidationError)
from wtforms.widgets import HTMLString # For DisabledSelectField
from wtforms.widgets import Select as SelectWidget # For DisabledSelectField from wtforms.widgets import Select as SelectWidget # For DisabledSelectField
from wtforms.widgets import HTMLString, html_params # For DisabledSelectField from wtforms.widgets import html_params
import dns.exception import dns.exception
import dns.resolver import dns.resolver
@ -78,7 +79,7 @@ def register_email_blacklist_validator(form, field):
validation_exception = StopValidation('Blacklisted email provider') validation_exception = StopValidation('Blacklisted email provider')
for item in email_blacklist: for item in email_blacklist:
if isinstance(item, re._pattern_type): if isinstance(item, re.Pattern):
if item.search(email): if item.search(email):
raise validation_exception raise validation_exception
elif isinstance(item, str): elif isinstance(item, str):

View File

@ -29,7 +29,7 @@ def _maintenance_mode_hook():
flask.flash(flask.Markup(message), 'danger') flask.flash(flask.Markup(message), 'danger')
try: try:
target_url = flask.url_for(endpoint) target_url = flask.url_for(endpoint)
except: except Exception:
# Non-GET-able endpoint, try referrer or default to home page # Non-GET-able endpoint, try referrer or default to home page
target_url = flask.request.referrer or flask.url_for('main.home') target_url = flask.request.referrer or flask.url_for('main.home')
return flask.redirect(target_url) return flask.redirect(target_url)

View File

@ -26,6 +26,9 @@ def login():
return flask.redirect(flask.url_for('account.login')) return flask.redirect(flask.url_for('account.login'))
username = form.username.data.strip() username = form.username.data.strip()
if not username.isascii():
flask.flash('Invalid characters in username.', 'danger')
return flask.redirect(flask.url_for('account.login'))
password = form.password.data password = form.password.data
user = models.User.by_username(username) user = models.User.by_username(username)
@ -151,7 +154,7 @@ def password_reset(payload=None):
s = get_serializer() s = get_serializer()
try: try:
request_timestamp, pw_hash, user_id = s.loads(payload) request_timestamp, pw_hash, user_id = s.loads(payload)
except: except Exception:
return flask.abort(404) return flask.abort(404)
user = models.User.by_id(user_id) user = models.User.by_id(user_id)

View File

@ -1,57 +1,53 @@
alembic==0.9.2 alembic==1.0.11
appdirs==1.4.3 appdirs==1.4.3
argon2-cffi==16.3.0 argon2-cffi==19.1.0
autopep8==1.3.1 autopep8==1.4.4
blinker==1.4 blinker==1.4
cffi==1.10.0 cffi==1.12.3
click==6.7 click==7.0
dominate==2.3.1 dnspython==1.16.0
dnspython==1.15.0 elasticsearch==7.0.2
elasticsearch==5.3.0 elasticsearch-dsl==7.0.0
elasticsearch-dsl==5.2.0 flake8==3.7.8
flake8==3.3.0 flake8-isort==2.7.0
flake8-isort==2.2.1 Flask==1.1.1
Flask==0.12.2
Flask-Assets==0.12 Flask-Assets==0.12
Flask-DebugToolbar==0.10.1 Flask-DebugToolbar==0.10.1
Flask-Migrate==2.0.3 Flask-Migrate==2.5.2
flask-paginate==0.4.5 flask-paginate==0.5.3
Flask-Script==2.0.5 Flask-Script==2.0.6
Flask-SQLAlchemy==2.2 Flask-SQLAlchemy==2.4.0
Flask-WTF==0.14.2 Flask-WTF==0.14.2
gevent==1.3.7 gevent==1.4.0
greenlet==0.4.15 greenlet==0.4.15
isort==4.2.15 isort==4.3.21
itsdangerous==0.24 itsdangerous==1.1.0
Jinja2==2.9.6 Jinja2==2.10.1
libsass==0.12.3 Mako==1.1.0
Mako==1.0.6 MarkupSafe==1.1.1
MarkupSafe==1.0 mysql-replication==0.19
mysql-replication==0.13 mysqlclient==1.4.3
mysqlclient==1.3.10
orderedset==2.0.1 orderedset==2.0.1
packaging==16.8 packaging==19.1
passlib==1.7.1 passlib==1.7.1
progressbar33==2.4 progressbar33==2.4
py==1.4.34 py==1.8.0
pycodestyle==2.3.1 pycodestyle==2.5.0
pycparser==2.17 pycparser==2.19
PyMySQL==0.7.11 PyMySQL==0.9.3
pyparsing==2.2.0 pyparsing==2.4.2
pytest==3.1.1 pytest==5.0.1
python-dateutil==2.6.0 python-dateutil==2.8.0
python-editor==1.0.3 python-editor==1.0.4
python-utils==2.1.0 python-utils==2.3.0
requests==2.18.4 requests==2.22.0
six==1.10.0 SQLAlchemy==1.3.6
SQLAlchemy==1.1.10 SQLAlchemy-FullText-Search==0.2.5
SQLAlchemy-FullText-Search==0.2.3 SQLAlchemy-Utils==0.34.1
SQLAlchemy-Utils==0.32.14 statsd==3.3.0
statsd==3.2.1 urllib3==1.25.3
urllib3==1.21.1 uWSGI==2.0.18
uWSGI==2.0.15
visitor==0.1.3
webassets==0.12.1 webassets==0.12.1
Werkzeug==0.12.2 Werkzeug==0.15.5
WTForms==2.1 WTForms==2.2.1
Flask-Caching==1.4.0 Flask-Caching==1.7.2