Skip to content

Commit 51b9e84

Browse files
committed
Move imports before exports
1 parent 285fe5c commit 51b9e84

3 files changed

Lines changed: 44 additions & 50 deletions

File tree

iptools/__init__.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,6 @@
2222
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2323
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2424
# POSSIBILITY OF SUCH DAMAGE.
25-
__version__ = '0.7.0-dev'
26-
27-
__all__ = (
28-
'IpRange',
29-
'IpRangeList',
30-
)
31-
3225

3326
# sniff for python2.x / python3k compatibility "fixes'
3427
try:
@@ -51,10 +44,16 @@ def next(iterable):
5144
Sequence = object
5245
# end compatibility "fixes'
5346

54-
5547
from . import ipv4
5648
from . import ipv6
5749

50+
__version__ = '0.7.0-dev'
51+
52+
__all__ = (
53+
'IpRange',
54+
'IpRangeList',
55+
)
56+
5857

5958
def _address2long(address):
6059
"""

iptools/ipv4.py

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,40 @@
2323
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2424
# POSSIBILITY OF SUCH DAMAGE.
2525

26+
import re
27+
28+
# sniff for python2.x / python3k compatibility "fixes'
29+
try:
30+
basestring = basestring
31+
except NameError:
32+
# 'basestring' is undefined, must be python3k
33+
basestring = str
34+
35+
try:
36+
bin = bin
37+
except NameError:
38+
# builtin bin function doesn't exist
39+
def bin(x):
40+
"""
41+
From http://code.activestate.com/recipes/219300/#c7
42+
"""
43+
if x < 0:
44+
return '-' + bin(-x)
45+
out = []
46+
if x == 0:
47+
out.append('0')
48+
while x > 0:
49+
out.append('01'[x & 1])
50+
x >>= 1
51+
pass
52+
try:
53+
return '0b' + ''.join(reversed(out))
54+
except NameError:
55+
out.reverse()
56+
return '0b' + ''.join(out)
57+
# end bin
58+
# end compatibility "fixes'
59+
2660
__all__ = (
2761
'cidr2block',
2862
'hex2ip',
@@ -60,43 +94,6 @@
6094
'TEST_NET_3',
6195
)
6296

63-
64-
import re
65-
66-
67-
# sniff for python2.x / python3k compatibility "fixes'
68-
try:
69-
basestring = basestring
70-
except NameError:
71-
# 'basestring' is undefined, must be python3k
72-
basestring = str
73-
74-
try:
75-
bin = bin
76-
except NameError:
77-
# builtin bin function doesn't exist
78-
def bin(x):
79-
"""
80-
From http://code.activestate.com/recipes/219300/#c7
81-
"""
82-
if x < 0:
83-
return '-' + bin(-x)
84-
out = []
85-
if x == 0:
86-
out.append('0')
87-
while x > 0:
88-
out.append('01'[x & 1])
89-
x >>= 1
90-
pass
91-
try:
92-
return '0b' + ''.join(reversed(out))
93-
except NameError:
94-
out.reverse()
95-
return '0b' + ''.join(out)
96-
# end bin
97-
# end compatibility "fixes'
98-
99-
10097
#: Regex for validating an IPv4 address
10198
_DOTTED_QUAD_RE = re.compile(r'^(\d{1,3}\.){0,3}\d{1,3}$')
10299

iptools/ipv6.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2424
# POSSIBILITY OF SUCH DAMAGE.
2525

26+
import re
27+
from . import ipv4
28+
2629
__all__ = (
2730
'cidr2block',
2831
'ip2long',
@@ -52,11 +55,6 @@
5255
'UNSPECIFIED_ADDRESS',
5356
)
5457

55-
56-
import re
57-
from . import ipv4
58-
59-
6058
#: Regex for validating an IPv6 in hex notation
6159
_HEX_RE = re.compile(r'^([0-9a-f]{0,4}:){2,7}[0-9a-f]{0,4}$')
6260

0 commit comments

Comments
 (0)