From d6ae4eaed86bb8e3df4a68a91ccfdb2cd3ea032d Mon Sep 17 00:00:00 2001 From: Martin Levy Date: Wed, 27 Dec 2023 11:49:53 -0800 Subject: [PATCH] added Content-Type processing on add, removed old api web checking (hence remove bs4), refactoring of all add methods, network now handles data/json cleanly, results returned based on Content-Type via new code, setup/requirements removed BeautifulSoup/bs4 --- CloudFlare/api_decode_from_web.py | 202 +++++++------- CloudFlare/api_v4.py | 47 ++-- CloudFlare/cloudflare.py | 447 +++++++++++++----------------- CloudFlare/network.py | 109 +++----- CloudFlare/utils.py | 28 +- Makefile | 4 +- requirements.txt | 2 +- setup.py | 2 +- 8 files changed, 382 insertions(+), 459 deletions(-) diff --git a/CloudFlare/api_decode_from_web.py b/CloudFlare/api_decode_from_web.py index fd7bd84..a6fc6b0 100644 --- a/CloudFlare/api_decode_from_web.py +++ b/CloudFlare/api_decode_from_web.py @@ -1,103 +1,105 @@ """ API extras for Cloudflare API""" -import sys -import datetime +# TODO - remove at some point -API_TYPES = ['GET', 'POST', 'PATCH', 'PUT', 'DELETE'] - -class mybs4(): - """ mybs4 """ - - _BeautifulSoup = None - _Comment = None - - def __init__(self): - """ __init__ """ - pass - - def _available(self): - """ _available() """ - if not mybs4._BeautifulSoup: - try: - from bs4 import BeautifulSoup, Comment - mybs4._BeautifulSoup = BeautifulSoup - mybs4._Comment = Comment - self.Comment = mybs4._Comment - except ImportError: - return False - return True - - def BeautifulSoup(self, content, parser): - """ BeautifulSoup() """ - self._available() - return mybs4._BeautifulSoup(content, parser) - -my_bs4 = mybs4() - -def do_section(section): - """ API extras for Cloudflare API""" - - cmds = [] - # look for deprecated first in section - deprecated = False - deprecated_date = '' - deprecated_already = False - for tag2 in section.find_all('h3'): - #

Deprecation Warning

- if 'Deprecation Warning' in str(tag2): - deprecated = True - break - for tag2 in section.find_all('p'): - #

End of life Date: November 2, 2020

- if 'End of life Date:' in str(tag2): - for child in tag2.children: - deprecated_date = str(child).replace('End of life Date:','').strip() - try: - # clean up date - d = datetime.datetime.strptime(deprecated_date, '%B %d, %Y') - if d <= datetime.datetime.now(): - # already done! - deprecated_already = True - deprecated_date = d.strftime('%Y-%m-%d') - except ValueError: - # Lets not worry about all the date formats that could show-up. Leave as a string - pass - break - if deprecated_date != '': - break - # look for all API calls in section - for tag2 in section.find_all('pre'): - cmd = [] - for child in tag2.children: - if isinstance(child, my_bs4.Comment): - # remove