Revert "perf: defer many requests imports"
This reverts commit 71b44efcac.
This gets frequently imported from one place or another. Since with
gc.freeze we can mostly reuse the import from parent, let's just leave
it here.
This commit is contained in:
parent
cc43af984e
commit
32bd5d3e2c
5 changed files with 13 additions and 22 deletions
|
|
@ -7,6 +7,8 @@ from typing import TYPE_CHECKING, Optional
|
|||
from urllib.parse import unquote
|
||||
|
||||
import filetype
|
||||
import requests
|
||||
import requests.exceptions
|
||||
from PIL import Image
|
||||
|
||||
import frappe
|
||||
|
|
@ -114,9 +116,6 @@ def get_local_image(file_url: str) -> tuple["ImageFile", str, str]:
|
|||
|
||||
|
||||
def get_web_image(file_url: str) -> tuple["ImageFile", str, str]:
|
||||
import requests
|
||||
import requests.exceptions
|
||||
|
||||
# download
|
||||
file_url = frappe.utils.get_url(file_url)
|
||||
r = requests.get(file_url, stream=True)
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
import json
|
||||
|
||||
import requests
|
||||
|
||||
import frappe
|
||||
from frappe import _
|
||||
from frappe.model.document import Document
|
||||
|
|
@ -22,8 +24,6 @@ class SlackWebhookURL(Document):
|
|||
|
||||
|
||||
def send_slack_message(webhook_url, message, reference_doctype, reference_name):
|
||||
import requests
|
||||
|
||||
data = {"text": message, "attachments": []}
|
||||
|
||||
slack_url, show_link = frappe.db.get_value(
|
||||
|
|
|
|||
|
|
@ -5,10 +5,11 @@ import base64
|
|||
import hashlib
|
||||
import hmac
|
||||
import json
|
||||
import typing
|
||||
from time import sleep
|
||||
from urllib.parse import urlparse
|
||||
|
||||
import requests
|
||||
|
||||
import frappe
|
||||
from frappe import _
|
||||
from frappe.model.document import Document
|
||||
|
|
@ -17,9 +18,6 @@ from frappe.utils.safe_exec import get_safe_globals
|
|||
|
||||
WEBHOOK_SECRET_HEADER = "X-Frappe-Webhook-Signature"
|
||||
|
||||
if typing.TYPE_CHECKING:
|
||||
import requests
|
||||
|
||||
|
||||
class Webhook(Document):
|
||||
def validate(self):
|
||||
|
|
@ -114,8 +112,6 @@ def get_context(doc):
|
|||
|
||||
|
||||
def enqueue_webhook(doc, webhook) -> None:
|
||||
import requests
|
||||
|
||||
webhook: Webhook = frappe.get_doc("Webhook", webhook.get("name"))
|
||||
headers = get_webhook_headers(doc, webhook)
|
||||
data = get_webhook_data(doc, webhook)
|
||||
|
|
@ -158,7 +154,7 @@ def log_request(
|
|||
url: str,
|
||||
headers: dict,
|
||||
data: dict,
|
||||
res: typing.Optional["requests.Response"] = None,
|
||||
res: requests.Response | None = None,
|
||||
):
|
||||
request_log = frappe.get_doc(
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import json
|
|||
|
||||
from google.oauth2.credentials import Credentials
|
||||
from googleapiclient.discovery import build
|
||||
from requests import get, post
|
||||
|
||||
import frappe
|
||||
from frappe.utils import get_request_site_address
|
||||
|
|
@ -55,8 +56,6 @@ class GoogleOAuth:
|
|||
frappe.throw(frappe._("Please update {} before continuing.").format(google_settings))
|
||||
|
||||
def authorize(self, oauth_code: str) -> dict[str, str | int]:
|
||||
import requests
|
||||
|
||||
"""Returns a dict with access and refresh token.
|
||||
|
||||
:param oauth_code: code got back from google upon successful auhtorization
|
||||
|
|
@ -74,14 +73,13 @@ class GoogleOAuth:
|
|||
}
|
||||
|
||||
return handle_response(
|
||||
requests.post(self.OAUTH_URL, data=data).json(),
|
||||
post(self.OAUTH_URL, data=data).json(),
|
||||
"Google Oauth Authorization Error",
|
||||
"Something went wrong during the authorization.",
|
||||
)
|
||||
|
||||
def refresh_access_token(self, refresh_token: str) -> dict[str, str | int]:
|
||||
"""Refreshes google access token using refresh token"""
|
||||
import requests
|
||||
|
||||
data = {
|
||||
"client_id": self.google_settings.client_id,
|
||||
|
|
@ -94,7 +92,7 @@ class GoogleOAuth:
|
|||
}
|
||||
|
||||
return handle_response(
|
||||
requests.post(self.OAUTH_URL, data=data).json(),
|
||||
post(self.OAUTH_URL, data=data).json(),
|
||||
"Google Oauth Access Token Refresh Error",
|
||||
"Something went wrong during the access token generation.",
|
||||
raise_err=True,
|
||||
|
|
@ -160,9 +158,7 @@ def handle_response(
|
|||
|
||||
|
||||
def is_valid_access_token(access_token: str) -> bool:
|
||||
import requests
|
||||
|
||||
response = requests.get(
|
||||
response = get(
|
||||
"https://oauth2.googleapis.com/tokeninfo", params={"access_token": access_token}
|
||||
).json()
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ import csv
|
|||
import json
|
||||
from io import StringIO
|
||||
|
||||
import requests
|
||||
|
||||
import frappe
|
||||
from frappe import _, msgprint
|
||||
from frappe.utils import cint, comma_or, cstr, flt
|
||||
|
|
@ -176,8 +178,6 @@ def getlink(doctype, name):
|
|||
|
||||
|
||||
def get_csv_content_from_google_sheets(url):
|
||||
import requests
|
||||
|
||||
# https://docs.google.com/spreadsheets/d/{sheetid}}/edit#gid={gid}
|
||||
validate_google_sheets_url(url)
|
||||
# get gid, defaults to first sheet
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue