Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

re-merging entity into messaging

  • Loading branch information...
commit 34d42242dae0ba061dc69b629e00f6d108baa871 1 parent 9ada64b
Jonthan Moss authored
Showing with 102 additions and 104 deletions.
  1. +0 −101 amity/entity.py
  2. +102 −3 amity/messaging.py
View
101 amity/entity.py
@@ -1,101 +0,0 @@
-import socket
-
-#Get my IP for events I am sending
-SOCK = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
-SOCK.connect(('google.com', 0))
-IP = SOCK.getsockname()[0]
-
-
-class Event(object):
- """
- Base event object
- """
- _data = {
- 'values': {},
- 'headers': {}
- }
-
- def __init__(self, values=None, headers=None):
- """
- Arguments:
-
- values
- A dictionary of values
-
- headers
- A dictionary of headers
- """
- self.set_header('from', IP)
- if headers:
- for header, value in headers.items():
- self.set_header(header, value)
- if values:
- for key, value in values.items():
- self.set_value(key, value)
-
- def set_header(self, header, value):
- """
- Sets a header within the event
-
- Arguments:
-
- header
- The name of the header to set
-
- value
- The value of the header
- """
- self._data['headers'][header] = value
- return self
-
- def get_header(self, header):
- """
- Gets the value of the specified header
- """
- value = None
- if header in self._data['headers']:
- value = self._data['headers'][header]
- return value
-
- def get_headers(self):
- """
- Returns a dictionary of all headers
- """
- return self._data['headers']
-
- def set_value(self, key, value):
- """
- Sets a value within the event
-
- Arguments:
-
- key
- The name of the key to set
-
- value
- The value of the key
- """
- self._data['values'][key] = value
- return self
-
- def get_value(self, key):
- """
- Gets the value of the specified key
- """
- value = None
- if key in self._data['values']:
- value = self._data['values'][key]
- return value
-
- def get_values(self):
- """
- Returns a dictionary of all values
- """
- return self._data['values']
-
- @property
- def data(self):
- """
- Returns the entire data dictionary for this event
- """
- return self._data
View
105 amity/messaging.py
@@ -1,10 +1,109 @@
-from amity.entity import Event
from kombu.connection import BrokerConnection
from kombu.messaging import Exchange, Queue, Producer, Consumer
from os import getpid
-from socket import timeout as socket_timeout
+import socket
import uuid
+#Get my IP for events I am sending
+SOCK = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+SOCK.connect(('google.com', 0))
+IP = SOCK.getsockname()[0]
+
+
+class Event(object):
+ """
+ Base event object
+ """
+ _data = {
+ 'values': {},
+ 'headers': {}
+ }
+
+ def __init__(self, values=None, headers=None):
+ """
+ Arguments:
+
+ values
+ A dictionary of values
+
+ headers
+ A dictionary of headers
+ """
+ self.set_header('from', IP)
+ if headers:
+ for header, value in headers.items():
+ self.set_header(header, value)
+ if values:
+ for key, value in values.items():
+ self.set_value(key, value)
+
+ def set_header(self, header, value):
+ """
+ Sets a header within the event
+
+ Arguments:
+
+ header
+ The name of the header to set
+
+ value
+ The value of the header
+ """
+ self._data['headers'][header] = value
+ return self
+
+ def get_header(self, header):
+ """
+ Gets the value of the specified header
+ """
+ value = None
+ if header in self._data['headers']:
+ value = self._data['headers'][header]
+ return value
+
+ def get_headers(self):
+ """
+ Returns a dictionary of all headers
+ """
+ return self._data['headers']
+
+ def set_value(self, key, value):
+ """
+ Sets a value within the event
+
+ Arguments:
+
+ key
+ The name of the key to set
+
+ value
+ The value of the key
+ """
+ self._data['values'][key] = value
+ return self
+
+ def get_value(self, key):
+ """
+ Gets the value of the specified key
+ """
+ value = None
+ if key in self._data['values']:
+ value = self._data['values'][key]
+ return value
+
+ def get_values(self):
+ """
+ Returns a dictionary of all values
+ """
+ return self._data['values']
+
+ @property
+ def data(self):
+ """
+ Returns the entire data dictionary for this event
+ """
+ return self._data
+
class Emitter(object):
"""
@@ -160,7 +259,7 @@ def listen(self):
while True:
try:
self.connection.drain_events(timeout=10)
- except socket_timeout:
+ except socket.timeout:
pass
class Responder(Listener):
Please sign in to comment.
Something went wrong with that request. Please try again.