[Checkins] SVN: zope.app.wsgi/trunk/src/zope/app/wsgi/__init__.py provide a user name for use in logs

Alex Chapman achapman at zope.com
Tue Mar 31 14:16:56 EDT 2009


Log message for revision 98707:
  provide a user name for use in logs

Changed:
  U   zope.app.wsgi/trunk/src/zope/app/wsgi/__init__.py

-=-
Modified: zope.app.wsgi/trunk/src/zope/app/wsgi/__init__.py
===================================================================
--- zope.app.wsgi/trunk/src/zope/app/wsgi/__init__.py	2009-03-31 18:14:18 UTC (rev 98706)
+++ zope.app.wsgi/trunk/src/zope/app/wsgi/__init__.py	2009-03-31 18:16:55 UTC (rev 98707)
@@ -55,6 +55,11 @@
 
         request = publish(request, handle_errors=handle_errors)
         response = request.response
+        try:
+            environ['wsgi.user_name'] = format_login(
+                request.principal.info.login) 
+        except AttributeError:
+            pass
 
         # Start the WSGI server response
         start_response(response.getStatusString(), response.getHeaders())
@@ -63,6 +68,13 @@
         return response.consumeBodyIter()
 
 
+# Defensive against ids with whitespace
+def format_login(login):
+    if login != login.replace(' ',''):
+        login = '"'+login+'"'
+    return login
+
+
 class PMDBWSGIPublisherApplication(WSGIPublisherApplication):
 
     def __init__(self, db=None, factory=HTTPPublicationRequestFactory,



More information about the Checkins mailing list