Commits

Zhang Huangbin committed e32d93b

Code cleanup.

Comments (0)

Files changed (1)

 
 
 class PolicyChannel(asynchat.async_chat):
+    """Process each smtp policy request"""
     def __init__(self,
                  conn,
                  plugins=[],
 
     def found_terminator(self):
         if self.buffer:
+            # Format received data
             line = self.buffer.pop()
             logging.debug("smtp session: " + line)
-            if line.find('=') != -1:
-                key = line.split('=')[0]
-                value = line.split('=', 1)[1]
+            if '=' in line:
+                (key, value) = line.split('=', 1)
                 self.smtp_session_data[key] = value
         elif len(self.smtp_session_data) != 0:
             try:
                 modeler = Modeler()
-                result = modeler.handle_data(smtp_session_data=self.smtp_session_data,
-                                             plugins=self.plugins,
-                                             plugins_for_sender=self.plugins_for_sender,
-                                             plugins_for_recipient=self.plugins_for_recipient,
-                                             plugins_for_misc=self.plugins_for_misc,
-                                             sender_search_attrlist=self.sender_search_attrlist,
-                                             recipient_search_attrlist=self.recipient_search_attrlist,
-                                            )
+                result = modeler.handle_data(
+                    smtp_session_data=self.smtp_session_data,
+                    plugins=self.plugins,
+                    plugins_for_sender=self.plugins_for_sender,
+                    plugins_for_recipient=self.plugins_for_recipient,
+                    plugins_for_misc=self.plugins_for_misc,
+                    sender_search_attrlist=self.sender_search_attrlist,
+                    recipient_search_attrlist=self.recipient_search_attrlist,
+                )
                 if result:
                     action = result
                 else:
 
 
 class DaemonSocket(asyncore.dispatcher):
+    """Create socket daemon"""
     def __init__(self, localaddr):
         asyncore.dispatcher.__init__(self)
         self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
         for plugin in settings.plugins:
             try:
                 self.loaded_plugins.append(__import__(plugin))
-                logging.info('Loading plugin: %s' % (plugin))
+                logging.info('Loading plugin: %s' % plugin)
             except Exception, e:
                 logging.error('Error while loading plugin (%s): %s' % (plugin, str(e)))
 
     def handle_accept(self):
         conn, remote_addr = self.accept()
         logging.debug("Connect from %s, port %s." % remote_addr)
-        channel = PolicyChannel(
+        PolicyChannel(
             conn,
             plugins=self.loaded_plugins,
             plugins_for_sender=self.plugins_for_sender,
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.