[Zodb-checkins] CVS: Packages/ZEO - smac.py:1.9.6.5
jeremy@digicool.com
jeremy@digicool.com
Mon, 7 May 2001 09:10:39 -0400 (EDT)
Update of /cvs-repository/Packages/ZEO
In directory korak:/tmp/cvs-serv20721
Modified Files:
Tag: ZEO-ZRPC-Dev
smac.py
Log Message:
Various small changes.
Swap order of if/elif, because one is far more common.
Delete unused _handle_read() -- was a variant implementation of
handle_read.
Put debugging output in message_output() under if __debug__.
Remove unused log_info and log methods.
--- Updated File smac.py in package Packages/ZEO --
--- smac.py 2001/04/20 19:14:08 1.9.6.4
+++ smac.py 2001/05/07 13:10:37 1.9.6.5
@@ -142,10 +142,10 @@
return # keep waiting for more input
# load all previous input and d into single string inp
- if inp is None:
- inp = d
- elif type(inp) is StringType:
+ if isinstance(inp, StringType):
inp = inp + d
+ elif inp is None:
+ inp = d
else:
inp.append(d)
inp = string.join(inp, '')
@@ -156,15 +156,7 @@
offset = offset + msg_size
if state is None:
# waiting for message
- try:
- msg_size = struct.unpack(">i", msg)[0]
- except:
- # XXX
- print 'unpack(">i", %s)' % repr(msg)
- print "state = %s" % state
- print "msg_size = %(msg_size)d, "\
- "input_len= %(input_len)d" % locals()
- raise
+ msg_size = struct.unpack(">i", msg)[0]
state = 1
else:
msg_size = 4
@@ -176,45 +168,6 @@
self.__inp = inp[offset:]
self.__input_len = input_len - offset
- def _handle_read(self):
- d = self.recv(self.READ_SIZE)
- if not d:
- return
-
- inp = self.__inp
- if inp is None:
- inp = d
- elif type(inp) is StringType:
- inp = [inp, d]
- else:
- inp.append(d)
-
- input_len = self.__input_len + len(d)
- msg_size = self.__msg_size
-
- while 1:
- if msg_size <= input_len:
- # Woo hoo, we have enough data
- if type(inp) is not StringType:
- inp = ''.join(inp)
- d = inp[:msg_size]
- inp = inp[msg_size:]
- input_len = input_len - msg_size
- if self.__state is None:
- # waiting for message
- msg_size = struct.unpack(">i", d)[0]
- self.__state = 1
- else:
- msg_size = 4
- self.__state = None
- self.message_input(d)
- else:
- break # not enough data
-
- self.__msg_size = msg_size
- self.__inp = inp
- self.__input_len = input_len
-
def readable(self):
return 1
@@ -239,12 +192,13 @@
self.close()
def message_output(self, message):
- if self._debug:
- if len(message) > 40:
- m = message[:40]+' ...'
- else:
- m = message
- LOG(self._debug, TRACE, 'message_output %s' % `m`)
+ if __debug__:
+ if self._debug:
+ if len(message) > 40:
+ m = message[:40]+' ...'
+ else:
+ m = message
+ LOG(self._debug, TRACE, 'message_output %s' % `m`)
if self.__closed is not None:
raise Disconnected, (
@@ -254,15 +208,6 @@
# do two separate appends to avoid copying the message string
self.__output.append(struct.pack(">i", len(message)))
self.__output.append(message)
-
- def log_info(self, message, type='trace'):
- if type == 'error':
- type = ERROR
- else:
- type = TRACE
- LOG('ZEO', type, message)
-
- log = log_info
def close(self):
if self.__closed is None: