|
3 | 3 |
|
4 | 4 | import json |
5 | 5 | import requests |
| 6 | +import keyword |
6 | 7 |
|
7 | 8 | from .network import CFnetwork |
8 | 9 | from .logging_helper import CFlogger |
@@ -48,6 +49,15 @@ def __init__(self, config): |
48 | 49 | self.network = CFnetwork(use_sessions=self.use_sessions) |
49 | 50 | self.user_agent = user_agent() |
50 | 51 |
|
| 52 | + if not isinstance(self.email, str): |
| 53 | + raise ValueError('email argument not string') |
| 54 | + if not isinstance(self.token, str): |
| 55 | + raise ValueError('token argument not string') |
| 56 | + if not isinstance(self.certtoken, str): |
| 57 | + raise ValueError('certtoken argument not string') |
| 58 | + if not isinstance(self.base_url, str): |
| 59 | + raise ValueError('base url argument not string') |
| 60 | + |
51 | 61 | if 'debug' in config and config['debug']: |
52 | 62 | self.logger = CFlogger(config['debug']).getLogger() |
53 | 63 | else: |
@@ -201,10 +211,22 @@ def _call_network(self, method, headers, parts, |
201 | 211 |
|
202 | 212 | try: |
203 | 213 | response = self.network(method, url, headers, params, data, files) |
| 214 | + except requests.RequestException as e: |
| 215 | + if self.logger: |
| 216 | + self.logger.debug('Call: requests exception! "%s"' % (e)) |
| 217 | + raise CloudFlareAPIError(0, e) |
| 218 | + except requests.ConnectionError as e: |
| 219 | + if self.logger: |
| 220 | + self.logger.debug('Call: requests connection exception! "%s"' % (e)) |
| 221 | + raise CloudFlareAPIError(0, 'connection error') |
| 222 | + except requests.exceptions.Timeout as e: |
| 223 | + if self.logger: |
| 224 | + self.logger.debug('Call: requests timeout exception! "%s"' % (e)) |
| 225 | + raise CloudFlareAPIError(0, 'connection timeout') |
204 | 226 | except Exception as e: |
205 | 227 | if self.logger: |
206 | 228 | self.logger.debug('Call: exception! "%s"' % (e)) |
207 | | - raise CloudFlareAPIError(0, 'connection failed.') |
| 229 | + raise |
208 | 230 |
|
209 | 231 | # Create response_{type|code|data} |
210 | 232 | try: |
@@ -859,6 +881,9 @@ def add(self, t, p1, p2=None, p3=None): |
859 | 881 | # should never happen |
860 | 882 | raise CloudFlareAPIError(0, 'api load type mismatch') |
861 | 883 |
|
| 884 | + if keyword.iskeyword(name): |
| 885 | + ## add an extra keywork prefix'ed with underscore so it can used with Python code |
| 886 | + setattr(branch, name + '_', f) |
862 | 887 | if '-' in name: |
863 | 888 | # dashes (vs underscores) cause issues in Python and other languages |
864 | 889 | setattr(branch, name.replace('-','_'), f) |
|
0 commit comments