Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes issue #85: the module can be imported on python 2.7.3 running i… #88

Merged
merged 4 commits into from
May 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions amqp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,19 @@
error_for_code,
__all__ as _all_exceptions,
)
from .utils import promise # noqa

# Enable celery 3.1.23 to import the package instead of breaking on an
# unknown symbol
__all_externals__ = [
'promise',
]

__all__ = [
'Connection',
'Channel',
'Message',
]
__all__ += _all_exceptions

__all__ += __all_externals__
13 changes: 11 additions & 2 deletions amqp/basic_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,24 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
from __future__ import absolute_import, unicode_literals

from . import spec
# Intended to fix #85: ImportError: cannot import name spec
# Encountered on python 2.7.3
# "The submodules often need to refer to each other. For example, the
# surround [sic] module might use the echo module. In fact, such
# references are so common that the import statement first looks in
# the containing package before looking in the standard module search
# path."
# Source:
# http://stackoverflow.com/a/14216937/4982251
from .spec import Basic
from .serialization import GenericContent

__all__ = ['Message']


class Message(GenericContent):
"""A Message for use with the Channnel.basic_* methods."""
CLASS_ID = spec.Basic.CLASS_ID
CLASS_ID = Basic.CLASS_ID

#: Instances of this class have these attributes, which
#: are passed back and forth as message properties between
Expand Down
3 changes: 2 additions & 1 deletion amqp/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,4 +254,5 @@ def error_for_code(code, text, method, default):


for _method_id, _method_name in list(METHOD_NAME_MAP.items()):
METHOD_NAME_MAP[unpack('>I', pack('>HH', *_method_id))[0]] = _method_name
METHOD_NAME_MAP[unpack(str('>I'), pack(str('>HH'), *_method_id))[0]] = \
_method_name
4 changes: 2 additions & 2 deletions amqp/serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from struct import pack, unpack_from
from time import mktime

from . import spec
from .spec import Basic
from .exceptions import FrameSyntaxError
from .five import int_types, long_t, string, string_t, items
from .utils import bytes_to_str as pstr_t, str_to_bytes
Expand Down Expand Up @@ -470,7 +470,7 @@ def decode_properties_basic(buf, offset=0,
return properties, offset

PROPERTY_CLASSES = {
spec.Basic.CLASS_ID: decode_properties_basic,
Basic.CLASS_ID: decode_properties_basic,
}


Expand Down
2 changes: 2 additions & 0 deletions amqp/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import logging
import sys

# enables celery 3.1.23 to start again
from vine import promise # noqa
from vine.utils import wraps

from .five import string_t
Expand Down