Skip to content

Commit

Permalink
Remove trailing whitespace.
Browse files Browse the repository at this point in the history
  • Loading branch information
timabbott committed Nov 28, 2012
1 parent 1009c05 commit 2c4c55c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 48 deletions.
12 changes: 6 additions & 6 deletions _zephyr.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down
56 changes: 28 additions & 28 deletions _zephyr.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ZUid(object):
"""
A per-transaction unique ID for zephyrs
"""

def __init__(self):
self.address = ''
self.time = 0
Expand All @@ -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
Expand All @@ -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 *:
Expand All @@ -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)
Expand All @@ -103,15 +103,15 @@ 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:
p_notice.message = PyString_FromStringAndSize(notice.z_message, notice.z_message_len)

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:
Expand All @@ -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)
Expand All @@ -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)

Expand All @@ -145,12 +145,12 @@ def initialize():

def openPort():
cdef unsigned short port

port = 0

errno = ZOpenPort(&port)
__error(errno)

return port

def getFD():
Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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
Expand Down
28 changes: 14 additions & 14 deletions zephyr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand All @@ -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)

0 comments on commit 2c4c55c

Please sign in to comment.