<commit_before>from py2neo import neo4j, cypher
from .exception import DoesNotExist, CypherException
from .util import camel_to_upper, CustomBatch, _legacy_conflict_check
from .properties import Property, PropertyManager, AliasProperty
from .relationship_manager import RelationshipManager, OUTGOING
from .traversal import TraversalSet
from .signals import hooks
from .index import NodeIndexManager
import logging
import os
import sys
logger = logging.getLogger(__name__)

if sys.version_info >= (3, 0):
    from urllib.parse import urlparse
else:
    from urlparse import urlparse # noqa


DATABASE_URL = os.environ.get('NEO4J_REST_URL', 'http://localhost:7474/db/data/')


def connection():
    if hasattr(connection, 'db'):
        return connection.db

    url = DATABASE_URL
    u = urlparse(url)
    if u.netloc.find('@') > -1:
        credentials, host = u.netloc.split('@')
        user, password, = credentials.split(':')
        neo4j.authenticate(host, user, password)
        url = ''.join([u.scheme, '://', host, u.path, u.query])

    connection.db = neo4j.GraphDatabaseService(url)
    return connection.db


def cypher_query(query, params=None):
    if os.environ.get('NEOMODEL_CYPHER_DEBUG', False):
        logger.debug(query)
        logger.debug("params: " + repr(params))
    try:
        return cypher.execute(connection(), query, params)
    except cypher.CypherError as e:
        message, etype, jtrace = e.args
        raise CypherException(query, params, message, etype, jtrace)<commit_msg>Add Better debugging fixed for tests<commit_after>from py2neo import neo4j, cypher
from py2neo.rest import SocketError
from .exception import DoesNotExist, CypherException
from .util import camel_to_upper, CustomBatch, _legacy_conflict_check
from .properties import Property, PropertyManager, AliasProperty
from .relationship_manager import RelationshipManager, OUTGOING
from .traversal import TraversalSet
from .signals import hooks
from .index import NodeIndexManager
import logging
import os
import sys
logger = logging.getLogger(__name__)

if sys.version_info >= (3, 0):
    from urllib.parse import urlparse
else:
    from urlparse import urlparse # noqa


DATABASE_URL = os.environ.get('NEO4J_REST_URL', 'http://localhost:7474/db/data/')


def connection():
    if hasattr(connection, 'db'):
        return connection.db

    url = DATABASE_URL
    u = urlparse(url)
    if u.netloc.find('@') > -1:
        credentials, host = u.netloc.split('@')
        user, password, = credentials.split(':')
        neo4j.authenticate(host, user, password)
        url = ''.join([u.scheme, '://', host, u.path, u.query])

    try:
        connection.db = neo4j.GraphDatabaseService(url)
    except SocketError as e:
        raise SocketError("Error connecting to {0} - {1}".format(url, e))
    return connection.db


def cypher_query(query, params=None):
    if os.environ.get('NEOMODEL_CYPHER_DEBUG', False):
        logger.debug(query)
        logger.debug("params: " + repr(params))
    try:
        return cypher.execute(connection(), query, params)
    except cypher.CypherError as e:
        message, etype, jtrace = e.args
        raise CypherException(query, params, message, etype, jtrace)
{'fraction_non_alphanumeric': 0.10844499844188221, 'fraction_numerical': 0.008413836086008103, 'mean_word_length': 3.791044776119403, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6295941', 'n_tokens_mistral': 1037, 'n_tokens_neox': 988, 'n_words': 268}