|
| 1 | +#!/usr/bin/env python |
| 2 | +# -*- encoding: utf-8 -*- |
| 3 | + |
| 4 | +# Copyright (c) 2002-2018 "Neo4j," |
| 5 | +# Neo4j Sweden AB [http://neo4j.com] |
| 6 | +# |
| 7 | +# This file is part of Neo4j. |
| 8 | +# |
| 9 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 10 | +# you may not use this file except in compliance with the License. |
| 11 | +# You may obtain a copy of the License at |
| 12 | +# |
| 13 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 14 | +# |
| 15 | +# Unless required by applicable law or agreed to in writing, software |
| 16 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 17 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 18 | +# See the License for the specific language governing permissions and |
| 19 | +# limitations under the License. |
| 20 | + |
| 21 | + |
| 22 | +# tag::custom-resolver-import[] |
| 23 | +from neo4j import GraphDatabase |
| 24 | +# end::custom-resolver-import[] |
| 25 | + |
| 26 | + |
| 27 | +# tag::custom-resolver[] |
| 28 | + |
| 29 | +class CustomResolverExample: |
| 30 | + |
| 31 | + def __init__(self, uri, user, password): |
| 32 | + self._driver = GraphDatabase.driver(uri, auth=(user, password), resolver=self.resolve) |
| 33 | + |
| 34 | + def resolve(self, address): |
| 35 | + host, port = address |
| 36 | + if host == "x.example.com": |
| 37 | + yield "a.example.com", port |
| 38 | + yield "b.example.com", port |
| 39 | + yield "c.example.com", port |
| 40 | + else: |
| 41 | + yield host, port |
| 42 | + |
| 43 | + def close(self): |
| 44 | + self._driver.close() |
| 45 | + |
| 46 | +# end::custom-resolver[] |
0 commit comments