diff --git a/coolamqp/framing/compilation/compile_definitions.py b/coolamqp/framing/compilation/compile_definitions.py index 0109147ab1d5dca885626b17cac36fd80718b514..62a957d53a2ba88897478d87fae438cd1cd6f008 100644 --- a/coolamqp/framing/compilation/compile_definitions.py +++ b/coolamqp/framing/compilation/compile_definitions.py @@ -55,7 +55,7 @@ binary string? It's a memoryview all right. Only thing that isn't are field names in tables. """ -import struct, collections, warnings, logging, six +import struct, collections, logging, six from coolamqp.framing.base import AMQPClass, AMQPMethodPayload, AMQPContentPropertyList from coolamqp.framing.field_table import enframe_table, deframe_table, frame_table_size @@ -230,7 +230,7 @@ Field = collections.namedtuple('Field', ('name', 'type', 'basic_type', 'reserved # # If you do not know in advance what properties you will be using, it is correct to use # this constructor. - + if zpf in BasicContentPropertyList.PARTICULAR_CLASSES: return %s.PARTICULAR_CLASSES[zpf](**kwargs) else: logger.debug('Property field (%s:%d) not seen yet, compiling', repr(zpf)) diff --git a/coolamqp/framing/definitions.py b/coolamqp/framing/definitions.py index cab1e0787980ef1a353b69ea557e695e8e2e5df2..e472c3d376f2de66819fb6592677c6cfe8b5dd92 100644 --- a/coolamqp/framing/definitions.py +++ b/coolamqp/framing/definitions.py @@ -23,7 +23,7 @@ binary string? It's a memoryview all right. Only thing that isn't are field names in tables. """ -import struct, collections, warnings, logging, six +import struct, collections, logging, six from coolamqp.framing.base import AMQPClass, AMQPMethodPayload, AMQPContentPropertyList from coolamqp.framing.field_table import enframe_table, deframe_table, frame_table_size @@ -2359,6 +2359,23 @@ class BasicContentPropertyList(AMQPContentPropertyList): ]) zpf = six.binary_type(zpf) +# If you know in advance what properties you will be using, use typized constructors like +# +# runs once +# my_type = BasicContentPropertyList.typize('content_type', 'content_encoding') +# +# runs many times +# props = my_type('text/plain', 'utf8') +# +# instead of +# +# # runs many times +# props = BasicContentPropertyList(content_type='text/plain', content_encoding='utf8') +# +# This way you will be faster. +# +# If you do not know in advance what properties you will be using, it is correct to use +# this constructor. if zpf in BasicContentPropertyList.PARTICULAR_CLASSES: return BasicContentPropertyList.PARTICULAR_CLASSES[zpf](**kwargs) else: