from select import select from socket import socket, SOL_SOCKET, SO_KEEPALIVE, SHUT_RDWR, error as SocketError, timeout as SocketTimeout, AF_INET, AF_INET6 from struct import pack as struct_pack, unpack as struct_unpack from threading import RLock, Condition from sys import platform, version_info from neobolt.addressing import SocketAddress, Resolver from neobolt.compat import perf_counter from neobolt.compat.ssl import SSL_AVAILABLE, HAS_SNI, SSLSocket, SSLError from neobolt.exceptions import ClientError, ProtocolError, SecurityError, ServiceUnavailable, AuthError, CypherError from neobolt.meta import version, import_best from neobolt.packstream import Packer, Unpacker from neobolt.security import AuthToken, TRUST_DEFAULT, TRUST_ON_FIRST_USE, KNOWN_HOSTS, PersonalCertificateStore, \ SecurityPlan ChunkedInputBuffer = import_best("neobolt.bolt._io", "neobolt.bolt.io").ChunkedInputBuffer ChunkedOutputBuffer = import_best("neobolt.bolt._io", "neobolt.bolt.io").ChunkedOutputBuffer DEFAULT_PORT = 7687 MAGIC_PREAMBLE = 0x6060B017 # Connection Pool Management INFINITE = -1 DEFAULT_MAX_CONNECTION_LIFETIME = 3600 # 1h DEFAULT_MAX_CONNECTION_POOL_SIZE = 100 DEFAULT_CONNECTION_TIMEOUT = 5.0 # 5s DEFAULT_KEEP_ALIVE = True # Connection Settings
# you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from unittest import TestCase from neobolt.meta import import_best MessageFrame = import_best("neobolt.bolt._io", "neobolt.bolt.io").MessageFrame class MessageFrameTestCase(TestCase): def test_should_be_able_to_read_int(self): # Given frame = MessageFrame(memoryview(b"\x00\x03ABC\x00\x00"), [(2, 5)]) # When values = [frame.read_int() for _ in range(4)] # Then assert values == [65, 66, 67, -1] def test_should_be_able_to_read_int_across_chunks(self): # Given
self.tag = tag self.fields = list(fields) def __repr__(self): return "Structure<%s>(%s)" % (self.tag, ", ".join( map(repr, self.fields))) def __eq__(self, other): try: return self.tag == other.tag and self.fields == other.fields except AttributeError: return False def __ne__(self, other): return not self.__eq__(other) def __len__(self): return len(self.fields) def __getitem__(self, key): return self.fields[key] def __setitem__(self, key, value): self.fields[key] = value Packer = import_best("neobolt.packstream._packer", "neobolt.packstream.packer").Packer Unpacker = import_best("neobolt.packstream._unpacker", "neobolt.packstream.unpacker").Unpacker
# you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from unittest import TestCase from neobolt.meta import import_best MessageFrame = import_best("neobolt.impl.python.bolt._io", "neobolt.impl.python.bolt.io").MessageFrame class MessageFrameTestCase(TestCase): def test_should_be_able_to_read_int(self): # Given frame = MessageFrame(memoryview(b"\x00\x03ABC\x00\x00"), [(2, 5)]) # When values = [frame.read_int() for _ in range(4)] # Then assert values == [65, 66, 67, -1] def test_should_be_able_to_read_int_across_chunks(self): # Given