|
26 | 26 | from neo4j.api import ( |
27 | 27 | Version, |
28 | 28 | ) |
| 29 | +from neo4j.io._courier import MessageInbox |
29 | 30 | from neo4j.meta import get_user_agent |
30 | 31 | from neo4j.exceptions import ( |
31 | 32 | ProtocolError, |
|
39 | 40 | SessionExpired, |
40 | 41 | ) |
41 | 42 | from neo4j.packstream import ( |
42 | | - UnpackableBuffer, |
43 | 43 | Unpacker, |
44 | 44 | Packer, |
45 | 45 | ) |
@@ -178,7 +178,10 @@ def pull_all(self, **handlers): |
178 | 178 | log.debug("[#%04X] C: PULL_ALL", self.local_port) |
179 | 179 | self._append(b"\x3F", (), Response(self, **handlers)) |
180 | 180 |
|
181 | | - def begin(self, mode=None, bookmarks=None, metadata=None, timeout=None, **handlers): |
| 181 | + def begin(self, mode=None, bookmarks=None, metadata=None, timeout=None, |
| 182 | + db=None, **handlers): |
| 183 | + if db is not None: |
| 184 | + raise ValueError("Database selection is not supported in Bolt 3") |
182 | 185 | extra = {} |
183 | 186 | if mode: |
184 | 187 | extra["mode"] = mode |
@@ -538,56 +541,16 @@ def recv_into(self, buffer, n_bytes=0, flags=0): |
538 | 541 | return n_bytes |
539 | 542 |
|
540 | 543 |
|
541 | | -class Inbox: |
542 | | - |
543 | | - def __init__(self, s, on_error): |
544 | | - super(Inbox, self).__init__() |
545 | | - self.on_error = on_error |
546 | | - self._messages = self._yield_messages(s) |
547 | | - |
548 | | - def __iter__(self): |
549 | | - return self |
| 544 | +class Inbox(MessageInbox): |
550 | 545 |
|
551 | 546 | def __next__(self): |
552 | | - return next(self._messages) |
553 | | - |
554 | | - @classmethod |
555 | | - def _load_chunks(cls, sock, buffer): |
556 | | - chunk_size = 0 |
557 | | - while True: |
558 | | - if chunk_size == 0: |
559 | | - buffer.receive(sock, 2) |
560 | | - chunk_size = buffer.pop_u16() |
561 | | - if chunk_size > 0: |
562 | | - buffer.receive(sock, chunk_size + 2) |
563 | | - yield chunk_size |
564 | | - |
565 | | - def _yield_messages(self, sock): |
566 | | - try: |
567 | | - buffer = UnpackableBuffer() |
568 | | - chunk_loader = self._load_chunks(sock, buffer) |
569 | | - unpacker = Unpacker(buffer) |
570 | | - details = [] |
571 | | - while True: |
572 | | - unpacker.reset() |
573 | | - details[:] = () |
574 | | - chunk_size = -1 |
575 | | - while chunk_size != 0: |
576 | | - chunk_size = next(chunk_loader) |
577 | | - summary_signature = None |
578 | | - summary_metadata = None |
579 | | - size, signature = unpacker.unpack_structure_header() |
580 | | - if size > 1: |
581 | | - raise ProtocolError("Expected one field") |
582 | | - if signature == b"\x71": |
583 | | - data = unpacker.unpack() |
584 | | - details.append(data) |
585 | | - else: |
586 | | - summary_signature = signature |
587 | | - summary_metadata = unpacker.unpack_map() |
588 | | - yield details, summary_signature, summary_metadata |
589 | | - except OSError as error: |
590 | | - self.on_error(error) |
| 547 | + tag, fields = self.pop() |
| 548 | + if tag == b"\x71": |
| 549 | + return fields, None, None |
| 550 | + elif fields: |
| 551 | + return [], tag, fields[0] |
| 552 | + else: |
| 553 | + return [], tag, None |
591 | 554 |
|
592 | 555 |
|
593 | 556 | class Response: |
|
0 commit comments