Skip to content

Commit

Permalink
Releasing 1.4.0
Browse files Browse the repository at this point in the history
- Updated LICENSE year.
- Updated Readme.
- Minor internal documentation updates.
- Raise earlier on UriConnection when Python is not compiled with SSL
support.
  • Loading branch information
eandersson committed Jul 10, 2016
1 parent 90f557f commit df35e89
Show file tree
Hide file tree
Showing 14 changed files with 70 additions and 45 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# Changelog

### Version 1.4.0
- 100% Unit-test Coverage!
- All classes are now slotted.
- New improved Heartbeat Monitor.
- If no data has been sent within the Heartbeat interval, the client will now send a Heartbeat to the server. - Thanks David Schneider.
- Reduced default RPC timeout from 120s to 60s.

### Version 1.3.4
- Dropped Python 3.2 Support.
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2014 Erik Olof Gunnar Andersson
Copyright (c) 2014-2016 Erik Olof Gunnar Andersson

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Introduction
-------------
AMQP-Storm is a library designed to be consistent, stable and thread-safe.

- 99%+ Unit-test coverage!
- 100% Unit-test Coverage!
- Supports Python 2.6, 2.7 and Python 3+.
- When using a SSL connection, TLSv1 or higher is required.

Expand Down
4 changes: 4 additions & 0 deletions amqpstorm/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ def __init__(self):

@property
def lock(self):
"""Threading lock.
:return:
"""
return self._lock

def set_state(self, state):
Expand Down
4 changes: 2 additions & 2 deletions amqpstorm/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
from amqpstorm import compatibility
from amqpstorm.base import BaseChannel
from amqpstorm.base import IDLE_WAIT
from amqpstorm.rpc import Rpc
from amqpstorm.basic import Basic
from amqpstorm.compatibility import try_utf8_decode
from amqpstorm.exception import AMQPChannelError
from amqpstorm.exception import AMQPConnectionError
from amqpstorm.exception import AMQPInvalidArgument
from amqpstorm.exception import AMQPMessageError
from amqpstorm.exchange import Exchange
from amqpstorm.message import Message
from amqpstorm.queue import Queue
from amqpstorm.compatibility import try_utf8_decode
from amqpstorm.rpc import Rpc

LOGGER = logging.getLogger(__name__)
CONTENT_FRAME = ['Basic.Deliver', 'ContentHeader', 'ContentBody']
Expand Down
9 changes: 4 additions & 5 deletions amqpstorm/channel0.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
from amqpstorm.base import LOCALE
from amqpstorm.base import MAX_CHANNELS
from amqpstorm.base import Stateful
from amqpstorm.exception import AMQPConnectionError
from amqpstorm.compatibility import try_utf8_decode

from amqpstorm.exception import AMQPConnectionError

LOGGER = logging.getLogger(__name__)

Expand All @@ -32,7 +31,7 @@ def __init__(self, connection):
self._heartbeat = self.parameters['heartbeat']

def on_frame(self, frame_in):
"""Handle frame sent to channel 0.
"""Handle frames sent to Channel0.
:param frame_in: Amqp frame.
:return:
Expand Down Expand Up @@ -107,7 +106,7 @@ def _set_connection_state(self, state):
self._connection.set_state(state)

def _write_frame(self, frame_out):
"""Write a pamqp frame from channel0.
"""Write a pamqp frame from Channel0.
:param frame_out: Amqp frame.
:return:
Expand Down Expand Up @@ -164,7 +163,7 @@ def _plain_credentials(self):

