[Zope-Checkins] CVS: Zope3/lib/python/Zope/Server/LineReceiver - LineServerChannel.py:1.1.2.3

Stephan Richter srichter@cbu.edu
Fri, 5 Apr 2002 10:18:48 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/Server/LineReceiver
In directory cvs.zope.org:/tmp/cvs-serv20940/LineReceiver

Modified Files:
      Tag: Zope3-Server-Branch
	LineServerChannel.py 
Log Message:
Changed Status messages mechanism.


=== Zope3/lib/python/Zope/Server/LineReceiver/LineServerChannel.py 1.1.2.2 => 1.1.2.3 ===
 
     # Define the reply code for non-authenticated responses
-    not_auth_reply = (530, 0)
+    not_auth_reply = 'LOGIN_REQUIRED'
 
     # Define the reply code for an unrecognized command
-    unknown_reply = (500, 0)
+    unknown_reply = 'CMD_UNKNOWN'
 
     # Define the status messages
     status_messages = {
-        500: ("'%s': command not understood.",),
-        530: ('Please log in with USER and PASS',)
+        'CMD_UNKNOWN'      : "500 '%s': command not understood.",
+        'LOGIN_REQUIRED'   : '530 Please log in with USER and PASS',
         }
 
 
@@ -71,7 +71,7 @@
         method = 'cmd_' + cmd.lower()
         if ( not self.authenticated and method not in self.special_commands):
             # The user is not logged in, therefore don't allow anything
-            self.reply(self.not_auth_reply[0], self.not_auth_reply[1])
+            self.reply(self.not_auth_reply)
 
         elif method in self.thread_commands:
             # Process in another thread.
@@ -81,24 +81,17 @@
             getattr(self, method)(command.args)
 
         else:
-            self.reply(self.unknown_reply[0],
-                       self.unknown_reply[1], cmd.upper())
+            self.reply(self.unknown_reply, cmd.upper())
 
 
-    def reply(self, code, pos=0, args=(), flush=1):
+    def reply(self, code, args=(), flush=1):
         """ """
         try:
-            msg = self.status_messages[code][pos] %args
+            msg = self.status_messages[code] %args
         except:
-            msg = 'The server created a bad response type (code %i).' %code
-            code = 500
+            msg = '500 Unknown Response: %i.' %code
 
-        if msg.startswith('-'):
-            fill = ''
-        else:
-            fill = ' '
-
-        self.write('%i%s%s\r\n' %(code, fill, msg))
+        self.write('%s\r\n' %msg)
 
         if flush:
             self.flush(0)