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 neo4j.addressing import SocketAddress, Resolver from neo4j.bolt.cert import KNOWN_HOSTS from neo4j.bolt.response import InitResponse, AckFailureResponse, ResetResponse from neo4j.compat.ssl import SSL_AVAILABLE, HAS_SNI, SSLError from neo4j.exceptions import ClientError, ProtocolError, SecurityError, ServiceUnavailable from neo4j.packstream import Packer, Unpacker from neo4j.util import import_best as _import_best from neo4j.compat import perf_counter from neo4j.config import default_config, INFINITE, TRUST_ON_FIRST_USE ChunkedInputBuffer = _import_best("neo4j.bolt._io", "neo4j.bolt.io").ChunkedInputBuffer ChunkedOutputBuffer = _import_best("neo4j.bolt._io", "neo4j.bolt.io").ChunkedOutputBuffer DEFAULT_PORT = 7687 MAGIC_PREAMBLE = 0x6060B017 # Signature bytes for each message type INIT = b"\x01" # 0000 0001 // INIT <user_agent> <auth> ACK_FAILURE = b"\x0E" # 0000 1110 // ACK_FAILURE RESET = b"\x0F" # 0000 1111 // RESET RUN = b"\x10" # 0001 0000 // RUN <statement> <parameters> DISCARD_ALL = b"\x2F" # 0010 1111 // DISCARD * PULL_ALL = b"\x3F" # 0011 1111 // PULL * SUCCESS = b"\x70" # 0111 0000 // SUCCESS <metadata> RECORD = b"\x71" # 0111 0001 // RECORD <value>
# 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 neo4j.util import import_best as _import_best MessageFrame = _import_best("neo4j.bolt._io", "neo4j.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):
#!/usr/bin/env python # -*- encoding: utf-8 -*- # Copyright (c) 2002-2018 "Neo Technology," # Network Engine for Objects in Lund AB [http://neotechnology.com] # # This file is part of Neo4j. # # Licensed under the Apache License, Version 2.0 (the "License"); # 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 neo4j.util import import_best as _import_best from .structure import Structure Packer = _import_best("neo4j.packstream._packer", "neo4j.packstream.packer").Packer Unpacker = _import_best("neo4j.packstream._unpacker", "neo4j.packstream.unpacker").Unpacker