Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Remove trailing whitespace.

  • Loading branch information...
commit 2c4c55c1cc6044dee74532606c729a6730f93a28 1 parent 1009c05
@timabbott timabbott authored
Showing with 48 additions and 48 deletions.
  1. +6 −6 _zephyr.pxd
  2. +28 −28 _zephyr.pyx
  3. +14 −14 zephyr.py
View
12 _zephyr.pxd
@@ -27,16 +27,16 @@ cdef extern from "zephyr/zephyr.h":
SERVNAK,
CLIENTACK,
STAT
-
+
enum _ZAuth_Levels:
ZAUTH_FAILED,
ZAUTH_YES,
ZAUTH_NO
-
+
ctypedef struct ZUnique_Id_t:
in_addr zuid_addr
timeval tv
-
+
ctypedef struct ZNotice_t:
char * z_packet
char * z_version
@@ -61,15 +61,15 @@ cdef extern from "zephyr/zephyr.h":
char * z_other_fields[10]
char * z_message
int z_message_len
-
+
ctypedef struct ZSubscription_t:
char * zsub_recipient
char * zsub_class
char * zsub_classinst
-
+
int (*ZAUTH)()
int (*ZNOAUTH)()
-
+
int ZInitialize()
int ZOpenPort(unsigned short * port)
int ZGetFD()
View
56 _zephyr.pyx
@@ -23,7 +23,7 @@ class ZUid(object):
"""
A per-transaction unique ID for zephyrs
"""
-
+
def __init__(self):
self.address = ''
self.time = 0
@@ -41,12 +41,12 @@ class ZNotice(object):
"""
A zephyr message
"""
-
+
def __init__(self, **options):
self.kind = ACKED
self.cls = 'message'
self.instance = 'personal'
-
+
self.uid = ZUid()
self.time = 0
self.port = 0
@@ -57,34 +57,34 @@ class ZNotice(object):
self.format = "Class $class, Instance $instance:\nTo: @bold($recipient) at $time $date\nFrom: @bold{$1 <$sender>}\n\n$2"
self.other_fields = []
self.fields = []
-
+
for k, v in options.iteritems():
setattr(self, k, v)
-
+
def getmessage(self):
return '\0'.join(self.fields)
-
+
def setmessage(self, newmsg):
self.fields = newmsg.split('\0')
-
+
message = property(getmessage, setmessage)
-
+
def send(self):
cdef ZNotice_t notice
_ZNotice_p2c(self, &notice)
-
+
original_message = self.message
-
+
if self.auth:
errno = ZSendNotice(&notice, ZAUTH)
else:
errno = ZSendNotice(&notice, ZNOAUTH)
__error(errno)
-
+
_ZNotice_c2p(&notice, self)
-
+
self.message = original_message
-
+
ZFreeNotice(&notice)
cdef void _ZNotice_c2p(ZNotice_t * notice, object p_notice) except *:
@@ -93,7 +93,7 @@ cdef void _ZNotice_c2p(ZNotice_t * notice, object p_notice) except *:
p_notice.time = notice.z_time.tv_sec + (notice.z_time.tv_usec / 100000.0)
p_notice.port = int(notice.z_port)
p_notice.auth = bool(notice.z_auth)
-
+
p_notice.cls = _string_c2p(notice.z_class)
p_notice.instance = _string_c2p(notice.z_class_inst)
p_notice.recipient = _string_c2p(notice.z_recipient)
@@ -103,7 +103,7 @@ cdef void _ZNotice_c2p(ZNotice_t * notice, object p_notice) except *:
p_notice.other_fields = list()
for i in range(notice.z_num_other_fields):
p_notice.other_fields.append(notice.z_other_fields[i])
-
+
if notice.z_message is NULL:
p_notice.message = None
else:
@@ -111,7 +111,7 @@ cdef void _ZNotice_c2p(ZNotice_t * notice, object p_notice) except *:
cdef void _ZNotice_p2c(object notice, ZNotice_t * c_notice) except *:
memset(c_notice, 0, sizeof(ZNotice_t))
-
+
c_notice.z_kind = notice.kind
_ZUid_p2c(notice.uid, &c_notice.z_uid)
if notice.time != 0:
@@ -120,7 +120,7 @@ cdef void _ZNotice_p2c(object notice, ZNotice_t * c_notice) except *:
if notice.port != 0:
c_notice.z_port = notice.port
c_notice.z_auth = int(notice.auth)
-
+
c_notice.z_class = _string_p2c(notice.cls)
c_notice.z_class_inst = _string_p2c(notice.instance)
c_notice.z_recipient = _string_p2c(notice.recipient)
@@ -130,12 +130,12 @@ cdef void _ZNotice_p2c(object notice, ZNotice_t * c_notice) except *:
c_notice.z_num_other_fields = len(notice.other_fields)
for i in range(c_notice.z_num_other_fields):
c_notice.z_other_fields[i] = _string_p2c(notice.other_fields[i])
-
+
if isinstance(notice.message, unicode):
notice.encoded_message = notice.message.encode('utf-8')
else:
notice.encoded_message = notice.message
-
+
c_notice.z_message = _string_p2c(notice.encoded_message)
c_notice.z_message_len = len(notice.encoded_message)
@@ -145,12 +145,12 @@ def initialize():
def openPort():
cdef unsigned short port
-
+
port = 0
-
+
errno = ZOpenPort(&port)
__error(errno)
-
+
return port
def getFD():
@@ -162,11 +162,11 @@ def setFD(fd):
def sub(cls, instance, recipient):
cdef ZSubscription_t newsub[1]
-
+
newsub[0].zsub_class = cls
newsub[0].zsub_classinst = instance
newsub[0].zsub_recipient = recipient
-
+
errno = ZSubscribeTo(newsub, 1, 0)
__error(errno)
@@ -190,11 +190,11 @@ def subAll(lst):
def unsub(cls, instance, recipient):
cdef ZSubscription_t delsub[1]
-
+
delsub[0].zsub_class = cls
delsub[0].zsub_classinst = instance
delsub[0].zsub_recipient = recipient
-
+
errno = ZUnsubscribeTo(delsub, 1, 0)
__error(errno)
@@ -213,12 +213,12 @@ def receive(block=False):
errno = ZReceiveNotice(&notice, &sender)
__error(errno)
-
+
if ZCheckAuthentication(&notice, &sender) == ZAUTH_YES:
notice.z_auth = 1
else:
notice.z_auth = 0
-
+
p_notice = ZNotice()
_ZNotice_c2p(&notice, p_notice)
return p_notice
View
28 zephyr.py
@@ -17,7 +17,7 @@ class Subscriptions(set):
"""
A set of <class, instance, recipient> tuples representing the
tuples that have been subbed to
-
+
Since subscriptions are shared across the entire process, this
class is a singleton
"""
@@ -26,40 +26,40 @@ def __new__(cls):
cls._instance = super(Subscriptions, cls).__new__(cls)
init()
return cls._instance
-
+
def __del__(self):
_z.cancelSubs()
super(Subscriptions, self).__del__()
-
+
def _fixTuple(self, item):
if len(item) != 3:
raise TypeError, 'item is not a zephyr subscription tuple'
-
+
item = list(item)
if item[2].startswith('*'):
item[2] = item[2][1:]
-
+
if '@' not in item[2]:
item[2] += '@%s' % _z.realm()
-
+
return tuple(item)
-
+
def add(self, item):
item = self._fixTuple(item)
-
+
if item in self:
return
-
+
_z.sub(*item)
-
+
super(Subscriptions, self).add(item)
-
+
def remove(self, item):
item = self._fixTuple(item)
-
+
if item not in self:
raise KeyError, item
-
+
_z.unsub(*item)
-
+
super(Subscriptions, self).remove(item)
Please sign in to comment.
Something went wrong with that request. Please try again.