@staticmethod
def _client_properties():
"""AMQP Library Properties.
"""AMQPStorm Client Properties.
:rtype: dict
"""
Expand Down
3 changes: 2 additions & 1 deletion amqpstorm/compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def get_default_ssl_version():
return ssl.PROTOCOL_TLSv1
return None


DEFAULT_SSL_VERSION = get_default_ssl_version()
SSL_SUPPORTED = DEFAULT_SSL_VERSION is not None
if SSL_SUPPORTED:
Expand Down Expand Up @@ -89,7 +90,7 @@ def is_integer(obj):
def is_unicode(obj):
"""Is this a unicode string.
This always returns False if running on Python 3.
This always returns False if running Python 3.x.
:param object obj:
:rtype: bool
Expand Down
24 changes: 12 additions & 12 deletions amqpstorm/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,23 +88,23 @@ def is_blocked(self):

@property
def server_properties(self):
"""Returns the RabbitMQ Server properties.
"""Returns the RabbitMQ Server Properties.
:rtype: dict
"""
return self._channel0.server_properties

@property
def socket(self):
"""Returns an instance of the socket.
"""Returns an instance of the Socket used by the Connection.
:rtype: socket
"""
return self._io.socket

@property
def fileno(self):
"""Socket Fileno.
"""Returns the Socket File number.
:return:
"""
Expand Down Expand Up @@ -139,7 +139,7 @@ def close(self):
self.set_state(self.CLOSED)
LOGGER.debug('Connection Closed')

def channel(self, rpc_timeout=120):
def channel(self, rpc_timeout=60):
"""Open Channel.
:param int rpc_timeout: Timeout before we give up waiting for an RPC
Expand All @@ -165,7 +165,7 @@ def channel(self, rpc_timeout=120):
return self._channels[channel_id]

def check_for_errors(self):
"""Check connection for errors.
"""Check Connection for errors.
:raises AMQPConnectionError: Raises if the connection
encountered an error.
Expand All @@ -178,7 +178,7 @@ def check_for_errors(self):
raise self.exceptions[0]

def write_frame(self, channel_id, frame_out):
"""Marshal and write an outgoing pamqp frame to the socket.
"""Marshal and write an outgoing pamqp frame to the Socket.
:param int channel_id:
:param pamqp_spec.Frame frame_out: Amqp frame.
Expand All @@ -189,7 +189,7 @@ def write_frame(self, channel_id, frame_out):
self._io.write_to_socket(frame_data)

def write_frames(self, channel_id, multiple_frames):
"""Marshal and write multiple outgoing pamqp frames to the socket.
"""Marshal and write multiple outgoing pamqp frames to the Socket.
:param int channel_id:
:param list multiple_frames: Amqp frames.
Expand Down Expand Up @@ -222,14 +222,14 @@ def _validate_parameters(self):
raise AMQPInvalidArgument('heartbeat should be an integer')

def _send_handshake(self):
"""Send RabbitMQ Handshake.
"""Send a RabbitMQ Handshake.
:return:
"""
self._io.write_to_socket(pamqp_header.ProtocolHeader().marshal())

def _wait_for_connection_to_open(self):
"""Wait for the connection to fully open.
"""Wait for the Connection to fully open.
:return:
"""
Expand All @@ -242,10 +242,10 @@ def _wait_for_connection_to_open(self):
sleep(IDLE_WAIT)

def _read_buffer(self, buffer):
"""Process the socket buffer, and direct the data to the correct
"""Process the socket buffer, and direct the data to the appropriate
channel.
:return:
:rtype: bytes
"""
while buffer:
buffer, channel_id, frame_in = \
Expand All @@ -263,7 +263,7 @@ def _read_buffer(self, buffer):
return buffer

def _handle_amqp_frame(self, data_in):
"""Unmarshal any incoming RabbitMQ frames and return the result.
"""Unmarshal a incoming RabbitMQ frame and return the result.
:param data_in: socket data
:return: buffer, channel_id, frame
Expand Down
16 changes: 7 additions & 9 deletions amqpstorm/heartbeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,14 @@ def stop(self):
self._timer = None

def _check_for_life_signs(self):
"""Check if we have any sign of life.
"""Check Connection for life signs.
First check if any data has been sent, if not send a heartbeat.
First check if any data has been sent, if not send a heartbeat
to the remote server.
If we have not received a heartbeat, or any data what so ever
within two intervals, we need to raise an exception so
that we can close the connection.
RabbitMQ may not necessarily send heartbeats if the connection
is busy, so we only raise if no frame has been received.
If we have not received any data what so ever within two
intervals, we need to raise an exception so that we can
close the connection.
:rtype: bool
"""
Expand Down Expand Up @@ -102,7 +100,7 @@ def _check_for_life_signs(self):
return True

