Make python ProtocolHandler available even with Cython

PYTHON-501
This commit is contained in:
Adam Holmberg
2016-02-26 15:07:00 -06:00
parent aa88936102
commit bdb55d0218
2 changed files with 7 additions and 6 deletions

View File

@@ -894,15 +894,15 @@ class EventMessage(_MessageType):
return event return event
class ProtocolHandler(object): class _ProtocolHandler(object):
""" """
ProtocolHander handles encoding and decoding messages. _ProtocolHander handles encoding and decoding messages.
This class can be specialized to compose Handlers which implement alternative This class can be specialized to compose Handlers which implement alternative
result decoding or type deserialization. Class definitions are passed to :class:`cassandra.cluster.Cluster` result decoding or type deserialization. Class definitions are passed to :class:`cassandra.cluster.Cluster`
on initialization. on initialization.
Contracted class methods are :meth:`ProtocolHandler.encode_message` and :meth:`ProtocolHandler.decode_message`. Contracted class methods are :meth:`_ProtocolHandler.encode_message` and :meth:`_ProtocolHandler.decode_message`.
""" """
message_types_by_opcode = _message_types_by_opcode.copy() message_types_by_opcode = _message_types_by_opcode.copy()
@@ -1039,12 +1039,12 @@ def cython_protocol_handler(colparser):
code_to_type = dict((v, k) for k, v in ResultMessage.type_codes.items()) code_to_type = dict((v, k) for k, v in ResultMessage.type_codes.items())
recv_results_rows = classmethod(make_recv_results_rows(colparser)) recv_results_rows = classmethod(make_recv_results_rows(colparser))
class CythonProtocolHandler(ProtocolHandler): class CythonProtocolHandler(_ProtocolHandler):
""" """
Use FastResultMessage to decode query result message messages. Use FastResultMessage to decode query result message messages.
""" """
my_opcodes = ProtocolHandler.message_types_by_opcode.copy() my_opcodes = _ProtocolHandler.message_types_by_opcode.copy()
my_opcodes[FastResultMessage.opcode] = FastResultMessage my_opcodes[FastResultMessage.opcode] = FastResultMessage
message_types_by_opcode = my_opcodes message_types_by_opcode = my_opcodes
@@ -1059,6 +1059,7 @@ if HAVE_CYTHON:
LazyProtocolHandler = cython_protocol_handler(LazyParser()) LazyProtocolHandler = cython_protocol_handler(LazyParser())
else: else:
# Use Python-based ProtocolHandler # Use Python-based ProtocolHandler
ProtocolHandler = _ProtocolHandler
LazyProtocolHandler = None LazyProtocolHandler = None

View File

@@ -16,7 +16,7 @@ a custom QueryHandler.
See :meth:`.Session.execute`, ::meth:`.Session.execute_async`, :attr:`.ResponseFuture.custom_payload`. See :meth:`.Session.execute`, ::meth:`.Session.execute_async`, :attr:`.ResponseFuture.custom_payload`.
.. autoclass:: ProtocolHandler .. autoclass:: _ProtocolHandler
.. autoattribute:: message_types_by_opcode .. autoattribute:: message_types_by_opcode
:annotation: = {default mapping} :annotation: = {default mapping}