From ccebe56f016e0fb8787bbef2d7c1b42c1be02abd Mon Sep 17 00:00:00 2001 From: Evgeniy Kirov Date: Fri, 2 Feb 2024 10:00:34 +0100 Subject: [PATCH 1/3] Fix integration tests --- tests/integration/test_api_resources.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/tests/integration/test_api_resources.py b/tests/integration/test_api_resources.py index b191e3ee..73923fb8 100644 --- a/tests/integration/test_api_resources.py +++ b/tests/integration/test_api_resources.py @@ -22,9 +22,8 @@ # increase throttle retries for Travis CI conf.retry_throttled = 10 -IMAGE_URL = ( - "https://github.githubassets.com/images/modules/logos_page/Octocat.png" -) +IMAGE_URL = "https://octodex.github.com/images/original.png" +IMAGE_FILENAME = "original.png" ASSETS_PATH = Path(__file__).parent / "assets" IMAGE_PATH = ASSETS_PATH / "img.png" @@ -106,7 +105,7 @@ def test_successful_upload_from_url(uploadcare): def test_successful_upload_from_url_sync_autostore(uploadcare): file = uploadcare.upload_from_url_sync(IMAGE_URL, interval=1) assert isinstance(file, File) - assert file.filename == "Octocat.png" + assert file.filename == IMAGE_FILENAME assert file.datetime_stored is not None assert isinstance(file.datetime_stored, datetime) @@ -114,7 +113,7 @@ def test_successful_upload_from_url_sync_autostore(uploadcare): def test_successful_upload_by_url(uploadcare): file = uploadcare.upload(IMAGE_URL) assert isinstance(file, File) - assert file.filename == "Octocat.png" + assert file.filename == IMAGE_FILENAME def test_successful_upload_from_url_signed(uploadcare): @@ -148,7 +147,7 @@ def test_successful_upload_from_url_check_duplicates(uploadcare): def test_successful_upload_from_url_sync_autostore_signed(uploadcare): file = uploadcare.upload_from_url_sync(IMAGE_URL, interval=1) assert isinstance(file, File) - assert file.filename == "Octocat.png" + assert file.filename == IMAGE_FILENAME assert file.datetime_stored is not None assert isinstance(file.datetime_stored, datetime) @@ -156,7 +155,7 @@ def test_successful_upload_from_url_sync_autostore_signed(uploadcare): def test_successful_upload_from_url_sync_dont_store(uploadcare): file = uploadcare.upload_from_url_sync(IMAGE_URL, store=False, interval=1) assert isinstance(file, File) - assert file.filename == "Octocat.png" + assert file.filename == IMAGE_FILENAME assert file.datetime_stored is None From 877fe1c971f31f8c394a6385f9ed393154f0b6e5 Mon Sep 17 00:00:00 2001 From: Evgeniy Kirov Date: Fri, 2 Feb 2024 10:02:04 +0100 Subject: [PATCH 2/3] 2023 -> 2024 --- LICENSE | 2 +- docs/conf.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/LICENSE b/LICENSE index c12bad7b..4867020d 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2023 Uploadcare, Inc +Copyright (c) 2024 Uploadcare, Inc Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/docs/conf.py b/docs/conf.py index 59be96cf..f5388e00 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -48,7 +48,7 @@ # General information about the project. project = "PyUploadcare" -copyright = "2011-2023, Uploadcare Inc" +copyright = "2011-2024, Uploadcare Inc" # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the From a6bfe1d8fbae0b894111bfb2d7b5424192a29118 Mon Sep 17 00:00:00 2001 From: Evgeniy Kirov Date: Thu, 1 Feb 2024 12:54:19 +0100 Subject: [PATCH 3/3] #279 Cache SSL context in client.py --- HISTORY.md | 6 ++++++ pyuploadcare/client.py | 16 ++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index abfa1fc0..ae2461fa 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [5.0.1](https://github.com/uploadcare/pyuploadcare/compare/v5.0.0...v5.0.1) - unreleased + +### Fixed + +- The SSL context is now cached by default, resulting in significant performance improvements when initializing the `Uploadcare` class frequently. [#279](https://github.com/uploadcare/pyuploadcare/issues/279) + ## [5.0.0](https://github.com/uploadcare/pyuploadcare/compare/v4.3.0...v5.0.0) - 2023-12-28 In version 5.0, we introduce a new [file uploader](https://uploadcare.com/docs/file-uploader/), which is now the default for Django projects. If you prefer to continue using the old jQuery-based widget, you can enable it by setting the `use_legacy_widget` option in your configuration: diff --git a/pyuploadcare/client.py b/pyuploadcare/client.py index b8fd4751..a9e3e350 100644 --- a/pyuploadcare/client.py +++ b/pyuploadcare/client.py @@ -1,5 +1,6 @@ import os import socket +import ssl from time import time from typing import ( IO, @@ -41,6 +42,9 @@ from pyuploadcare.secure_url import BaseSecureUrlBuilder +DEFAULT_SSL_CONTEXT = ssl.create_default_context() + + class Uploadcare: """Uploadcare client. @@ -122,7 +126,11 @@ def __init__( self.rest_client = Client( base_url=api_base, auth=auth, - verify=verify_api_ssl, + verify=( + DEFAULT_SSL_CONTEXT + if verify_api_ssl is True + else verify_api_ssl + ), timeout=timeout, user_agent_extension=user_agent_extension, retry_throttled=retry_throttled, @@ -131,7 +139,11 @@ def __init__( self.upload_client = Client( base_url=upload_base, - verify=verify_upload_ssl, + verify=( + DEFAULT_SSL_CONTEXT + if verify_upload_ssl is True + else verify_upload_ssl + ), timeout=timeout, user_agent_extension=user_agent_extension, retry_throttled=retry_throttled,