소스 검색

refactor: clean up code to py310 supported features (#17367)

refactor: clean up code to py39+ supported syntax

- f-strings instead of format
- latest typing support instead of pre 3.9 TitleCase
- remove UTF-8 declarations.
- many more changes

Powered by https://github.com/asottile/pyupgrade/ + manual cleanups
pull/2/head
Ankush Menat 2 년 전
committed by GitHub
부모
커밋
b613fd1285
10개의 변경된 파일20개의 추가작업 그리고 34개의 파일을 삭제
  1. +1
    -2
      payments/payment_gateways/doctype/braintree_settings/braintree_settings.py
  2. +0
    -1
      payments/payment_gateways/doctype/braintree_settings/test_braintree_settings.py
  3. +6
    -9
      payments/payment_gateways/doctype/paypal_settings/paypal_settings.py
  4. +1
    -2
      payments/payment_gateways/doctype/paytm_settings/paytm_settings.py
  5. +0
    -1
      payments/payment_gateways/doctype/paytm_settings/test_paytm_settings.py
  6. +10
    -13
      payments/payment_gateways/doctype/razorpay_settings/razorpay_settings.py
  7. +2
    -3
      payments/payment_gateways/doctype/stripe_settings/stripe_settings.py
  8. +0
    -1
      payments/payment_gateways/doctype/stripe_settings/test_stripe_settings.py
  9. +0
    -1
      payments/payments/doctype/payment_gateway/payment_gateway.py
  10. +0
    -1
      payments/payments/doctype/payment_gateway/test_payment_gateway.py

+ 1
- 2
payments/payment_gateways/doctype/braintree_settings/braintree_settings.py 파일 보기

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2018, Frappe Technologies and contributors
# License: MIT. See LICENSE

@@ -184,7 +183,7 @@ class BraintreeSettings(Document):
)

def get_payment_url(self, **kwargs):
return get_url("./integrations/braintree_checkout?{0}".format(urlencode(kwargs)))
return get_url(f"./integrations/braintree_checkout?{urlencode(kwargs)}")

def create_payment_request(self, data):
self.data = frappe._dict(data)


+ 0
- 1
payments/payment_gateways/doctype/braintree_settings/test_braintree_settings.py 파일 보기

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2018, Frappe Technologies and Contributors
# License: MIT. See LICENSE
import unittest


+ 6
- 9
payments/payment_gateways/doctype/paypal_settings/paypal_settings.py 파일 보기

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2015, Frappe Technologies and contributors
# License: MIT. See LICENSE

