From ab95fa192df7da77606faf3fe766e7a310261981 Mon Sep 17 00:00:00 2001 From: Changaco Date: Mon, 29 Aug 2016 00:03:41 +0200 Subject: [PATCH 1/4] add pando 0.43 to dependencies --- requirements.txt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/requirements.txt b/requirements.txt index 3c8f7e2568..456957e62b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,9 +2,10 @@ python-mimeparse==0.1.4 first==2.0.1 dependency_injection==1.1.0 -algorithm==1.0.0 -filesystem_tree==1.0.0 -aspen==0.42 +algorithm==1.2.0 +filesystem_tree==1.1.2 +aspen==1.0rc1 +pando==0.43 gunicorn==19.6.0 From 4309bad43c6b962519d37e21d9822a5848f66855 Mon Sep 17 00:00:00 2001 From: Changaco Date: Tue, 21 Jun 2016 18:26:41 +0200 Subject: [PATCH 2/4] transition from aspen 0.42 to pando 0.43 --- error.spt | 4 +- liberapay/__init__.py | 14 +---- liberapay/billing/exchanges.py | 4 +- liberapay/billing/payday.py | 17 ++++--- liberapay/constants.py | 2 +- liberapay/elsewhere/_base.py | 9 ++-- liberapay/elsewhere/bitbucket.py | 2 +- liberapay/elsewhere/bountysource.py | 2 +- liberapay/exceptions.py | 2 +- liberapay/main.py | 51 ++++++++++--------- liberapay/models/account_elsewhere.py | 4 +- liberapay/models/participant.py | 2 +- liberapay/renderers/csv_dump.py | 2 +- liberapay/security/authentication.py | 2 +- liberapay/security/csrf.py | 2 +- liberapay/testing/__init__.py | 7 +-- liberapay/utils/__init__.py | 4 +- liberapay/utils/history.py | 2 +- liberapay/utils/http_caching.py | 7 +-- liberapay/utils/i18n.py | 2 +- liberapay/website.py | 6 +-- liberapay/wireup.py | 12 +++-- tests/py/test_charts_json.py | 3 +- tests/py/test_elsewhere.py | 4 +- tests/py/test_hooks.py | 6 +-- tests/py/test_pages.py | 2 +- tests/py/test_payio.py | 2 +- tests/py/test_sign_in.py | 2 +- tests/py/test_utils.py | 13 ++--- www/%username/avatar.spt | 2 +- www/%username/charts.json.spt | 2 +- www/%username/communities.json.spt | 2 +- www/%username/edit.spt | 2 +- www/%username/elsewhere/delete.spt | 2 + www/%username/elsewhere/refresh.spt | 2 +- www/%username/emails/modify.json.spt | 2 +- www/%username/emails/verify.html.spt | 4 +- www/%username/giving/index.html.spt | 4 +- www/%username/goal.spt | 2 +- www/%username/identity.spt | 2 +- www/%username/income/index.html.spt | 2 +- www/%username/income/take.spt | 2 +- www/%username/members.json.spt | 2 +- www/%username/membership/%action.spt | 2 +- www/%username/receipts/%exchange_id.spt | 2 +- www/%username/routes/bank-account.spt | 2 +- www/%username/routes/credit-card.json.spt | 2 +- www/%username/routes/delete.json.spt | 2 +- www/%username/settings/edit.spt | 4 +- www/%username/tips.json.spt | 2 +- www/%username/wallet/export.spt | 2 +- www/%username/wallet/index.html.spt | 2 +- .../wallet/payin/bankwire/%back_to.spt | 2 +- www/%username/wallet/payin/card/%back_to.spt | 2 +- www/%username/wallet/payout/%back_to.spt | 2 +- www/%username/widgets/%type.spt | 2 +- www/about/teams.spt | 2 +- www/admin/payday/%id.spt | 2 +- www/callbacks/mangopay.spt | 2 +- www/for/%name/%action.spt | 2 +- www/for/%name/edit.spt | 2 +- www/for/%name/index.html.spt | 2 +- www/for/%name/index.json.spt | 2 +- www/for/new.spt | 2 +- .../%platform/%user_name/%endpoint.json.spt | 2 +- www/on/%platform/%user_name/failure.html.spt | 2 +- www/on/%platform/%user_name/index.html.spt | 2 +- www/on/%platform/associate.spt | 2 +- www/on/%platform/index.spt | 2 +- www/on/%platform/redirect.spt | 2 +- www/on/confirm.html.spt | 2 +- www/on/index.spt | 2 +- www/on/take-over.html.spt | 2 +- www/sign-out.spt | 2 +- 74 files changed, 145 insertions(+), 142 deletions(-) diff --git a/error.spt b/error.spt index df4b9b9fb9..c118cdce32 100644 --- a/error.spt +++ b/error.spt @@ -1,6 +1,6 @@ from __future__ import absolute_import, division, print_function, unicode_literals -from aspen.http import status_strings +from pando.http import status_strings from liberapay.exceptions import LazyResponse from liberapay.utils.i18n import HTTP_ERRORS @@ -48,4 +48,4 @@ if code == 500 and not err: , "error_message_long": err } [----------------------------------------] text/plain -{{err}} +{{err or msg}} diff --git a/liberapay/__init__.py b/liberapay/__init__.py index e701cbf5da..413d505bd1 100644 --- a/liberapay/__init__.py +++ b/liberapay/__init__.py @@ -1,10 +1,8 @@ from __future__ import print_function, unicode_literals -from mimetypes import guess_type - from six.moves.urllib.parse import urlsplit, urlunsplit -from aspen.http.request import Line +from pando.http.request import Line from . import constants @@ -62,13 +60,3 @@ def canonize(request, website): def insert_constants(): return {'constants': constants} - - -def fill_accept_header(state, request, accept_header): - """Work around aspen's content negotiation weirdness - - This sets `accept_header` to `application/json` when the requested URL ends - in `.json` and the `Accept` header is missing. - """ - if not accept_header: - state['accept_header'] = guess_type(request.path.raw, strict=False)[0] diff --git a/liberapay/billing/exchanges.py b/liberapay/billing/exchanges.py index 06acc5ee04..fd2c0c26d6 100644 --- a/liberapay/billing/exchanges.py +++ b/liberapay/billing/exchanges.py @@ -4,14 +4,14 @@ from decimal import Decimal, ROUND_UP -from aspen import Response -from aspen.utils import typecheck from mangopaysdk.entities.payin import PayIn from mangopaysdk.entities.payout import PayOut from mangopaysdk.entities.transfer import Transfer from mangopaysdk.entities.wallet import Wallet from mangopaysdk.types.exceptions.responseexception import ResponseException from mangopaysdk.types.money import Money +from pando import Response +from pando.utils import typecheck from liberapay.billing import ( mangoapi, diff --git a/liberapay/billing/payday.py b/liberapay/billing/payday.py index b7ba64ba2d..efa72efe86 100644 --- a/liberapay/billing/payday.py +++ b/liberapay/billing/payday.py @@ -5,7 +5,8 @@ import os.path import pickle -import aspen.utils +from babel.dates import format_timedelta +import pando.utils from psycopg2 import IntegrityError from liberapay import constants @@ -58,7 +59,7 @@ def start(cls): """, back_as=dict) log("Picking up payday #%s." % d['id']) - d['ts_start'] = d['ts_start'].replace(tzinfo=aspen.utils.utc) + d['ts_start'] = d['ts_start'].replace(tzinfo=pando.utils.utc) log("Payday started at %s." % d['ts_start']) @@ -75,7 +76,7 @@ def run(self, log_dir='.', keep_log=False): """ self.db.self_check() - _start = aspen.utils.utcnow() + _start = pando.utils.utcnow() log("Greetings, program! It's PAYDAY!!!!") self.shuffle(log_dir) @@ -89,10 +90,10 @@ def run(self, log_dir='.', keep_log=False): if not keep_log: os.unlink(self.transfers_filename) - _end = aspen.utils.utcnow() + _end = pando.utils.utcnow() _delta = _end - _start - fmt_past = "Script ran for %%(age)s (%s)." % _delta - log(aspen.utils.to_age(_start, fmt_past=fmt_past)) + msg = "Script ran for %s ({0})." + log(msg.format(_delta) % format_timedelta(_delta, locale='en')) if keep_log: output_log_path = log_dir+'/payday-%i.txt' % self.id @@ -465,7 +466,7 @@ def update_stats(self): log("Updated payday stats.") def update_cached_amounts(self): - now = aspen.utils.utcnow() + now = pando.utils.utcnow() with self.db.get_cursor() as cursor: self.prepare(cursor, now) self.transfer_virtually(cursor) @@ -558,7 +559,7 @@ def end(self): SET ts_end=now() WHERE ts_end='1970-01-01T00:00:00+00'::timestamptz RETURNING ts_end AT TIME ZONE 'UTC' - """, default=NoPayday).replace(tzinfo=aspen.utils.utc) + """, default=NoPayday).replace(tzinfo=pando.utils.utc) def notify_participants(self): previous_ts_end = self.db.one(""" diff --git a/liberapay/constants.py b/liberapay/constants.py index c6c1849702..e2eed9dc1f 100644 --- a/liberapay/constants.py +++ b/liberapay/constants.py @@ -1,13 +1,13 @@ # coding: utf8 from __future__ import print_function, unicode_literals -from aspen.utils import utc from collections import namedtuple, OrderedDict from datetime import date, datetime, timedelta from decimal import Decimal import re from jinja2 import StrictUndefined +from pando.utils import utc class CustomUndefined(StrictUndefined): diff --git a/liberapay/elsewhere/_base.py b/liberapay/elsewhere/_base.py index 3a9995dcb4..69d3c9b5ed 100644 --- a/liberapay/elsewhere/_base.py +++ b/liberapay/elsewhere/_base.py @@ -10,8 +10,9 @@ from urllib import quote import xml.etree.ElementTree as ET -from aspen import Response -from aspen.utils import to_age, utc +from babel.dates import format_timedelta +from pando import Response +from pando.utils import utc from oauthlib.oauth2 import TokenExpiredError from requests_oauthlib import OAuth1Session, OAuth2Session @@ -161,10 +162,12 @@ def log_ratelimit_headers(self, limit, remaining, reset): return percent_remaining = remaining/limit if percent_remaining < 0.5: + reset_delta = reset - datetime.now().replace(tz=utc) + reset_delta = format_timedelta(reset_delta, locale='en') log_msg = ( '{0} API: {1:.1%} of ratelimit has been consumed, ' '{2} requests remaining, resets {3}.' - ).format(self.name, 1 - percent_remaining, remaining, to_age(reset)) + ).format(self.name, 1 - percent_remaining, remaining, reset_delta) log_lvl = logging.WARNING if percent_remaining < 0.2: log_lvl = logging.ERROR diff --git a/liberapay/elsewhere/bitbucket.py b/liberapay/elsewhere/bitbucket.py index e871a0aa21..7b9dc00324 100644 --- a/liberapay/elsewhere/bitbucket.py +++ b/liberapay/elsewhere/bitbucket.py @@ -1,6 +1,6 @@ from __future__ import absolute_import, division, print_function, unicode_literals -from aspen import Response +from pando import Response from liberapay.elsewhere._base import PlatformOAuth1 from liberapay.elsewhere._extractors import any_key, key, not_available from liberapay.elsewhere._paginators import keys_paginator diff --git a/liberapay/elsewhere/bountysource.py b/liberapay/elsewhere/bountysource.py index c550f4ec57..16dfd6c16b 100644 --- a/liberapay/elsewhere/bountysource.py +++ b/liberapay/elsewhere/bountysource.py @@ -12,7 +12,7 @@ import requests -from aspen import Response +from pando import Response from liberapay.elsewhere._base import Platform from liberapay.elsewhere._extractors import key, not_available diff --git a/liberapay/exceptions.py b/liberapay/exceptions.py index 484d7471e8..78cd7bf44f 100644 --- a/liberapay/exceptions.py +++ b/liberapay/exceptions.py @@ -1,7 +1,7 @@ from __future__ import print_function, unicode_literals -from aspen import Response from dependency_injection import resolve_dependencies +from pando import Response from .constants import MAX_TIP, MIN_TIP, PASSWORD_MIN_SIZE, PASSWORD_MAX_SIZE diff --git a/liberapay/main.py b/liberapay/main.py index 9a498d613b..6f6294ea68 100644 --- a/liberapay/main.py +++ b/liberapay/main.py @@ -5,8 +5,10 @@ import aspen import aspen.http.mapping +import pando +from pando.algorithms.website import fill_response_with_output -from liberapay import canonize, fill_accept_header, insert_constants, utils, wireup +from liberapay import canonize, insert_constants, utils, wireup from liberapay.cron import Cron from liberapay.models.community import Community from liberapay.models.participant import Participant @@ -74,7 +76,7 @@ def _assert(x): # ================= def return_500_for_exception(website, exception): - response = aspen.Response(500) + response = pando.Response(500) if website.show_tracebacks: import traceback response.body = traceback.format_exc() @@ -90,6 +92,7 @@ def return_500_for_exception(website, exception): algorithm = website.algorithm algorithm.functions = [ algorithm['parse_environ_into_request'], + algorithm['insert_variables_for_aspen'], algorithm['parse_body_into_request'], algorithm['raise_200_for_OPTIONS'], @@ -101,16 +104,17 @@ def return_500_for_exception(website, exception): csrf.reject_forgeries, authentication.authenticate_user_if_possible, - algorithm['dispatch_request_to_filesystem'], + algorithm['dispatch_path_to_filesystem'], + algorithm['handle_dispatch_exception'], http_caching.get_etag_for_file if env.cache_static else noop, http_caching.try_to_serve_304 if env.cache_static else noop, algorithm['apply_typecasters_to_path'], - algorithm['get_resource_for_request'], - algorithm['extract_accept_from_request'], - fill_accept_header, - algorithm['get_response_for_resource'], + algorithm['load_resource_from_filesystem'], + algorithm['create_response_object'], + algorithm['render_resource'], + algorithm['fill_response_with_output'], tell_sentry, algorithm['get_response_for_exception'], @@ -129,8 +133,8 @@ def return_500_for_exception(website, exception): ] -# Monkey patch aspen -# ================== +# Monkey patch aspen and pando +# ============================ pop = aspen.http.mapping.Mapping.pop def _pop(self, name, default=aspen.http.mapping.NO_DEFAULT): @@ -140,31 +144,32 @@ def _pop(self, name, default=aspen.http.mapping.NO_DEFAULT): raise aspen.Response(400, "Missing key: %s" % repr(name)) aspen.http.mapping.Mapping.pop = _pop -if hasattr(aspen.Response, 'redirect'): - raise Warning('aspen.Response.redirect() already exists') +if hasattr(pando.Response, 'redirect'): + raise Warning('pando.Response.redirect() already exists') def _redirect(response, url, code=302): response.code = code response.headers['Location'] = url raise response -aspen.Response.redirect = _redirect +pando.Response.redirect = _redirect -if hasattr(aspen.Response, 'render'): - raise Warning('aspen.Response.render() already exists') +if hasattr(pando.Response, 'render'): + raise Warning('pando.Response.render() already exists') def _render(response, path, state, **extra): state.update(extra) - assert response is state['response'] - aspen.resources.get(state['website'], path).respond(state) + request_processor = state['request_processor'] + output = aspen.resources.get(request_processor, path).render(state) + fill_response_with_output(output, response, request_processor) raise response -aspen.Response.render = _render +pando.Response.render = _render -if hasattr(aspen.Response, 'set_cookie'): - raise Warning('aspen.Response.set_cookie() already exists') +if hasattr(pando.Response, 'set_cookie'): + raise Warning('pando.Response.set_cookie() already exists') def _set_cookie(response, *args, **kw): set_cookie(response.headers.cookie, *args, **kw) -aspen.Response.set_cookie = _set_cookie +pando.Response.set_cookie = _set_cookie -if hasattr(aspen.Response, 'erase_cookie'): - raise Warning('aspen.Response.erase_cookie() already exists') +if hasattr(pando.Response, 'erase_cookie'): + raise Warning('pando.Response.erase_cookie() already exists') def _erase_cookie(response, *args, **kw): erase_cookie(response.headers.cookie, *args, **kw) -aspen.Response.erase_cookie = _erase_cookie +pando.Response.erase_cookie = _erase_cookie diff --git a/liberapay/models/account_elsewhere.py b/liberapay/models/account_elsewhere.py index 0ea6d02cb0..a1fb5da588 100644 --- a/liberapay/models/account_elsewhere.py +++ b/liberapay/models/account_elsewhere.py @@ -7,8 +7,8 @@ from six.moves.urllib.parse import urlsplit, urlunsplit -from aspen import Response -from aspen.utils import utcnow +from pando import Response +from pando.utils import utcnow from postgres.orm import Model from psycopg2 import IntegrityError import xmltodict diff --git a/liberapay/models/participant.py b/liberapay/models/participant.py index 80913c94a6..577daabbd8 100644 --- a/liberapay/models/participant.py +++ b/liberapay/models/participant.py @@ -11,10 +11,10 @@ from six.moves.urllib.parse import urlencode -from aspen.utils import utcnow import aspen_jinja2_renderer from html2text import html2text from markupsafe import escape as htmlescape +from pando.utils import utcnow from postgres.orm import Model from psycopg2 import IntegrityError from psycopg2.extras import Json diff --git a/liberapay/renderers/csv_dump.py b/liberapay/renderers/csv_dump.py index 2e088fb15f..7b0f29ce65 100644 --- a/liberapay/renderers/csv_dump.py +++ b/liberapay/renderers/csv_dump.py @@ -3,7 +3,7 @@ import csv from io import BytesIO -from aspen import renderers +from aspen.simplates import renderers class Renderer(renderers.Renderer): diff --git a/liberapay/security/authentication.py b/liberapay/security/authentication.py index b0b4f47b7b..44a723526c 100644 --- a/liberapay/security/authentication.py +++ b/liberapay/security/authentication.py @@ -4,7 +4,7 @@ from six.moves.urllib.parse import urlencode -from aspen import Response +from pando import Response from liberapay.constants import SESSION, SESSION_TIMEOUT from liberapay.exceptions import AuthRequired diff --git a/liberapay/security/csrf.py b/liberapay/security/csrf.py index 667f1e90cc..7aa3af6396 100644 --- a/liberapay/security/csrf.py +++ b/liberapay/security/csrf.py @@ -12,7 +12,7 @@ from datetime import timedelta import re -from aspen import Response +from pando import Response from .crypto import constant_time_compare, get_random_string diff --git a/liberapay/testing/__init__.py b/liberapay/testing/__init__.py index 8be1dddd4a..2f882b8921 100644 --- a/liberapay/testing/__init__.py +++ b/liberapay/testing/__init__.py @@ -6,9 +6,10 @@ import unittest from os.path import dirname, join, realpath -from aspen import resources, Response -from aspen.utils import utcnow -from aspen.testing.client import Client +from aspen import resources +from pando import Response +from pando.utils import utcnow +from pando.testing.client import Client from psycopg2 import IntegrityError, InternalError from liberapay.billing import exchanges diff --git a/liberapay/utils/__init__.py b/liberapay/utils/__init__.py index 81e0f9c79b..c477bc2da6 100644 --- a/liberapay/utils/__init__.py +++ b/liberapay/utils/__init__.py @@ -13,8 +13,8 @@ from six.moves.urllib.parse import quote as urlquote -from aspen import Response, json -from aspen.utils import to_rfc822, utcnow +from pando import Response, json +from pando.utils import to_rfc822, utcnow from markupsafe import Markup from postgres.cursors import SimpleCursorBase diff --git a/liberapay/utils/history.py b/liberapay/utils/history.py index ee3ecc8ad4..1e097f03aa 100644 --- a/liberapay/utils/history.py +++ b/liberapay/utils/history.py @@ -1,7 +1,7 @@ from datetime import datetime from decimal import Decimal -from aspen import Response +from pando import Response from psycopg2 import IntegrityError diff --git a/liberapay/utils/http_caching.py b/liberapay/utils/http_caching.py index 67d91888da..0420c24fd6 100644 --- a/liberapay/utils/http_caching.py +++ b/liberapay/utils/http_caching.py @@ -8,8 +8,9 @@ from os import stat from tempfile import mkstemp -from aspen import resources, Response -from aspen.dispatcher import DispatchResult, DispatchStatus +from aspen import resources +from aspen.request_processor.dispatcher import DispatchResult, DispatchStatus +from pando import Response from liberapay.utils import b64encode_s, find_files @@ -26,7 +27,7 @@ def compile_assets(website): dispatch_result = DispatchResult(DispatchStatus.okay, spt, {}, "Found.", {}, True) state = dict(dispatch_result=dispatch_result, response=Response()) state['state'] = state - content = resources.get(website, spt).respond(state).body + content = resources.get(website.request_processor, spt).render(state).body if not isinstance(content, bytes): content = content.encode('utf8') tmpfd, tmpfpath = mkstemp(dir='.') diff --git a/liberapay/utils/i18n.py b/liberapay/utils/i18n.py index 8823e2d8f9..3a7e5d7842 100644 --- a/liberapay/utils/i18n.py +++ b/liberapay/utils/i18n.py @@ -9,7 +9,6 @@ from unicodedata import combining, normalize from aspen.simplates.pagination import parse_specline, split_and_escape -from aspen.utils import utcnow from babel.core import LOCALE_ALIASES, Locale from babel.dates import format_datetime, format_timedelta from babel.messages.extract import extract_python @@ -19,6 +18,7 @@ get_decimal_symbol, NumberFormatError, parse_decimal ) import jinja2.ext +from pando.utils import utcnow from liberapay.exceptions import InvalidNumber from liberapay.website import website diff --git a/liberapay/website.py b/liberapay/website.py index bc5761417b..75d612617a 100644 --- a/liberapay/website.py +++ b/liberapay/website.py @@ -1,8 +1,4 @@ -import aspen -from aspen.website import Website +from pando.website import Website - -aspen.logging.LOGGING_THRESHOLD = 2 # Hide Aspen's startup messages website = Website() -aspen.logging.LOGGING_THRESHOLD = 0 diff --git a/liberapay/wireup.py b/liberapay/wireup.py index d603b2f7a5..f9bab0b849 100644 --- a/liberapay/wireup.py +++ b/liberapay/wireup.py @@ -10,7 +10,7 @@ from six import text_type as str from algorithm import Algorithm -import aspen +import pando from babel.core import Locale from babel.messages.pofile import read_po from babel.numbers import parse_pattern @@ -39,10 +39,12 @@ def canonical(env): canonical_scheme = env.canonical_scheme canonical_host = env.canonical_host - canonical_domain = None - if env.canonical_host: + if canonical_host: canonical_domain = ('.' + canonical_host.split(':')[0]).encode('ascii') - canonical_url = '%s://%s' % (canonical_scheme, canonical_host) + canonical_url = '%s://%s' % (canonical_scheme, canonical_host) + else: + canonical_domain = None + canonical_url = '' asset_url = canonical_url+'/assets/' return locals() @@ -193,7 +195,7 @@ def make_sentry_teller(env): def tell_sentry(exception, state, allow_reraise=False): - if isinstance(exception, aspen.Response) and exception.code < 500: + if isinstance(exception, pando.Response) and exception.code < 500: # Only log server errors return diff --git a/tests/py/test_charts_json.py b/tests/py/test_charts_json.py index 7448a90233..1bf41731b5 100644 --- a/tests/py/test_charts_json.py +++ b/tests/py/test_charts_json.py @@ -3,7 +3,8 @@ import datetime import json -from aspen.utils import utcnow +from pando.utils import utcnow + from liberapay.billing.payday import Payday from liberapay.testing.mangopay import FakeTransfersHarness diff --git a/tests/py/test_elsewhere.py b/tests/py/test_elsewhere.py index f6b8dbe722..34ef9bff3a 100644 --- a/tests/py/test_elsewhere.py +++ b/tests/py/test_elsewhere.py @@ -186,7 +186,7 @@ def test_confirm(self): assert 'Please Confirm' in response.text def test_take_over(self): - data = {'account_id': self.alice_elsewhere.id, 'should_transfer': 'yes'} + data = {'account_id': str(self.alice_elsewhere.id), 'should_transfer': 'yes'} response = self.client.PxST('/on/take-over.html', data=data) assert response.code == 403 @@ -233,6 +233,6 @@ def test_delete(self): alice = self.make_participant('alice', elsewhere=platform) self.make_elsewhere('github', '1', 'alice') alice.take_over(('github', '1')) - data = dict(platform=platform, user_id=alice.id) + data = dict(platform=platform, user_id=str(alice.id)) response = self.client.PxST('/alice/elsewhere/delete', data, auth_as=alice) assert response.code == 302 diff --git a/tests/py/test_hooks.py b/tests/py/test_hooks.py index eea1920356..9a82390af3 100644 --- a/tests/py/test_hooks.py +++ b/tests/py/test_hooks.py @@ -5,9 +5,9 @@ from base64 import b64encode import json -from aspen.exceptions import MalformedBody, UnknownBodyType -from aspen.http.request import Request -from aspen.http.response import Response +from pando.exceptions import MalformedBody, UnknownBodyType +from pando.http.request import Request +from pando.http.response import Response from liberapay.constants import SESSION from liberapay.security import csrf diff --git a/tests/py/test_pages.py b/tests/py/test_pages.py index 546d90cce8..0918193f7e 100644 --- a/tests/py/test_pages.py +++ b/tests/py/test_pages.py @@ -7,7 +7,7 @@ import os import re -from aspen import json, Response +from pando import json, Response import pytest from liberapay.billing.payday import Payday diff --git a/tests/py/test_payio.py b/tests/py/test_payio.py index e6dd8fd8dd..a7a3506fc5 100644 --- a/tests/py/test_payio.py +++ b/tests/py/test_payio.py @@ -2,7 +2,7 @@ from decimal import Decimal as D -from aspen import Response +from pando import Response import mock import pytest diff --git a/tests/py/test_sign_in.py b/tests/py/test_sign_in.py index 09f40094e1..1d51337a73 100644 --- a/tests/py/test_sign_in.py +++ b/tests/py/test_sign_in.py @@ -8,7 +8,7 @@ from six.moves.http_cookies import SimpleCookie -from aspen.utils import utcnow +from pando.utils import utcnow from liberapay.constants import SESSION from liberapay.models.participant import Participant diff --git a/tests/py/test_utils.py b/tests/py/test_utils.py index d46f546944..91b67bfee1 100644 --- a/tests/py/test_utils.py +++ b/tests/py/test_utils.py @@ -3,7 +3,8 @@ from datetime import datetime from datetime import timedelta -from aspen.http.response import Response +from pando.http.response import Response + from liberapay import utils from liberapay.testing import Harness from liberapay.utils import i18n, markdown, b64encode_s, b64decode_s @@ -13,20 +14,20 @@ class Tests(Harness): def test_get_participant_gets_participant(self): expected = self.make_participant('alice') - state = self.client.GET('/alice/', return_after='dispatch_request_to_filesystem', + state = self.client.GET('/alice/', return_after='handle_dispatch_exception', want='state') actual = utils.get_participant(state, restrict=False) assert actual == expected def test_get_participant_gets_participant_from_id(self): expected = self.make_participant('alice') - state = self.client.POST('/~1/', return_after='dispatch_request_to_filesystem', + state = self.client.POST('/~1/', return_after='handle_dispatch_exception', want='state') actual = utils.get_participant(state, restrict=False) assert actual == expected def test_get_participant_raises_404_for_missing_id(self): - state = self.client.GET('/~/', return_after='dispatch_request_to_filesystem', + state = self.client.GET('/~/', return_after='handle_dispatch_exception', want='state') with self.assertRaises(Response) as cm: utils.get_participant(state, restrict=False) @@ -35,7 +36,7 @@ def test_get_participant_raises_404_for_missing_id(self): def test_get_participant_canonicalizes(self): self.make_participant('alice') - state = self.client.GET('/Alice/?foo=bar', return_after='dispatch_request_to_filesystem', + state = self.client.GET('/Alice/?foo=bar', return_after='handle_dispatch_exception', want='state') with self.assertRaises(Response) as cm: utils.get_participant(state, restrict=False) @@ -45,7 +46,7 @@ def test_get_participant_canonicalizes(self): def test_get_participant_canonicalizes_id_to_username(self): self.make_participant('alice') - state = self.client.GET('/~1/?x=2', return_after='dispatch_request_to_filesystem', + state = self.client.GET('/~1/?x=2', return_after='handle_dispatch_exception', want='state') with self.assertRaises(Response) as cm: utils.get_participant(state, restrict=False) diff --git a/www/%username/avatar.spt b/www/%username/avatar.spt index a32bce4ccd..8f81004bc2 100644 --- a/www/%username/avatar.spt +++ b/www/%username/avatar.spt @@ -1,4 +1,4 @@ -from aspen import Response +from pando import Response from liberapay.utils import b64encode_s, get_participant diff --git a/www/%username/charts.json.spt b/www/%username/charts.json.spt index e5c66d95c6..4e9c600111 100644 --- a/www/%username/charts.json.spt +++ b/www/%username/charts.json.spt @@ -16,7 +16,7 @@ implementation. """ -from aspen import Response +from pando import Response from liberapay.utils import get_participant diff --git a/www/%username/communities.json.spt b/www/%username/communities.json.spt index 3a51bfbcb8..8c425287e4 100644 --- a/www/%username/communities.json.spt +++ b/www/%username/communities.json.spt @@ -1,4 +1,4 @@ -from aspen import Response +from pando import Response from liberapay.utils import get_participant diff --git a/www/%username/edit.spt b/www/%username/edit.spt index 8ced882105..f46f328f5a 100644 --- a/www/%username/edit.spt +++ b/www/%username/edit.spt @@ -1,7 +1,7 @@ # coding: utf8 from __future__ import print_function, unicode_literals -from aspen import Response +from pando import Response from liberapay.utils import get_participant, markdown from liberapay.utils.i18n import LANGUAGES_2 diff --git a/www/%username/elsewhere/delete.spt b/www/%username/elsewhere/delete.spt index ce2b07d0f8..2bfd0957b7 100644 --- a/www/%username/elsewhere/delete.spt +++ b/www/%username/elsewhere/delete.spt @@ -14,5 +14,7 @@ participant.delete_elsewhere(platform, user_id) if request.headers.get('X-Requested-With') != 'XMLHttpRequest': response.redirect('..') +[---] text/html + [---] application/json via json_dump {} diff --git a/www/%username/elsewhere/refresh.spt b/www/%username/elsewhere/refresh.spt index cb2120714e..7dcac69788 100644 --- a/www/%username/elsewhere/refresh.spt +++ b/www/%username/elsewhere/refresh.spt @@ -1,4 +1,4 @@ -from aspen import Response +from pando import Response from liberapay.models.account_elsewhere import AccountElsewhere from liberapay.utils import get_participant diff --git a/www/%username/emails/modify.json.spt b/www/%username/emails/modify.json.spt index 906c004c1c..b16d11f5e7 100644 --- a/www/%username/emails/modify.json.spt +++ b/www/%username/emails/modify.json.spt @@ -1,4 +1,4 @@ -from aspen import Response +from pando import Response from liberapay.utils import get_participant [-----------------------------------------] diff --git a/www/%username/emails/verify.html.spt b/www/%username/emails/verify.html.spt index a899e5da57..f0cc4ce8c1 100644 --- a/www/%username/emails/verify.html.spt +++ b/www/%username/emails/verify.html.spt @@ -2,8 +2,8 @@ """ from datetime import timedelta -from aspen import Response -from aspen.utils import utcnow +from pando import Response +from pando.utils import utcnow from liberapay.utils import b64decode_s, emails, get_participant [-----------------------------------------------------------------------------] diff --git a/www/%username/giving/index.html.spt b/www/%username/giving/index.html.spt index 1c9b3722eb..90a1c6c86d 100644 --- a/www/%username/giving/index.html.spt +++ b/www/%username/giving/index.html.spt @@ -1,8 +1,8 @@ from datetime import timedelta from decimal import Decimal -from aspen import Response -from aspen.utils import utcnow +from pando import Response +from pando.utils import utcnow from liberapay.models.participant import Participant from liberapay.utils import get_participant diff --git a/www/%username/goal.spt b/www/%username/goal.spt index 6c91b7c27c..d7d0e55218 100644 --- a/www/%username/goal.spt +++ b/www/%username/goal.spt @@ -1,4 +1,4 @@ -from aspen import Response +from pando import Response from liberapay.utils import get_participant diff --git a/www/%username/identity.spt b/www/%username/identity.spt index d36d491af6..9afe4ce29d 100644 --- a/www/%username/identity.spt +++ b/www/%username/identity.spt @@ -1,6 +1,6 @@ from datetime import datetime -from aspen import Response +from pando import Response from mangopaysdk.entities.userlegal import UserLegal from mangopaysdk.entities.usernatural import UserNatural diff --git a/www/%username/income/index.html.spt b/www/%username/income/index.html.spt index 49a2d3ab62..55b2428887 100644 --- a/www/%username/income/index.html.spt +++ b/www/%username/income/index.html.spt @@ -1,7 +1,7 @@ # encoding: utf8 from __future__ import division, print_function, unicode_literals -from aspen import Response +from pando import Response from liberapay.utils import get_participant diff --git a/www/%username/income/take.spt b/www/%username/income/take.spt index f010aeaa1f..54b2ad0ac9 100644 --- a/www/%username/income/take.spt +++ b/www/%username/income/take.spt @@ -1,6 +1,6 @@ from __future__ import division, print_function, unicode_literals -from aspen import Response +from pando import Response from liberapay.elsewhere._paginators import _modify_query from liberapay.exceptions import AuthRequired diff --git a/www/%username/members.json.spt b/www/%username/members.json.spt index 5b4e6e8b0f..119c3f5c72 100644 --- a/www/%username/members.json.spt +++ b/www/%username/members.json.spt @@ -1,6 +1,6 @@ """Endpoint to list team members. """ -from aspen import Response +from pando import Response from liberapay.utils import get_participant [--------------------] diff --git a/www/%username/membership/%action.spt b/www/%username/membership/%action.spt index 8b3a9f649c..2534175cca 100644 --- a/www/%username/membership/%action.spt +++ b/www/%username/membership/%action.spt @@ -2,7 +2,7 @@ from __future__ import division, print_function, unicode_literals from datetime import timedelta -from aspen import Response +from pando import Response from liberapay.elsewhere._paginators import _modify_query from liberapay.exceptions import AuthRequired diff --git a/www/%username/receipts/%exchange_id.spt b/www/%username/receipts/%exchange_id.spt index 1fa16bfa46..a6b7c77bb9 100644 --- a/www/%username/receipts/%exchange_id.spt +++ b/www/%username/receipts/%exchange_id.spt @@ -1,4 +1,4 @@ -from aspen import Response +from pando import Response from liberapay.billing import mangoapi from liberapay.models.exchange_route import ExchangeRoute diff --git a/www/%username/routes/bank-account.spt b/www/%username/routes/bank-account.spt index 2f7acc90ad..2c10fa8cb1 100644 --- a/www/%username/routes/bank-account.spt +++ b/www/%username/routes/bank-account.spt @@ -1,7 +1,7 @@ from functools import reduce -from aspen import Response +from pando import Response from mangopaysdk.entities.bankaccount import BankAccount from mangopaysdk.types.address import Address from mangopaysdk.types.bankaccountdetailsiban import BankAccountDetailsIBAN diff --git a/www/%username/routes/credit-card.json.spt b/www/%username/routes/credit-card.json.spt index 7a4395ade3..1cb16a0c05 100644 --- a/www/%username/routes/credit-card.json.spt +++ b/www/%username/routes/credit-card.json.spt @@ -1,6 +1,6 @@ from __future__ import absolute_import, division, print_function, unicode_literals -from aspen import Response +from pando import Response from mangopaysdk.entities.card import Card from mangopaysdk.entities.cardregistration import CardRegistration diff --git a/www/%username/routes/delete.json.spt b/www/%username/routes/delete.json.spt index fd6db519be..ba919d56ae 100644 --- a/www/%username/routes/delete.json.spt +++ b/www/%username/routes/delete.json.spt @@ -1,6 +1,6 @@ from __future__ import absolute_import, division, print_function, unicode_literals -from aspen import Response +from pando import Response from liberapay.models.exchange_route import ExchangeRoute from liberapay.utils import get_participant diff --git a/www/%username/settings/edit.spt b/www/%username/settings/edit.spt index b759ec7944..81c594dce4 100644 --- a/www/%username/settings/edit.spt +++ b/www/%username/settings/edit.spt @@ -1,4 +1,4 @@ -from aspen import Response +from pando import Response from liberapay.constants import PRIVACY_FIELDS from liberapay.models.participant import Participant @@ -47,5 +47,7 @@ elif 'username' in body: if request.headers.get('X-Requested-With') != 'XMLHttpRequest': response.redirect('.') +[---] text/html + [---] application/json out diff --git a/www/%username/tips.json.spt b/www/%username/tips.json.spt index 6efc5c7458..d654202020 100644 --- a/www/%username/tips.json.spt +++ b/www/%username/tips.json.spt @@ -1,6 +1,6 @@ from itertools import chain -from aspen import Response +from pando import Response from liberapay.utils import get_participant [-----------------------] diff --git a/www/%username/wallet/export.spt b/www/%username/wallet/export.spt index fea0d470eb..fc1f44c361 100644 --- a/www/%username/wallet/export.spt +++ b/www/%username/wallet/export.spt @@ -1,6 +1,6 @@ from datetime import datetime -from aspen import Response +from pando import Response from liberapay.utils import get_participant from liberapay.utils.history import export_history diff --git a/www/%username/wallet/index.html.spt b/www/%username/wallet/index.html.spt index 67cf6121b2..cc3a5613b5 100644 --- a/www/%username/wallet/index.html.spt +++ b/www/%username/wallet/index.html.spt @@ -1,6 +1,6 @@ from datetime import datetime -from aspen import Response +from pando import Response from liberapay.utils import get_participant from liberapay.utils.history import iter_payday_events diff --git a/www/%username/wallet/payin/bankwire/%back_to.spt b/www/%username/wallet/payin/bankwire/%back_to.spt index ac5d89467d..569e23203c 100644 --- a/www/%username/wallet/payin/bankwire/%back_to.spt +++ b/www/%username/wallet/payin/bankwire/%back_to.spt @@ -3,7 +3,7 @@ from __future__ import absolute_import, division, print_function, unicode_litera from decimal import Decimal as D, InvalidOperation -from aspen import json, Response +from pando import json, Response from liberapay.billing import mangoapi from liberapay.billing.exchanges import payin_bank_wire, upcharge_bank_wire diff --git a/www/%username/wallet/payin/card/%back_to.spt b/www/%username/wallet/payin/card/%back_to.spt index 436f15d780..0fc158a462 100644 --- a/www/%username/wallet/payin/card/%back_to.spt +++ b/www/%username/wallet/payin/card/%back_to.spt @@ -3,7 +3,7 @@ from __future__ import absolute_import, division, print_function, unicode_litera from decimal import Decimal as D, InvalidOperation -from aspen import Response +from pando import Response from liberapay.billing import mangoapi from liberapay.billing.exchanges import charge, record_exchange_result, repr_error, upcharge_card diff --git a/www/%username/wallet/payout/%back_to.spt b/www/%username/wallet/payout/%back_to.spt index 37e678980b..033c19ac55 100644 --- a/www/%username/wallet/payout/%back_to.spt +++ b/www/%username/wallet/payout/%back_to.spt @@ -4,7 +4,7 @@ from __future__ import absolute_import, division, print_function, unicode_litera from datetime import datetime from decimal import Decimal as D -from aspen import Response +from pando import Response from liberapay.billing import mangoapi from liberapay.billing.exchanges import payout diff --git a/www/%username/widgets/%type.spt b/www/%username/widgets/%type.spt index 974c922721..8eb6386296 100644 --- a/www/%username/widgets/%type.spt +++ b/www/%username/widgets/%type.spt @@ -1,4 +1,4 @@ -from aspen import Response +from pando import Response from markupsafe import Markup from liberapay.utils import get_participant diff --git a/www/about/teams.spt b/www/about/teams.spt index 9ec41eb093..2378a50e57 100644 --- a/www/about/teams.spt +++ b/www/about/teams.spt @@ -1,6 +1,6 @@ # encoding: utf8 -from aspen import Response +from pando import Response from liberapay.exceptions import AuthRequired, UsernameAlreadyTaken from liberapay.models.participant import Participant diff --git a/www/admin/payday/%id.spt b/www/admin/payday/%id.spt index d54a1cfcbf..cbcd40735f 100644 --- a/www/admin/payday/%id.spt +++ b/www/admin/payday/%id.spt @@ -5,7 +5,7 @@ from subprocess import Popen import sys from threading import Lock -from aspen import Response +from pando import Response from liberapay.exceptions import AuthRequired from liberapay.utils import pid_exists diff --git a/www/callbacks/mangopay.spt b/www/callbacks/mangopay.spt index 3746f44934..5c63bb88d3 100644 --- a/www/callbacks/mangopay.spt +++ b/www/callbacks/mangopay.spt @@ -3,7 +3,7 @@ Doc: https://docs.mangopay.com/api-references/notifications/ """ -from aspen import Response +from pando import Response from liberapay.billing import mangoapi from liberapay.billing.exchanges import record_exchange_result, record_payout_refund, repr_error diff --git a/www/for/%name/%action.spt b/www/for/%name/%action.spt index 07a9581050..1d63a5762e 100644 --- a/www/for/%name/%action.spt +++ b/www/for/%name/%action.spt @@ -1,4 +1,4 @@ -from aspen import Response +from pando import Response from liberapay.utils import get_community diff --git a/www/for/%name/edit.spt b/www/for/%name/edit.spt index 6d8fb134f9..2e01efa774 100644 --- a/www/for/%name/edit.spt +++ b/www/for/%name/edit.spt @@ -1,4 +1,4 @@ -from aspen import Response +from pando import Response from liberapay.utils import get_community from liberapay.utils.i18n import LANGUAGES_2 diff --git a/www/for/%name/index.html.spt b/www/for/%name/index.html.spt index 5ae6053020..86657a28ea 100644 --- a/www/for/%name/index.html.spt +++ b/www/for/%name/index.html.spt @@ -1,4 +1,4 @@ -from aspen import Response +from pando import Response from six.moves.urllib.parse import quote as urlquote diff --git a/www/for/%name/index.json.spt b/www/for/%name/index.json.spt index 0bd177fc31..f24f2fe0bb 100644 --- a/www/for/%name/index.json.spt +++ b/www/for/%name/index.json.spt @@ -1,4 +1,4 @@ -from aspen import Response +from pando import Response from liberapay.models.community import Community [----------------------] diff --git a/www/for/new.spt b/www/for/new.spt index 487e3f640d..87387ddcba 100644 --- a/www/for/new.spt +++ b/www/for/new.spt @@ -1,4 +1,4 @@ -from aspen import Response +from pando import Response from liberapay.exceptions import AuthRequired from liberapay.models.community import name_maxlength, normalize diff --git a/www/on/%platform/%user_name/%endpoint.json.spt b/www/on/%platform/%user_name/%endpoint.json.spt index 22e59e8263..706f06cc3d 100644 --- a/www/on/%platform/%user_name/%endpoint.json.spt +++ b/www/on/%platform/%user_name/%endpoint.json.spt @@ -1,7 +1,7 @@ from base64 import b64decode, b64encode from urllib import urlencode -from aspen import Response +from pando import Response from liberapay.models.account_elsewhere import get_account_elsewhere diff --git a/www/on/%platform/%user_name/failure.html.spt b/www/on/%platform/%user_name/failure.html.spt index f02272a52c..af5679fe59 100644 --- a/www/on/%platform/%user_name/failure.html.spt +++ b/www/on/%platform/%user_name/failure.html.spt @@ -1,4 +1,4 @@ -from aspen import Response +from pando import Response from liberapay.models.account_elsewhere import get_account_elsewhere diff --git a/www/on/%platform/%user_name/index.html.spt b/www/on/%platform/%user_name/index.html.spt index b69fbcaeb9..90169cd933 100644 --- a/www/on/%platform/%user_name/index.html.spt +++ b/www/on/%platform/%user_name/index.html.spt @@ -1,6 +1,6 @@ # encoding: utf8 -from aspen import Response +from pando import Response from liberapay.models.account_elsewhere import * from liberapay.utils import b64decode_s diff --git a/www/on/%platform/associate.spt b/www/on/%platform/associate.spt index b120ae46d8..1b22e86f2a 100644 --- a/www/on/%platform/associate.spt +++ b/www/on/%platform/associate.spt @@ -1,7 +1,7 @@ import json -from aspen import resources, Response from oauthlib.oauth2 import OAuth2Error +from pando import Response from requests_oauthlib.oauth1_session import TokenRequestDenied from liberapay.elsewhere._exceptions import CantReadMembership diff --git a/www/on/%platform/index.spt b/www/on/%platform/index.spt index 5aa01a0d91..1cfc01089d 100644 --- a/www/on/%platform/index.spt +++ b/www/on/%platform/index.spt @@ -1,4 +1,4 @@ -from aspen import Response +from pando import Response from oauthlib.oauth2 import TokenExpiredError from liberapay.models.account_elsewhere import AccountElsewhere diff --git a/www/on/%platform/redirect.spt b/www/on/%platform/redirect.spt index c02243dc4a..6ecc13ceb7 100644 --- a/www/on/%platform/redirect.spt +++ b/www/on/%platform/redirect.spt @@ -1,7 +1,7 @@ from datetime import timedelta import json -from aspen import Response +from pando import Response from liberapay.exceptions import AuthRequired from liberapay.models.participant import Participant from liberapay.utils import b64encode_s diff --git a/www/on/confirm.html.spt b/www/on/confirm.html.spt index 638ab1c614..c4324e6e5e 100644 --- a/www/on/confirm.html.spt +++ b/www/on/confirm.html.spt @@ -1,4 +1,4 @@ -from aspen import Response +from pando import Response from liberapay.exceptions import AuthRequired from liberapay.models.account_elsewhere import AccountElsewhere diff --git a/www/on/index.spt b/www/on/index.spt index b42c61ffad..44e6e616e7 100644 --- a/www/on/index.spt +++ b/www/on/index.spt @@ -1,4 +1,4 @@ -from aspen import Response +from pando import Response [---] platform = request.qs.get('platform') if platform: diff --git a/www/on/take-over.html.spt b/www/on/take-over.html.spt index 026b63b0e0..69a4161d8c 100644 --- a/www/on/take-over.html.spt +++ b/www/on/take-over.html.spt @@ -1,4 +1,4 @@ -from aspen import Response +from pando import Response from liberapay.exceptions import AuthRequired from liberapay.models.account_elsewhere import AccountElsewhere diff --git a/www/sign-out.spt b/www/sign-out.spt index 440f8a5b96..dcafbc4f3f 100644 --- a/www/sign-out.spt +++ b/www/sign-out.spt @@ -1,4 +1,4 @@ -from aspen import Response +from pando import Response from liberapay.security.authentication import ANON From 5d3f29c2428bf2d236266682f38059850ca82408 Mon Sep 17 00:00:00 2001 From: Changaco Date: Fri, 26 Aug 2016 23:58:35 +0200 Subject: [PATCH 3/4] upgrade aspen-jinja2 to 0.5 --- liberapay/renderers/jinja2_htmlescaped.py | 28 +++++++++++++---------- requirements.txt | 2 +- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/liberapay/renderers/jinja2_htmlescaped.py b/liberapay/renderers/jinja2_htmlescaped.py index b928bf22d9..873858b12c 100644 --- a/liberapay/renderers/jinja2_htmlescaped.py +++ b/liberapay/renderers/jinja2_htmlescaped.py @@ -5,27 +5,31 @@ from liberapay.constants import JINJA_ENV_COMMON -class HTMLRenderer(base.Renderer): - def render_content(self, context): +class Renderer(base.Renderer): + + autoescape = True + def render_content(self, context): # Extend to inject an HTML-escaping function. Since autoescape is on, # template authors shouldn't normally need to use this function, but # having it in the simplate context makes it easier to implement i18n. - - context['escape'] = context['state']['escape'] = htmlescape - + if self.is_sgml: + context['escape'] = context['state']['escape'] = htmlescape return base.Renderer.render_content(self, context) class Factory(base.Factory): - Renderer = HTMLRenderer + Renderer = Renderer def compile_meta(self, configuration): - # Override to turn on autoescaping. + # Override to add our own JINJA_ENV_COMMON conf loader = base.FileSystemLoader(configuration.project_root) - return base.Environment( - loader=loader, - autoescape=True, extensions=['jinja2.ext.autoescape'], - **JINJA_ENV_COMMON - ) + return { + 'default_env': base.Environment(loader=loader, **JINJA_ENV_COMMON), + 'htmlescaped_env': base.Environment( + loader=loader, + autoescape=True, extensions=['jinja2.ext.autoescape'], + **JINJA_ENV_COMMON + ), + } diff --git a/requirements.txt b/requirements.txt index 456957e62b..0852468fba 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,7 +11,7 @@ gunicorn==19.6.0 MarkupSafe==0.23 Jinja2==2.8 -aspen-jinja2==0.4 +aspen-jinja2==0.5 psycopg2==2.6.1 postgres==2.2.1 From 086f8bf415ac1c37565732ae809d07f918ec7d96 Mon Sep 17 00:00:00 2001 From: Changaco Date: Fri, 26 Aug 2016 23:59:02 +0200 Subject: [PATCH 4/4] test Content-Type charset in responses --- tests/py/test_hooks.py | 2 +- tests/py/test_pages.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/py/test_hooks.py b/tests/py/test_hooks.py index 9a82390af3..a51b8718a4 100644 --- a/tests/py/test_hooks.py +++ b/tests/py/test_hooks.py @@ -110,7 +110,7 @@ class Tests2(Harness): def test_accept_header_is_respected(self): r = self.client.GET('/about/stats', HTTP_ACCEPT=b'application/json') - assert r.headers['Content-Type'].startswith('application/json') + assert r.headers['Content-Type'] == 'application/json; charset=UTF-8' json.loads(r.body) def test_error_spt_works(self): diff --git a/tests/py/test_pages.py b/tests/py/test_pages.py index 0918193f7e..c6b423419b 100644 --- a/tests/py/test_pages.py +++ b/tests/py/test_pages.py @@ -109,6 +109,8 @@ def test_homepage_in_all_supported_langs(self): link_lang = link_lang.format(l, self.website.canonical_scheme, self.website.canonical_host) assert link_lang in r.text + assert r.headers[b'Content-Type'] == 'text/html; charset=UTF-8' + def test_escaping_on_homepage(self): alice = self.make_participant('alice') expected = ""