diff --git a/MANIFEST.in b/MANIFEST.in index 6d1198817..b4bfa7b81 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,2 +1,4 @@ +global-exclude *.class *.pyc *.pyo *.so *.dll __pycache__ recursive-include neo4j *.c -recursive-exclude test * +recursive-include neo4j *.pyx +prune test diff --git a/neo4j/addressing.py b/neo4j/addressing.py index c70b2d85f..8dca01e17 100644 --- a/neo4j/addressing.py +++ b/neo4j/addressing.py @@ -20,13 +20,34 @@ from collections import namedtuple -from socket import getaddrinfo, gaierror, error as SocketError, \ - SOCK_STREAM, IPPROTO_TCP, AF_INET6, inet_aton, inet_pton +from socket import getaddrinfo, gaierror, SOCK_STREAM, IPPROTO_TCP from neo4j.compat import urlparse from neo4j.exceptions import AddressError +VALID_IPv4_SEGMENTS = [str(i).encode("latin1") for i in range(0x100)] +VALID_IPv6_SEGMENT_CHARS = b"0123456789abcdef" + + +def is_ipv4_address(string): + if not isinstance(string, bytes): + string = str(string).encode("latin1") + segments = string.split(b".") + return len(segments) == 4 and all(segment in VALID_IPv4_SEGMENTS for segment in segments) + + +def is_ipv6_address(string): + if not isinstance(string, bytes): + string = str(string).encode("latin1") + segments = string.lower().split(b":") + return 3 <= len(segments) <= 8 and all(all(c in VALID_IPv6_SEGMENT_CHARS for c in segment) for segment in segments) + + +def is_ip_address(string): + return is_ipv4_address(string) or is_ipv6_address(string) + + IPv4SocketAddress = namedtuple("Address", ["host", "port"]) IPv6SocketAddress = namedtuple("Address", ["host", "port", "flow_info", "scope_id"]) @@ -65,25 +86,3 @@ def resolve(socket_address): getaddrinfo(socket_address[0], socket_address[1], 0, SOCK_STREAM, IPPROTO_TCP)] except gaierror: raise AddressError("Cannot resolve address {!r}".format(socket_address[0])) - - -def is_ipv4_address(string): - try: - inet_aton(string) - except (OSError, SocketError): - return False - else: - return True - - -def is_ipv6_address(string): - try: - inet_pton(AF_INET6, string) - except (OSError, SocketError): - return False - else: - return True - - -def is_ip_address(string): - return is_ipv4_address(string) or is_ipv6_address(string) diff --git a/neo4j/meta.py b/neo4j/meta.py index 9ed76aa83..3086cb71b 100644 --- a/neo4j/meta.py +++ b/neo4j/meta.py @@ -19,4 +19,4 @@ # limitations under the License. -version = "1.2.0rc1" +version = "1.2.0rc2" diff --git a/setup.py b/setup.py index 171bdc31f..641ff9c3f 100644 --- a/setup.py +++ b/setup.py @@ -18,7 +18,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os + +from __future__ import print_function + +from os.path import dirname, join as path_join try: from setuptools import setup, Extension except ImportError: @@ -30,41 +33,54 @@ from Cython.Build import cythonize from Cython.Distutils import build_ext except ImportError: - cmdclass = {} ext_modules = [ Extension("neo4j.bolt._io", ["neo4j/bolt/_io.c"]), Extension("neo4j.packstream._packer", ["neo4j/packstream/_packer.c"]), Extension("neo4j.packstream._unpacker", ["neo4j/packstream/_unpacker.c"]), ] else: - cmdclass = {'build_ext': build_ext} ext_modules = cythonize([Extension("*", ["**/*.pyx"])]) +classifiers = [ + "Intended Audience :: Developers", + "License :: OSI Approved :: Apache Software License", + "Operating System :: OS Independent", + "Topic :: Database", + "Topic :: Software Development", + "Programming Language :: Python :: 2.7", + "Programming Language :: Python :: 3.4", + "Programming Language :: Python :: 3.5", + "Programming Language :: Python :: 3.6", +] +packages = [ + "neo4j", + "neo4j.bolt", + "neo4j.compat", + "neo4j.packstream", + "neo4j.v1", +] +package_data = { + "neo4j.bolt": ["*.pyx"], + "neo4j.packstream": ["*.pyx"], +} +setup_args = { + "name": "neo4j-driver", + "version": version, + "description": "Neo4j Bolt driver for Python", + "license": "Apache License, Version 2.0", + "long_description": open(path_join(dirname(__file__), "README.rst")).read(), + "author": "Neo Technology", + "author_email": "drivers@neo4j.com", + "keywords": "neo4j graph database", + "url": "https://github.com/neo4j/neo4j-python-driver", + "classifiers": classifiers, + "packages": packages, + "ext_modules": ext_modules, +} -# Used for reading the README into long_description below. -def read(fname): - return open(os.path.join(os.path.dirname(__file__), fname)).read() - - -setup(name="neo4j-driver", - version=version, - description="Neo4j Bolt driver for Python", - license="Apache License, Version 2.0", - long_description=read("README.rst"), - author="Neo Technology", - author_email="drivers@neo4j.com", - keywords="neo4j graph database", - url="https://github.com/neo4j/neo4j-python-driver", - classifiers=[ - "Intended Audience :: Developers", - "License :: OSI Approved :: Apache Software License", - "Operating System :: OS Independent", - "Topic :: Database", - "Topic :: Software Development", - "Programming Language :: Python :: 2.7", - "Programming Language :: Python :: 3.4", - "Programming Language :: Python :: 3.5", - "Programming Language :: Python :: 3.6", - ], - packages=["neo4j", "neo4j.bolt", "neo4j.compat", "neo4j.packstream", "neo4j.v1"], - ext_modules=ext_modules) +try: + setup(**setup_args) +except SystemExit: + print("Compilation failed, falling back to pure Python.") + del setup_args["ext_modules"] + setup(**setup_args)