Skip to content
This repository was archived by the owner on Nov 22, 2024. It is now read-only.

Commit 676d258

Browse files
committed
2.20.* warning now in its own file and warning sent to stderr or logging only if release number 2.20 or above
1 parent 3181096 commit 676d258

2 files changed

Lines changed: 39 additions & 20 deletions

File tree

CloudFlare/cloudflare.py

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,14 @@
1818
from .api_extras import api_extras
1919
from .api_decode_from_openapi import api_decode_from_openapi
2020
from .exceptions import CloudFlareAPIError, CloudFlareInternalError
21+
from .warning_2_20 import warning_2_20, print_warning_2_20
2122

2223
BASE_URL = 'https://api.cloudflare.com/client/v4'
2324
OPENAPI_URL = 'https://github.com/cloudflare/api-schemas/raw/main/openapi.json'
2425

2526
DEFAULT_GLOBAL_REQUEST_TIMEOUT = 5
2627
DEFAULT_MAX_REQUEST_RETRIES = 5
2728

28-
MAJOR_VERSION_WARNING = """
29-
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
30-
!! !!
31-
!! You are seeing this warning because you have upgraded to a version that is !!
32-
!! not intended to be installed. !!
33-
!! !!
34-
!! This version only exists to catch any accidental upgrades before we !!
35-
!! release a major release. !!
36-
!! !!
37-
!! You should determine if you need to revert this upgrade and pin to v2.19.* !!
38-
!! or if you can upgrade to v3.x. !!
39-
!! !!
40-
!! To see more about upgrading to next major version, please see !!
41-
!! https://github.com/cloudflare/python-cloudflare/discussions/191 !!
42-
!! !!
43-
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
44-
"""
45-
4629
class CloudFlare():
4730
""" A Python interface Cloudflare's v4 API.
4831
@@ -68,7 +51,6 @@ class _v4base():
6851

6952
def __init__(self, config):
7053
""" :meta private: """
71-
print(MAJOR_VERSION_WARNING)
7254

7355
self.network = None
7456
self.config = config
@@ -107,6 +89,13 @@ def __init__(self, config):
10789

10890
self.logger = CFlogger(config['debug']).getLogger() if 'debug' in config and config['debug'] else None
10991

92+
warning = warning_2_20()
93+
if warning:
94+
if self.logger:
95+
self.logger.warning('\n' + warning)
96+
else:
97+
print_warning_2_20(warning)
98+
11099
def __del__(self):
111100
if self.network:
112101
del self.network
@@ -297,7 +286,6 @@ def do_certauth(self, method, parts, identifiers, params=None, data=None, files=
297286

298287
def _call_network(self, method, headers, parts, identifiers, params, data_str, data_json, files):
299288
""" Cloudflare v4 API"""
300-
print(MAJOR_VERSION_WARNING)
301289

302290
if (method is None) or (parts[0] is None):
303291
# should never happen

CloudFlare/warning_2_20.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
""" warning message if version is 2.20 or above (technically, there's no version above 2.20.0) """
2+
3+
import sys
4+
5+
from . import __version__
6+
7+
MAJOR_VERSION_WARNING = """\
8+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
9+
!! You're seeing this warning because you've upgraded the Python package 'cloudflare' to version !!
10+
!! 2.20.* via an automated upgrade without version pinning. Version 2.20.0 exists to catch any !!
11+
!! of these upgrades before Cloudflare releases a new major release under the release number 3.x. !!
12+
!! !!
13+
!! Should you determine that you need to revert this upgrade and pin to v2.19.* it is recommended !!
14+
!! you do the following: pip install --upgrade cloudflare==2.19.* or equivilant. !!
15+
!! !!
16+
!! Or you can upgrade to v3.x. NOTE: Release 3.x will not be code-compatible or call-compatible !!
17+
!! with previous releases. To see more about upgrading to next major version, please see: !!
18+
!! https://github.com/cloudflare/python-cloudflare/discussions/191 !!
19+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\
20+
"""
21+
22+
def warning_2_20():
23+
""" warning_2_20 """
24+
25+
if __version__ < '2.20.0':
26+
return None
27+
return MAJOR_VERSION_WARNING
28+
29+
def print_warning_2_20(warning):
30+
""" print_warning_2_20 """
31+
print(warning, file=sys.stderr)

0 commit comments

Comments
 (0)