Skip to content

Commit

Permalink
Refactor imports
Browse files Browse the repository at this point in the history
Improved compatibility, robustness, clear errors and some cleaning up.
Also synced with the readme.
  • Loading branch information
yesbox committed Dec 30, 2016
1 parent b4465b9 commit c013305
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 33 deletions.
10 changes: 5 additions & 5 deletions CloudFlare/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
""" Cloudflare v4 API"""

try:
from cloudflare import CloudFlare
except:
pass
from __future__ import absolute_import

__version__ = '1.4.11'

from .cloudflare import CloudFlare

__all__ = ['CloudFlare']
14 changes: 7 additions & 7 deletions CloudFlare/cloudflare.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
""" Cloudflare v4 API"""
from __future__ import absolute_import

import json
import urllib
import requests

from logger import Logger
from utils import user_agent, sanitize_secrets
from read_configs import read_configs
from api_v4 import api_v4
from api_extras import api_extras
from exceptions import CloudFlareError, CloudFlareAPIError, CloudFlareInternalError
from .logger import Logger
from .utils import user_agent, sanitize_secrets
from .read_configs import read_configs
from .api_v4 import api_v4
from .api_extras import api_extras
from .exceptions import CloudFlareError, CloudFlareAPIError, CloudFlareInternalError

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

Expand Down
5 changes: 4 additions & 1 deletion CloudFlare/read_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import os
import re
import ConfigParser
try:
import ConfigParser # py2
except ImportError:
import configparser as ConfigParser # py3

def read_configs():
""" reading the config file for Cloudflare API"""
Expand Down
4 changes: 3 additions & 1 deletion CloudFlare/utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
""" misc utilities for Cloudflare API"""
from __future__ import absolute_import

import sys
import requests
from __init__ import __version__

from . import __version__

def user_agent():
""" misc utilities for Cloudflare API"""
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,6 @@ The exception returns both an integer and textual message in one value.

```python
import CloudFlare
import CloudFlare.exceptions

...
try
Expand All @@ -316,7 +315,6 @@ You can itterate over that array to see the additional error.
```python
import sys
import CloudFlare
import CloudFlare.exceptions

...
try
Expand Down
3 changes: 0 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ A more complex example follows.
.. code:: python
import CloudFlare
import CloudFlare.exceptions
def main():
zone_name = 'example.com'
Expand Down Expand Up @@ -336,7 +335,6 @@ The exception returns both an integer and textual message in one value.
.. code:: python
import CloudFlare
import CloudFlare.exceptions
...
try
Expand All @@ -356,7 +354,6 @@ the additional error.
import sys
import CloudFlare
import CloudFlare.exceptions
...
try
Expand Down
3 changes: 2 additions & 1 deletion cli4/__main__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/usr/bin/env python
"""Cloudflare API via command line"""
from __future__ import absolute_import

import sys

from cli4 import cli4
from .cli4 import cli4

def main(args=None):
"""Cloudflare API via command line"""
Expand Down
5 changes: 1 addition & 4 deletions cli4/cli4.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python
"""Cloudflare API via command line"""

import os
import sys
import re
import getopt
Expand All @@ -11,11 +10,9 @@
except ImportError:
yaml = None

import converters
from . import converters

sys.path.insert(0, os.path.abspath('..'))
import CloudFlare
import CloudFlare.exceptions

def dump_commands(cf):
"""dump a tree of all the known API commands"""
Expand Down
7 changes: 1 addition & 6 deletions cli4/converters.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
#!/usr/bin/env python
"""Cloudflare API via command line"""
from __future__ import absolute_import

import os
import sys

sys.path.insert(0, os.path.abspath('..'))
import CloudFlare
import CloudFlare.exceptions

def convert_zones_to_identifier(cf, zone_name):
"""zone names to numbers"""
Expand Down
12 changes: 9 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
#!/usr/bin/env python
"""Cloudflare API code - setup.py file"""

import re
from setuptools import setup, find_packages
from CloudFlare import __version__

_version_re = re.compile(r"__version__\s=\s'(.*)'")


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

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

with open('CloudFlare/__init__.py', 'r') as f:
version = _version_re.search(f.read()).group(1)

setup(
name='cloudflare',
version=__version__,
version=version,
description='Python wrapper for the Cloudflare v4 API',
long_description=long_description,
author='Martin J. Levy',
Expand Down Expand Up @@ -51,5 +56,6 @@ def main():
]
)


if __name__ == '__main__':
main()

0 comments on commit c013305

Please sign in to comment.