Moved _handleCloseRequest to a new method. Added warning messages.
authormorrowa
Tue Jun 23 13:52:28 2009 -0700 (2009-06-23)
changeset 546d1392a3e0a6
parent 53 e9f209a24d53
child 55 f240f9023393
Moved _handleCloseRequest to a new method. Added warning messages.
Python/BLIP.py
     1.1 --- a/Python/BLIP.py	Tue Jun 23 12:46:40 2009 -0700
     1.2 +++ b/Python/BLIP.py	Tue Jun 23 13:52:28 2009 -0700
     1.3 @@ -161,6 +161,7 @@
     1.4                  log.debug("pendingResponses[%i] := %s",requestNo,response)
     1.5              return self._sendMessage(req)
     1.6          else:
     1.7 +            log.warning("%s: Attempt to send a request after the connection has started closing: %s" % (self, req))
     1.8              return False
     1.9      
    1.10      def _outQueueMessage(self, msg,isNew=True):
    1.11 @@ -292,21 +293,7 @@
    1.12      def _dispatchMetaRequest(self, request):
    1.13          """Handles dispatching internal meta requests."""
    1.14          if request['Profile'] == kMsgProfile_Bye:
    1.15 -            shouldClose = True
    1.16 -            if self.onCloseRequest:
    1.17 -                shouldClose = self.onCloseRequest()
    1.18 -            if not shouldClose:
    1.19 -                log.debug("Sending resfusal to close...")
    1.20 -                response = request.response
    1.21 -                response.isError = True
    1.22 -                response['Error-Domain'] = "BLIP"
    1.23 -                response['Error-Code'] = 403
    1.24 -                response.body = "Close request denied"
    1.25 -                response.send()
    1.26 -            else:
    1.27 -                log.debug("Sending permission to close...")
    1.28 -                response = request.response
    1.29 -                response.send()
    1.30 +            self._handleCloseRequest(request)
    1.31          else:
    1.32              response = request.response
    1.33              response.isError = True
    1.34 @@ -317,6 +304,24 @@
    1.35      
    1.36      ### CLOSING:
    1.37      
    1.38 +    def _handleCloseRequest(self, request):
    1.39 +        """Handles requests from a peer to close."""
    1.40 +        shouldClose = True
    1.41 +        if self.onCloseRequest:
    1.42 +            shouldClose = self.onCloseRequest()
    1.43 +        if not shouldClose:
    1.44 +            log.debug("Sending resfusal to close...")
    1.45 +            response = request.response
    1.46 +            response.isError = True
    1.47 +            response['Error-Domain'] = "BLIP"
    1.48 +            response['Error-Code'] = 403
    1.49 +            response.body = "Close request denied"
    1.50 +            response.send()
    1.51 +        else:
    1.52 +            log.debug("Sending permission to close...")
    1.53 +            response = request.response
    1.54 +            response.send()
    1.55 +    
    1.56      def close(self):
    1.57          """Publicly callable close method. Sends close request to peer."""
    1.58          if self.status != kOpen: