Permalink
Browse files

Remove force binary and unicode casting

  • Loading branch information...
1 parent e918d15 commit efea53d109352400830609ecdca86707782fb822 @gmr gmr committed May 7, 2014
Showing with 6 additions and 21 deletions.
  1. +6 −21 pika/channel.py
View
@@ -29,13 +29,12 @@ class Channel(object):
OPEN = 2
CLOSING = 3
- def __init__(self, connection, channel_number, on_open_callback=None, force_binary=False):
+ def __init__(self, connection, channel_number, on_open_callback=None):
"""Create a new instance of the Channel
:param pika.connection.Connection connection: The connection
:param int channel_number: The channel number for this instance
:param method on_open_callback: The method to call on channel open
- :param bool force_binary: Prevents channel from autodetecting unicode
"""
if not isinstance(channel_number, int):
@@ -45,7 +44,7 @@ def __init__(self, connection, channel_number, on_open_callback=None, force_bina
self.connection = connection
# The frame-handler changes depending on the type of frame processed
- self.frame_dispatcher = ContentFrameDispatcher(force_binary)
+ self.frame_dispatcher = ContentFrameDispatcher()
self._blocked = collections.deque(list())
self._blocking = None
@@ -1087,7 +1086,7 @@ class ContentFrameDispatcher(object):
back in three parts upon receipt.
"""
- def __init__(self, force_binary):
+ def __init__(self):
"""Create a new instance of the Dispatcher passing in the callback
manager.
@@ -1096,7 +1095,6 @@ def __init__(self, force_binary):
self._header_frame = None
self._seen_so_far = 0
self._body_fragments = list()
- self.force_binary = force_binary
def process(self, frame_value):
"""Invoked by the Channel object when passed frames that are not
@@ -1121,25 +1119,12 @@ def process(self, frame_value):
def _finish(self):
"""Invoked when all of the message has been received
- :rtype: tuple(pika.frame.Method, pika.frame.Header, str|unicode)
+ :rtype: tuple(pika.frame.Method, pika.frame.Header, str)
"""
- value = None
- if self.force_binary:
- value = ''.join(self._body_fragments)
- else:
- try:
- value = ''.join(self._body_fragments).decode('utf-8')
- try:
- value = str(value)
- except UnicodeEncodeError:
- pass
- except UnicodeDecodeError:
- value = ''.join(self._body_fragments)
-
content = (self._method_frame,
self._header_frame,
- value)
+ ''.join(self._body_fragments))
self._reset()
return content
@@ -1149,7 +1134,7 @@ def _handle_body_frame(self, body_frame):
:param Body body_frame: The body frame
:raises: pika.exceptions.BodyTooLongError
- :rtype: tuple(pika.frame.Method, pika.frame.Header, str|unicode)|None
+ :rtype: tuple(pika.frame.Method, pika.frame.Header, str)|None
"""
self._seen_so_far += len(body_frame.fragment)

1 comment on commit efea53d

Removing force_binary without modifying connection.py has broken the whole library. Please see #469 for the fix

Please sign in to comment.