@@ -193,7 +192,7 @@ class PayPalSettings(Document):
params.update(
{
"METHOD": "SetExpressCheckout",
"returnUrl": get_url("{0}.get_express_checkout_details".format(api_path)),
"returnUrl": get_url(f"{api_path}.get_express_checkout_details"),
"cancelUrl": get_url("/payment-cancel"),
"PAYMENTREQUEST_0_PAYMENTACTION": "SALE",
"PAYMENTREQUEST_0_AMT": kwargs["amount"],
@@ -331,7 +330,7 @@ def confirm_payment(token):
).run_method("on_payment_authorized", "Completed")
frappe.db.commit()

redirect_url = "/integrations/payment-success?doctype={0}&docname={1}".format(
redirect_url = "/integrations/payment-success?doctype={}&docname={}".format(
data.get("reference_doctype"), data.get("reference_docname")
)
else:
@@ -404,7 +403,7 @@ def create_recurring_profile(token, payerid):
).run_method("on_payment_authorized", status_changed_to)
frappe.db.commit()

redirect_url = "/integrations/payment-success?doctype={0}&docname={1}".format(
redirect_url = "/integrations/payment-success?doctype={}&docname={}".format(
data.get("reference_doctype"), data.get("reference_docname")
)
else:
@@ -427,11 +426,9 @@ def get_redirect_uri(doc, token, payerid):
data = json.loads(doc.data)

if data.get("subscription_details") or data.get("subscription_id"):
return get_url(
"{0}.create_recurring_profile?token={1}&payerid={2}".format(api_path, token, payerid)
)
return get_url(f"{api_path}.create_recurring_profile?token={token}&payerid={payerid}")
else:
return get_url("{0}.confirm_payment?token={1}".format(api_path, token))
return get_url(f"{api_path}.confirm_payment?token={token}")


def manage_recurring_payment_profile_status(profile_id, action, args, url):
@@ -474,7 +471,7 @@ def ipn_handler():
queue="long",
timeout=600,
is_async=True,
**{"doctype": "Integration Request", "docname": doc.name}
**{"doctype": "Integration Request", "docname": doc.name},
)

except frappe.InvalidStatusError:


+ 1
- 2
payments/payment_gateways/doctype/paytm_settings/paytm_settings.py 파일 보기

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2020, Frappe Technologies and contributors
# License: MIT. See LICENSE

@@ -37,7 +36,7 @@ class PaytmSettings(Document):
integration_request = create_request_log(kwargs, service_name="Paytm")
kwargs.update(dict(order_id=integration_request.name))

return get_url("./integrations/paytm_checkout?{0}".format(urlencode(kwargs)))
return get_url(f"./integrations/paytm_checkout?{urlencode(kwargs)}")


def get_paytm_config():


+ 0
- 1
payments/payment_gateways/doctype/paytm_settings/test_paytm_settings.py 파일 보기

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2020, Frappe Technologies and Contributors
# License: MIT. See LICENSE
# import frappe


+ 10
- 13
payments/payment_gateways/doctype/razorpay_settings/razorpay_settings.py 파일 보기

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2015, Frappe Technologies and contributors
# License: MIT. See LICENSE

@@ -124,9 +123,7 @@ class RazorpaySettings(Document):
"quantity": 1 (The total amount is calculated as item.amount * quantity)
}
"""
url = "https://api.razorpay.com/v1/subscriptions/{0}/addons".format(
kwargs.get("subscription_id")
)
url = "https://api.razorpay.com/v1/subscriptions/{}/addons".format(kwargs.get("subscription_id"))

try:
if not frappe.conf.converted_rupee_to_paisa:
@@ -195,7 +192,7 @@ class RazorpaySettings(Document):

def get_payment_url(self, **kwargs):
integration_request = create_request_log(kwargs, service_name="Razorpay")
return get_url("./integrations/razorpay_checkout?token={0}".format(integration_request.name))
return get_url(f"./integrations/razorpay_checkout?token={integration_request.name}")

def create_order(self, **kwargs):
# Creating Orders https://razorpay.com/docs/api/orders/
@@ -257,7 +254,7 @@ class RazorpaySettings(Document):

try:
resp = make_get_request(
"https://api.razorpay.com/v1/payments/{0}".format(self.data.razorpay_payment_id),
f"https://api.razorpay.com/v1/payments/{self.data.razorpay_payment_id}",
auth=(settings.api_key, settings.api_secret),
)

@@ -303,7 +300,7 @@ class RazorpaySettings(Document):
if custom_redirect_to:
redirect_to = custom_redirect_to

redirect_url = "payment-success?doctype={0}&docname={1}".format(
redirect_url = "payment-success?doctype={}&docname={}".format(
self.data.reference_doctype, self.data.reference_docname
)
else:
@@ -339,7 +336,7 @@ class RazorpaySettings(Document):

try:
resp = make_post_request(
"https://api.razorpay.com/v1/subscriptions/{0}/cancel".format(subscription_id),
f"https://api.razorpay.com/v1/subscriptions/{subscription_id}/cancel",
auth=(settings.api_key, settings.api_secret),
)
except Exception:
@@ -383,14 +380,14 @@ def capture_payment(is_sandbox=False, sanbox_response=None):
settings = controller.get_settings(data)

resp = make_get_request(
"https://api.razorpay.com/v1/payments/{0}".format(data.get("razorpay_payment_id")),
"https://api.razorpay.com/v1/payments/{}".format(data.get("razorpay_payment_id")),
auth=(settings.api_key, settings.api_secret),
data={"amount": data.get("amount")},
)

if resp.get("status") == "authorized":
resp = make_post_request(
"https://api.razorpay.com/v1/payments/{0}/capture".format(data.get("razorpay_payment_id")),
"https://api.razorpay.com/v1/payments/{}/capture".format(data.get("razorpay_payment_id")),
auth=(settings.api_key, settings.api_secret),
data={"amount": data.get("amount")},
)
@@ -403,7 +400,7 @@ def capture_payment(is_sandbox=False, sanbox_response=None):
doc.status = "Failed"
doc.error = frappe.get_traceback()
doc.save()
frappe.log_error(doc.error, "{0} Failed".format(doc.name))
frappe.log_error(doc.error, f"{doc.name} Failed")


@frappe.whitelist(allow_guest=True)
@@ -498,7 +495,7 @@ def razorpay_subscription_callback():
queue="long",
timeout=600,
is_async=True,
**{"doctype": "Integration Request", "docname": doc.name}
**{"doctype": "Integration Request", "docname": doc.name},
)

except frappe.InvalidStatusError:
@@ -521,7 +518,7 @@ def validate_payment_callback(data):
settings = controller.get_settings(data)

resp = make_get_request(
"https://api.razorpay.com/v1/subscriptions/{0}".format(subscription_id),
f"https://api.razorpay.com/v1/subscriptions/{subscription_id}",
auth=(settings.api_key, settings.api_secret),
)



+ 2
- 3
payments/payment_gateways/doctype/stripe_settings/stripe_settings.py 파일 보기

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2017, Frappe Technologies and contributors
# License: MIT. See LICENSE

@@ -163,7 +162,7 @@ class StripeSettings(Document):
def validate_stripe_credentails(self):
if self.publishable_key and self.secret_key:
header = {
"Authorization": "Bearer {0}".format(
"Authorization": "Bearer {}".format(
self.get_password(fieldname="secret_key", raise_exception=False)
)
}
@@ -190,7 +189,7 @@ class StripeSettings(Document):
)

def get_payment_url(self, **kwargs):
return get_url("./integrations/stripe_checkout?{0}".format(urlencode(kwargs)))
return get_url(f"./integrations/stripe_checkout?{urlencode(kwargs)}")

def create_request(self, data):
import stripe


+ 0
- 1
payments/payment_gateways/doctype/stripe_settings/test_stripe_settings.py 파일 보기

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2018, Frappe Technologies and Contributors
# License: MIT. See LICENSE
import unittest


+ 0
- 1
payments/payments/doctype/payment_gateway/payment_gateway.py 파일 보기

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and contributors
# License: MIT. See LICENSE



+ 0
- 1
payments/payments/doctype/payment_gateway/test_payment_gateway.py 파일 보기

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: MIT. See LICENSE
import unittest


불러오는 중...
취소
저장