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

Commit c013305

Browse files
committed
Refactor imports
Improved compatibility, robustness, clear errors and some cleaning up. Also synced with the readme.
1 parent b4465b9 commit c013305

File tree

10 files changed

+32
-33
lines changed

10 files changed

+32
-33
lines changed

CloudFlare/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
""" Cloudflare v4 API"""
2-
3-
try:
4-
from cloudflare import CloudFlare
5-
except:
6-
pass
2+
from __future__ import absolute_import
73

84
__version__ = '1.4.11'
5+
6+
from .cloudflare import CloudFlare
7+
8+
__all__ = ['CloudFlare']

CloudFlare/cloudflare.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
""" Cloudflare v4 API"""
2+
from __future__ import absolute_import
23

34
import json
4-
import urllib
55
import requests
66

7-
from logger import Logger
8-
from utils import user_agent, sanitize_secrets
9-
from read_configs import read_configs
10-
from api_v4 import api_v4
11-
from api_extras import api_extras
12-
from exceptions import CloudFlareError, CloudFlareAPIError, CloudFlareInternalError
7+
from .logger import Logger
8+
from .utils import user_agent, sanitize_secrets
9+
from .read_configs import read_configs
10+
from .api_v4 import api_v4
11+
from .api_extras import api_extras
12+
from .exceptions import CloudFlareError, CloudFlareAPIError, CloudFlareInternalError
1313

1414
BASE_URL = 'https://api.cloudflare.com/client/v4'
1515

CloudFlare/read_configs.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
import os
44
import re
5-
import ConfigParser
5+
try:
6+
import ConfigParser # py2
7+
except ImportError:
8+
import configparser as ConfigParser # py3
69

710
def read_configs():
811
""" reading the config file for Cloudflare API"""

CloudFlare/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
""" misc utilities for Cloudflare API"""
2+
from __future__ import absolute_import
23

34
import sys
45
import requests
5-
from __init__ import __version__
6+
7+
from . import __version__
68

79
def user_agent():
810
""" misc utilities for Cloudflare API"""

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,6 @@ The exception returns both an integer and textual message in one value.
298298

299299
```python
300300
import CloudFlare
301-
import CloudFlare.exceptions
302301

303302
...
304303
try
@@ -316,7 +315,6 @@ You can itterate over that array to see the additional error.
316315
```python
317316
import sys
318317
import CloudFlare
319-
import CloudFlare.exceptions
320318

321319
...
322320
try

README.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ A more complex example follows.
140140
.. code:: python
141141
142142
import CloudFlare
143-
import CloudFlare.exceptions
144143
145144
def main():
146145
zone_name = 'example.com'
@@ -336,7 +335,6 @@ The exception returns both an integer and textual message in one value.
336335
.. code:: python
337336
338337
import CloudFlare
339-
import CloudFlare.exceptions
340338
341339
...
342340
try
@@ -356,7 +354,6 @@ the additional error.
356354
357355
import sys
358356
import CloudFlare
359-
import CloudFlare.exceptions
360357
361358
...
362359
try

cli4/__main__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#!/usr/bin/env python
22
"""Cloudflare API via command line"""
3+
from __future__ import absolute_import
34

45
import sys
56

6-
from cli4 import cli4
7+
from .cli4 import cli4
78

89
def main(args=None):
910
"""Cloudflare API via command line"""

cli4/cli4.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/usr/bin/env python
22
"""Cloudflare API via command line"""
33

4-
import os
54
import sys
65
import re
76
import getopt
@@ -11,11 +10,9 @@
1110
except ImportError:
1211
yaml = None
1312

14-
import converters
13+
from . import converters
1514

16-
sys.path.insert(0, os.path.abspath('..'))
1715
import CloudFlare
18-
import CloudFlare.exceptions
1916

2017
def dump_commands(cf):
2118
"""dump a tree of all the known API commands"""

cli4/converters.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
#!/usr/bin/env python
21
"""Cloudflare API via command line"""
2+
from __future__ import absolute_import
33

4-
import os
5-
import sys
6-
7-
sys.path.insert(0, os.path.abspath('..'))
84
import CloudFlare
9-
import CloudFlare.exceptions
105

116
def convert_zones_to_identifier(cf, zone_name):
127
"""zone names to numbers"""

setup.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
#!/usr/bin/env python
22
"""Cloudflare API code - setup.py file"""
3-
3+
import re
44
from setuptools import setup, find_packages
5-
from CloudFlare import __version__
5+
6+
_version_re = re.compile(r"__version__\s=\s'(.*)'")
7+
68

79
def main():
810
"""Cloudflare API code - setup.py file"""
911

1012
with open('README.rst') as read_me:
1113
long_description = read_me.read()
1214

15+
with open('CloudFlare/__init__.py', 'r') as f:
16+
version = _version_re.search(f.read()).group(1)
17+
1318
setup(
1419
name='cloudflare',
15-
version=__version__,
20+
version=version,
1621
description='Python wrapper for the Cloudflare v4 API',
1722
long_description=long_description,
1823
author='Martin J. Levy',
@@ -51,5 +56,6 @@ def main():
5156
]
5257
)
5358

59+
5460
if __name__ == '__main__':
5561
main()

0 commit comments

Comments
 (0)