diff options
author | Matus Valo <matusvalo@gmail.com> | 2020-08-20 13:41:58 +0200 |
---|---|---|
committer | Asif Saif Uddin <auvipy@gmail.com> | 2020-08-24 15:04:25 +0600 |
commit | 9b31652fb679510f0f10ab7dedf47bd3daf8a466 (patch) | |
tree | 7bb49ad5c861961279b1284d821c60a3f1c6835b /amqp | |
parent | 3221bff40a864ae9dac5f1c427c3a4db02b25563 (diff) | |
download | py-amqp-9b31652fb679510f0f10ab7dedf47bd3daf8a466.tar.gz |
Multiple improvements of cythonized code
* set cython language_level = 3
* Cythonize amqp.method_framing.Buffer
* Use directly chr() function
* Cythonize str_to_bytes() and bytes_to_str() in amqp/utils.py
Diffstat (limited to 'amqp')
-rw-r--r-- | amqp/abstract_channel.pxd | 1 | ||||
-rw-r--r-- | amqp/basic_message.pxd | 3 | ||||
-rw-r--r-- | amqp/method_framing.pxd | 7 | ||||
-rw-r--r-- | amqp/serialization.pxd | 4 | ||||
-rw-r--r-- | amqp/serialization.py | 4 | ||||
-rw-r--r-- | amqp/utils.pxd | 4 |
6 files changed, 18 insertions, 5 deletions
diff --git a/amqp/abstract_channel.pxd b/amqp/abstract_channel.pxd index d2e32b1..cfcaa62 100644 --- a/amqp/abstract_channel.pxd +++ b/amqp/abstract_channel.pxd @@ -1,3 +1,4 @@ +# cython: language_level=3 import cython from .serialization cimport loads, dumps diff --git a/amqp/basic_message.pxd b/amqp/basic_message.pxd index 7ba043f..58bb4aa 100644 --- a/amqp/basic_message.pxd +++ b/amqp/basic_message.pxd @@ -1,4 +1,5 @@ -from serialization cimport GenericContent +# cython: language_level=3 +from .serialization cimport GenericContent cdef class Message(GenericContent): cdef public object channel diff --git a/amqp/method_framing.pxd b/amqp/method_framing.pxd index 60ad8a1..4264471 100644 --- a/amqp/method_framing.pxd +++ b/amqp/method_framing.pxd @@ -1,4 +1,9 @@ -from basic_message cimport Message +# cython: language_level=3 +from .basic_message cimport Message cdef object FRAME_OVERHEAD cdef object _CONTENT_METHODS + +cdef class Buffer: + cdef bytearray _buf + cdef object view diff --git a/amqp/serialization.pxd b/amqp/serialization.pxd index 0e86834..c7a06dd 100644 --- a/amqp/serialization.pxd +++ b/amqp/serialization.pxd @@ -1,5 +1,9 @@ +# cython: language_level=3 import cython +from amqp.utils cimport str_to_bytes +from amqp.utils cimport bytes_to_str as pstr_t + cdef int _flushbits(list bits, write) # Does not raise FrameSyntaxError due performance reasons diff --git a/amqp/serialization.py b/amqp/serialization.py index 1d1b377..75b082e 100644 --- a/amqp/serialization.py +++ b/amqp/serialization.py @@ -16,8 +16,6 @@ from .spec import Basic from .utils import bytes_to_str as pstr_t from .utils import str_to_bytes -ftype_t = chr - ILLEGAL_TABLE_TYPE = """\ Table type {0!r} not handled by amqp. """ @@ -32,7 +30,7 @@ ILLEGAL_TABLE_TYPE_WITH_VALUE = """\ def _read_item(buf, offset): - ftype = ftype_t(buf[offset]) + ftype = chr(buf[offset]) offset += 1 # 'S': long string diff --git a/amqp/utils.pxd b/amqp/utils.pxd new file mode 100644 index 0000000..c56577d --- /dev/null +++ b/amqp/utils.pxd @@ -0,0 +1,4 @@ +# cython: language_level=3 + +cpdef str_to_bytes(s) +cpdef bytes_to_str(s) |