From f2eabd112b6e49f04d245d6bbdee32396c871989 Mon Sep 17 00:00:00 2001 From: Adrian Moennich Date: Wed, 28 Jul 2021 12:28:50 +0200 Subject: [PATCH] Fix flake8 issues --- payment_sixpay/indico_sixpay/__init__.py | 32 +++++++++---------- payment_sixpay/indico_sixpay/plugin.py | 31 +++++------------- .../indico_sixpay/request_handlers.py | 10 +++--- payment_sixpay/indico_sixpay/utility.py | 4 +-- payment_sixpay/setup.py | 2 +- 5 files changed, 32 insertions(+), 47 deletions(-) diff --git a/payment_sixpay/indico_sixpay/__init__.py b/payment_sixpay/indico_sixpay/__init__.py index ace9ae6..592baf9 100644 --- a/payment_sixpay/indico_sixpay/__init__.py +++ b/payment_sixpay/indico_sixpay/__init__.py @@ -1,17 +1,17 @@ # -*- coding: utf-8 -*- -## -## This file is part of the SixPay Indico EPayment Plugin. -## Copyright (C) 2017 - 2018 Max Fischer -## -## This is free software; you can redistribute it and/or -## modify it under the terms of the GNU General Public License as -## published by the Free Software Foundation; either version 3 of the -## License, or (at your option) any later version. -## -## This software is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with SixPay Indico EPayment Plugin;if not, see . +# +# This file is part of the SixPay Indico EPayment Plugin. +# Copyright (C) 2017 - 2018 Max Fischer +# +# This is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 3 of the +# License, or (at your option) any later version. +# +# This software is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with SixPay Indico EPayment Plugin;if not, see . diff --git a/payment_sixpay/indico_sixpay/plugin.py b/payment_sixpay/indico_sixpay/plugin.py index 9e4bf0e..15d08c4 100644 --- a/payment_sixpay/indico_sixpay/plugin.py +++ b/payment_sixpay/indico_sixpay/plugin.py @@ -25,7 +25,7 @@ and provides callbacks for finished payments via its blueprint. from __future__ import absolute_import, unicode_literals import requests -import urlparse +from urllib.parse import urljoin from werkzeug.exceptions import InternalServerError as HTTPInternalServerError from werkzeug.exceptions import NotImplemented as HTTPNotImplemented from wtforms.fields import StringField @@ -182,7 +182,7 @@ class PluginSettingsForm(PaymentPluginSettingsFormBase): validators=[Optional(), Email(), Length(0, 50)], description=gettext( 'Mail address to receive notifications of transactions.' - 'This is independent of Indico\'s own payment notifications.' + "This is independent of Indico's own payment notifications." ) ) @@ -191,9 +191,6 @@ class EventSettingsForm(PaymentEventSettingsFormBase): """Configuration form for the Plugin for a specific event.""" # every setting may be overwritten for each event - #url = PluginSettingsForm.url - #username = PluginSettingsForm.username - #password = PluginSettingsForm.password account_id = PluginSettingsForm.account_id order_description = PluginSettingsForm.order_description order_identifier = PluginSettingsForm.order_identifier @@ -318,23 +315,11 @@ class SixpayPaymentPlugin(PaymentPluginMixin, IndicoPlugin): plugin_settings[format_field].format(**format_map) ) except ValueError: - message = ( - "Invalid format field placeholder for {0}," - " please contact the event organisers!" - ) - raise HTTPNotImplemented( - (gettext(message) + '\n\n[' + message + ']') - .format(self.name) - ) + message = 'Invalid format field placeholder for {0}, please contact the event organisers!' + raise HTTPNotImplemented((gettext(message) + '\n\n[' + message + ']').format(self.name)) except KeyError: - message = ( - 'Unknown format field placeholder "{0}" for {1},' - ' please contact the event organisers!' - ) - raise HTTPNotImplemented(( - gettext(message) + '\n\n[' + message + ']' - ).format(format_field, self.name) - ) + message = 'Unknown format field placeholder "{0}" for {1}, please contact the event organisers!' + raise HTTPNotImplemented((gettext(message) + '\n\n[' + message + ']').format(format_field, self.name)) # see the SixPay Manual # https://saferpay.github.io/jsonapi/#Payment_v1_PaymentPage_Initialize @@ -398,7 +383,7 @@ class SixpayPaymentPlugin(PaymentPluginMixin, IndicoPlugin): def _init_payment_page(self, sixpay_url, transaction_data, credentials): """Initialize payment page.""" - endpoint = urlparse.urljoin(sixpay_url, saferpay_pp_init_url) + endpoint = urljoin(sixpay_url, saferpay_pp_init_url) url_request = requests.post( endpoint, json=transaction_data, @@ -413,6 +398,6 @@ class SixpayPaymentPlugin(PaymentPluginMixin, IndicoPlugin): raise HTTPInternalServerError( 'Failed request to SixPay service:' ' {ErrorMessage}. {ErrorDetail}' - .format(response) + .format(**response) ) return response diff --git a/payment_sixpay/indico_sixpay/request_handlers.py b/payment_sixpay/indico_sixpay/request_handlers.py index 4e9a8a6..37037b7 100644 --- a/payment_sixpay/indico_sixpay/request_handlers.py +++ b/payment_sixpay/indico_sixpay/request_handlers.py @@ -20,7 +20,7 @@ from __future__ import unicode_literals import requests -import urlparse +from urllib.parse import urljoin from flask import flash, redirect, request from flask_pluginengine import current_plugin from werkzeug.exceptions import BadRequest @@ -98,7 +98,7 @@ class SixPayResponseHandler(BaseRequestHandler): self._process_confirmation() except TransactionFailure as err: current_plugin.logger.warning( - "SixPay transaction failed during %s: %s" + 'SixPay transaction failed during %s: %s' % (err.step, err.details) ) @@ -123,7 +123,7 @@ class SixPayResponseHandler(BaseRequestHandler): self._register_payment(assert_response) except TransactionFailure as err: current_plugin.logger.warning( - "SixPay transaction failed during %s: %s" + 'SixPay transaction failed during %s: %s' % (err.step, err.details) ) raise @@ -142,7 +142,7 @@ class SixPayResponseHandler(BaseRequestHandler): request. If the request itself fails, a :py:exc:`~.TransactionFailure` is raised for ``task``. """ - request_url = urlparse.urljoin(self.sixpay_url, endpoint) + request_url = urljoin(self.sixpay_url, endpoint) credentials = ( get_setting('username'), get_setting('password') @@ -325,7 +325,7 @@ class UserSuccessHandler(SixPayResponseHandler): self._process_confirmation() except TransactionFailure as err: current_plugin.logger.warning( - "SixPay transaction failed during %s: %s" % ( + 'SixPay transaction failed during %s: %s' % ( err.step, err.details ) ) diff --git a/payment_sixpay/indico_sixpay/utility.py b/payment_sixpay/indico_sixpay/utility.py index 5234bab..cf86594 100644 --- a/payment_sixpay/indico_sixpay/utility.py +++ b/payment_sixpay/indico_sixpay/utility.py @@ -57,7 +57,7 @@ def validate_currency(iso_code): raise HTTPNotImplemented( gettext( "Unsupported currency '{0}' for SixPay." - " Please contact the organisers" + ' Please contact the organisers' ).format(iso_code) ) try: @@ -66,7 +66,7 @@ def validate_currency(iso_code): raise HTTPNotImplemented( gettext( "Unknown currency '{0}' for SixPay." - " Please contact the organisers" + ' Please contact the organisers' ).format(iso_code) ) diff --git a/payment_sixpay/setup.py b/payment_sixpay/setup.py index 741e51b..f662d15 100644 --- a/payment_sixpay/setup.py +++ b/payment_sixpay/setup.py @@ -6,7 +6,7 @@ from setuptools import find_packages, setup repo_base_dir = os.path.abspath(os.path.dirname(__file__)) # pull in the packages metadata package_about = {} -with open(os.path.join(repo_base_dir, "indico_sixpay", "__about__.py")) as about_file: +with open(os.path.join(repo_base_dir, 'indico_sixpay', '__about__.py')) as about_file: exec(about_file.read(), package_about) setup(