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

Original headers #309

Merged
merged 10 commits into from
Apr 27, 2020
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Add support for \r\n EOL handling (as per [stomp protocol v1.2](http://stomp.github.io/stomp-specification-1.2.html#Augmented_BNF))
* Remove heartbeat loop sleep (issue https://github.com/jasonrbriggs/stomp.py/issues/297, https://github.com/jasonrbriggs/stomp.py/pull/298)
* Update version number using the makefile and the poetry version command
* Add `original_headers` access to the Frame so that you can get the original value of a header even if a listener modifies it (issue https://github.com/jasonrbriggs/stomp.py/issues/300, PR https://github.com/jasonrbriggs/stomp.py/pull/309)


## Version 6.0.0 - Feb 2020
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,6 @@ run-docker:
remove-docker:
docker stop stomppy
docker rm stomppy


docker: remove-docker docker-image run-docker
9 changes: 9 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ The current version of stomp.py supports:

There is also legacy 3.1.7 version using the old 3-series code (see `3.1.7 on PyPi`_ and `3.1.7 on GitHub`_). This is no longer supported, but (at least as of 2018) there were still a couple of reports of this version still being used in the wild.

Note: stomp.py now follows `semantic versioning`_:

- MAJOR version for incompatible API changes,
- MINOR version for functionality added in a backwards compatible manner, and
- PATCH version for backwards compatible bug fixes.



Testing
=======
Expand Down Expand Up @@ -98,3 +105,5 @@ For testing locally, you'll need to install docker. Once installed:
.. _`stompserver`: http://stompserver.rubyforge.org

.. _`buy me a coffee`: https://www.paypal.me/jasonrbriggs

.. _`semantic versioning`: https://semver.org/
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "stomp.py"
version = "6.1.0"
version = "7.0.0"
description = "Python STOMP client, supporting versions 1.0, 1.1 and 1.2 of the protocol"
authors = ["Jason R Briggs <[email protected]>"]
license = "Apache-2.0"
Expand Down
43 changes: 21 additions & 22 deletions stomp/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def __init__(self, host='localhost', port=61613, user='', passcode='', ver='1.1'
self.__subscriptions = {}
self.__subscription_id = 1

def __print_async(self, frame_type, headers, body):
def __print_async(self, frame_type, frame):
"""
Utility function to print a message and setup the command prompt
for the next input
Expand All @@ -110,16 +110,16 @@ def __print_async(self, frame_type, headers, body):
return
if self.verbose:
self.__sysout(frame_type)
for k, v in headers.items():
for k, v in frame.headers.items():
self.__sysout("%s: %s" % (k, v))
else:
if "message-id" in headers:
self.__sysout("message-id: %s" % headers["message-id"])
if "subscription" in headers:
self.__sysout("subscription: %s" % headers["subscription"])
if "message-id" in frame.headers:
self.__sysout("message-id: %s" % frame.headers["message-id"])
if "subscription" in frame.headers:
self.__sysout("subscription: %s" % frame.headers["subscription"])
if self.prompt != '':
self.__sysout('')
self.__sysout(body)
self.__sysout(frame.body)
if not self.__start:
self.__sysout(self.prompt, end='')
else:
Expand Down Expand Up @@ -147,43 +147,42 @@ def on_disconnected(self):
if not self.__quit:
self.__error("lost connection")

def on_message(self, headers, body):
def on_message(self, frame):
"""
See :py:meth:`ConnectionListener.on_message`

Special case: if the header 'filename' is present, the content is written out
as a file
"""
self.__sysout('')
if "filename" in headers:
content = base64.b64decode(body.encode())
if os.path.exists(headers["filename"]):
fname = "%s.%s" % (headers["filename"], int(time.time()))
if "filename" in frame.headers:
content = base64.b64decode(frame.body.encode())
if os.path.exists(frame.headers["filename"]):
fname = "%s.%s" % (frame.headers["filename"], int(time.time()))
else:
fname = headers["filename"]
fname = frame.headers["filename"]
with open(fname, 'wb') as f:
f.write(content)
self.__print_async("MESSAGE", headers, "Saved file: %s" % fname)
else:
self.__print_async("MESSAGE", headers, body)
frame.body = "Saved file: %s" % fname
self.__print_async("MESSAGE", frame)

def on_error(self, headers, body):
def on_error(self, frame):
"""
See :py:meth:`ConnectionListener.on_error`
"""
self.__print_async("ERROR", headers, body)
self.__print_async("ERROR", frame)

def on_receipt(self, headers, body):
def on_receipt(self, frame):
"""
See :py:meth:`ConnectionListener.on_receipt`
"""
self.__print_async("RECEIPT", headers, body)
self.__print_async("RECEIPT", frame)

def on_connected(self, headers, body):
def on_connected(self, frame):
"""
See :py:meth:`ConnectionListener.on_connected`
"""
self.__print_async("CONNECTED", headers, body)
self.__print_async("CONNECTED", frame)

def on_send(self, frame):
if self.verbose:
Expand Down
12 changes: 6 additions & 6 deletions stomp/adapter/multicast.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ def process_frame(self, f, frame_str):
if frame_type == "message":
if f.headers["destination"] not in self.subscriptions.values():
return
(f.headers, f.body) = self.notify("before_message", f.headers, f.body)
self.notify(frame_type, f.headers, f.body)
self.notify("before_message", f)
self.notify(frame_type, f)
if "receipt" in f.headers:
receipt_frame = Frame("RECEIPT", {"receipt-id": f.headers["receipt"]})
lines = convert_frame(receipt_frame)
Expand Down Expand Up @@ -148,18 +148,18 @@ def send_frame(self, cmd, headers=None, body=''):
"""
if headers is None:
headers = {}
frame = utils.Frame(cmd, headers, body)
frame = Frame(cmd, headers, body)

if cmd == CMD_BEGIN:
trans = headers[HDR_TRANSACTION]
if trans in self.transactions:
self.notify("error", {}, "Transaction %s already started" % trans)
self.notify("error", Frame(None, {}, "Transaction %s already started" % trans))
else:
self.transactions[trans] = []
elif cmd == CMD_COMMIT:
trans = headers[HDR_TRANSACTION]
if trans not in self.transactions:
self.notify("error", {}, "Transaction %s not started" % trans)
self.notify("error", Frame(None, {}, "Transaction %s not started" % trans))
else:
for f in self.transactions[trans]:
self.transport.transmit(f)
Expand All @@ -171,7 +171,7 @@ def send_frame(self, cmd, headers=None, body=''):
if "transaction" in headers:
trans = headers["transaction"]
if trans not in self.transactions:
self.transport.notify("error", {}, "Transaction %s not started" % trans)
self.transport.notify("error", Frame(None, {}, "Transaction %s not started" % trans))
return
else:
self.transactions[trans].append(frame)
Expand Down
Loading