|
| 1 | +# Copyright (c) "Neo4j" |
| 2 | +# Neo4j Sweden AB [https://neo4j.com] |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | + |
| 16 | + |
| 17 | +from __future__ import annotations |
| 18 | + |
| 19 | +from .. import _typing as t # noqa: TC001 |
| 20 | + |
| 21 | + |
| 22 | +class UnsupportedType: |
| 23 | + """ |
| 24 | + Represents a type unknown to the driver, received from the server. |
| 25 | +
|
| 26 | + This type is used for instance when a newer DBMS produces a result |
| 27 | + containing a type that the current version of the driver does not yet |
| 28 | + understand. |
| 29 | +
|
| 30 | + Note that this type may only be received from the server, but cannot be |
| 31 | + sent to the server (e.g., as a query parameter). |
| 32 | +
|
| 33 | + The attributes exposed by this type are meant for displaying and debugging |
| 34 | + purposes. |
| 35 | + They may change in future versions of the server, and should not be relied |
| 36 | + upon for any logic in your application. |
| 37 | + If your application requires handling this type, you must upgrade your |
| 38 | + driver to a version that supports it. |
| 39 | + """ |
| 40 | + |
| 41 | + _name: str |
| 42 | + _minimum_protocol_version: tuple[int, int] |
| 43 | + _message: str | None |
| 44 | + |
| 45 | + @classmethod |
| 46 | + def _new( |
| 47 | + cls, |
| 48 | + name: str, |
| 49 | + minimum_protocol_version: tuple[int, int], |
| 50 | + message: str | None, |
| 51 | + ) -> t.Self: |
| 52 | + obj = cls.__new__(cls) |
| 53 | + obj._name = name |
| 54 | + obj._minimum_protocol_version = minimum_protocol_version |
| 55 | + obj._message = message |
| 56 | + return obj |
| 57 | + |
| 58 | + @property |
| 59 | + def name(self) -> str: |
| 60 | + """The name of the type.""" |
| 61 | + return self._name |
| 62 | + |
| 63 | + @property |
| 64 | + def minimum_protocol_version(self) -> tuple[int, int]: |
| 65 | + """ |
| 66 | + The minimum required Bolt protocol version that supports this type. |
| 67 | +
|
| 68 | + This is a 2-:class:`tuple` of ``(major, minor)`` integers. |
| 69 | +
|
| 70 | + To understand which driver version this corresponds to, refer to the |
| 71 | + driver's release notes or documentation. |
| 72 | +
|
| 73 | +
|
| 74 | + .. seealso:: |
| 75 | + < |
| 76 | + link to evolving doc listing which version of the driver |
| 77 | + supports which Bolt version |
| 78 | + > |
| 79 | + """ |
| 80 | + # TODO fix link above |
| 81 | + return self._minimum_protocol_version |
| 82 | + |
| 83 | + @property |
| 84 | + def message(self) -> str | None: |
| 85 | + """ |
| 86 | + Optional, further details about this type. |
| 87 | +
|
| 88 | + Any additional information provided by the server about this type. |
| 89 | + """ |
| 90 | + return self._message |
| 91 | + |
| 92 | + def __str__(self) -> str: |
| 93 | + return f"{self.__class__.__name__}<{self._name}>" |
| 94 | + |
| 95 | + def __repr__(self) -> str: |
| 96 | + args = [ |
| 97 | + f" name={self._name!r}", |
| 98 | + f" minimum_protocol_version={self._minimum_protocol_version!r}", |
| 99 | + ] |
| 100 | + if self._message is not None: |
| 101 | + args.append(f" message={self._message!r}") |
| 102 | + return f"<{self.__class__.__name__}{''.join(args)}>" |
0 commit comments