def _start_new_timer(self):
"""Create a timer that will check for life signs on our connection.
"""Create a timer that will check for life signs on our Connection.
:return:
"""
Expand Down
12 changes: 7 additions & 5 deletions amqpstorm/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,11 @@ def _find_address_and_connect(self, addresses):
"""Find and connect to the appropriate address.
:param addresses:
:raises AMQPConnectionError: If no appropriate address can be found,
raise an exception.
:return:
:rtype: socket.socket
"""
for address in addresses:
sock = self._create_socket(socket_family=address[0])
Expand All @@ -169,7 +171,7 @@ def _create_socket(self, socket_family):
"""Create Socket.
:param int family:
:return:
:rtype: socket.socket
"""
sock = socket.socket(socket_family, socket.SOCK_STREAM, 0)
sock.setsockopt(socket.SOL_TCP, socket.TCP_NODELAY, 1)
Expand All @@ -183,7 +185,7 @@ def _create_socket(self, socket_family):
return sock

def _ssl_wrap_socket(self, sock):
"""Wrap SSLSocket around the socket.
"""Wrap SSLSocket around the Socket.
:param socket sock:
:rtype: SSLSocket
Expand Down Expand Up @@ -222,7 +224,7 @@ def _receive(self):
If an error is thrown, handle it and return an empty string.
:return: buffer
:rtype: str
:rtype: bytes
"""
result = EMPTY_BUFFER
try:
Expand All @@ -237,7 +239,7 @@ def _receive(self):
def _read_from_socket(self):
"""Read data from the socket.
:return:
:rtype: bytes
"""
if self.use_ssl:
result = self.socket.read(FRAME_MAX)
Expand Down
1 change: 1 addition & 0 deletions amqpstorm/tests/channel_tests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import threading

import mock

try:
Expand Down
5 changes: 3 additions & 2 deletions amqpstorm/tests/compatiblity_tests.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
import logging
import imp
import logging
import ssl
import sys

Expand Down Expand Up @@ -127,7 +127,8 @@ class SslTLSNone(object):


class CompatibilitySslTests(unittest.TestCase):
@unittest.skipIf('ssl' not in sys.modules, 'no ssl support')
@unittest.skipIf('ssl' not in sys.modules, 'Python not compiled '
'with SSL support')
def test_compatibility_default_ssl_version(self):
self.assertTrue(compatibility.SSL_SUPPORTED)
if hasattr(ssl, 'PROTOCOL_TLSv1_2'):
Expand Down
13 changes: 13 additions & 0 deletions amqpstorm/tests/uri_connection_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import unittest

from amqpstorm import UriConnection
from amqpstorm import compatibility
from amqpstorm.exception import AMQPConnectionError

from amqpstorm.tests.utility import MockLoggingHandler

Expand Down Expand Up @@ -193,3 +195,14 @@ def test_uri_get_invalid_ssl_validation(self):
self.assertIn("ssl_options: cert_reqs 'cert_test' not found "
"falling back to CERT_NONE.",
self.logging_handler.messages['warning'][0])

def test_uri_ssl_not_supported(self):
compatibility.SSL_SUPPORTED = False
try:
self.assertRaisesRegexp(AMQPConnectionError,
'Python not compiled with '
'support for TLSv1 or higher',
UriConnection,
'amqps://localhost:5672/%2F')
finally:
compatibility.SSL_SUPPORTED = True
Loading

0 comments on commit df35e89

Please sign in to comment.