コード例 #1
0
def test_service_root_on_bound_path(graph):
    alice = Node(name="Alice")
    bob = Node(name="Bob")
    carol = Node(name="Carol")
    dave = Node(name="Dave")
    path = Path(alice, "LOVES", bob, Rev("HATES"), carol, "KNOWS", dave)
    graph.create(path)
    assert path.service_root == ServiceRoot("http://localhost:7474/")
    path[0].unbind()
    assert path.service_root == ServiceRoot("http://localhost:7474/")
コード例 #2
0
ファイル: relationship_test.py プロジェクト: zrg1993/py2neo
def test_service_root(graph):
    a, b, ab = graph.create({}, {}, (0, "KNOWS", 1))
    assert ab.service_root == ServiceRoot("http://localhost:7474/")
    ab.rel.unbind()
    assert ab.service_root == ServiceRoot("http://localhost:7474/")
    a.unbind()
    assert ab.service_root == ServiceRoot("http://localhost:7474/")
    b.unbind()
    try:
        _ = ab.service_root
    except BindError:
        assert True
    else:
        assert False
コード例 #3
0
ファイル: server.py プロジェクト: LiuYuQ/beifen
    def start(self):
        """ Start the server.

        :rtype: :class:`py2neo.server.GraphServerProcess`

        """
        try:
            out = check_output("%s start" % self.script, shell=True)
        except CalledProcessError as error:
            if error.returncode == 2:
                raise OSError(
                    "Another process is listening on the server port")
            elif error.returncode == 512:
                raise OSError("Another server process is already running")
            else:
                raise OSError("An error occurred while trying to start "
                              "the server [%s]" % error.returncode)
        else:
            uri = None
            kwargs = {}
            for line in out.decode("utf-8").splitlines(False):
                if line.startswith("Using additional JVM arguments:"):
                    kwargs["jvm_arguments"] = shlex.split(line[32:])
                elif line.startswith("process"):
                    numbers = number_in_brackets.search(line).groups()
                    if numbers:
                        kwargs["pid"] = int(numbers[0])
                elif line.startswith("http"):
                    uri = line.partition(" ")[0]
            if not uri:
                raise RuntimeError(
                    "Unable to parse output from server startup")
            return GraphServerProcess(self, ServiceRoot(uri), **kwargs)
コード例 #4
0
    def service_root(self):
        """ The service root exposed by this server.

        :return: :class:`py2neo.ServiceRoot`

        """
        return ServiceRoot("http://localhost:%s" % self.info["NEO4J_SERVER_PORT"])
コード例 #5
0
def main():
    script, args = sys.argv[0], sys.argv[1:]
    if len(args) < 2 or len(args) > 3:
        _help(script)
        return
    try:
        service_root = ServiceRoot(NEO4J_URI)
        user_name = args[0]
        password = args[1]
        user_manager = UserManager.for_user(service_root, user_name, password)
        if len(args) == 2:
            # Check password
            if user_manager.password_change_required:
                print("Password change required")
            else:
                print("Password change not required")
        else:
            # Change password
            password_manager = user_manager.password_manager
            new_password = args[2]
            if password_manager.change(new_password):
                print("Password change succeeded")
            else:
                print("Password change failed")
                sys.exit(2)
    except Exception as error:
        sys.stderr.write("%s: %s\n" % (error.__class__.__name__, ustr(error)))
        sys.exit(1)
コード例 #6
0
ファイル: admin.py プロジェクト: Sapphirine/stackexchange
 def __init__(self, uri=None):
     if uri is None:
         service_root = ServiceRoot()
         manager = Resource(service_root.resource.metadata["management"])
         monitor = Monitor(manager.metadata["services"]["monitor"])
         uri = monitor.resource.uri
     Service.__init__(self)
     self.bind(uri)
コード例 #7
0
def change_password():
    global NEO4J_URL, NEO4J_HOST_PORT, NEO4J_USER, NEO4J_PASSWORD, NEO4J_DEFAULT_PASSWORD

    service_root = ServiceRoot(NEO4J_URL)
    user_name = NEO4J_USER
    password = NEO4J_DEFAULT_PASSWORD
    user_manager = UserManager.for_user(service_root, user_name, password)
    password_manager = user_manager.password_manager
    new_password = NEO4J_PASSWORD
    password_manager.change(new_password)
コード例 #8
0
def test_service_root_on_unbound_path():
    alice = Node(name="Alice")
    bob = Node(name="Bob")
    carol = Node(name="Carol")
    dave = Node(name="Dave")
    path = Path(alice, "LOVES", bob, Rev("HATES"), carol, "KNOWS", dave)
    try:
        assert path.service_root == ServiceRoot("http://localhost:7474/")
    except BindError:
        assert True
    else:
        assert False
コード例 #9
0
ファイル: service_root_test.py プロジェクト: zrg1993/py2neo
def test_same_uri_gives_same_instance():
    uri = "http://localhost:7474/"
    service_root_1 = ServiceRoot(uri)
    service_root_2 = ServiceRoot(uri)
    assert service_root_1 is service_root_2
コード例 #10
0
ファイル: service_root_test.py プロジェクト: zrg1993/py2neo
def test_can_create_service_root_without_trailing_slash():
    uri = "http://localhost:7474/"
    service_root = ServiceRoot(uri[:-1])
    assert service_root.uri == uri
    index = service_root.resource.get().content
    assert "data" in index
コード例 #11
0
ファイル: neo4j.py プロジェクト: vbursztyn/SegundoVoto
 def __init__(self):
     neo4jUri = 'http://localhost:7474/'
     self.graph = ServiceRoot(neo4jUri).graph
コード例 #12
0
ファイル: neo.py プロジェクト: maryamm02/elegans
def graph_p2():
    """ Get connection to graph via py2neo. """
    graphenedb_url = os.environ.get("GRAPHENEDB_URL", "http://localhost:7474/")
    return ServiceRoot(graphenedb_url).graph
コード例 #13
0
ファイル: __init__.py プロジェクト: devangmundhra/alltoez
__author__ = 'devangmundhra'

from django.conf import settings

from py2neo import ServiceRoot, Relationship, Node

_neo4j_url = settings.NEO4J_URL
neo4j_graph = ServiceRoot(_neo4j_url).graph