Commits

Anonymous committed a349668

More PEP8 tweaks

Comments (0)

Files changed (1)

memcacheliked/__init__.py

 STORAGE_STATUS_NOT_STORED = 'NOT_STORED'
 STORAGE_STATUS_EXISTS = 'EXISTS'
 STORAGE_STATUS_NOT_FOUND = 'NOT_FOUND'
-STORAGE_STATUSES = set([STORAGE_STATUS_STORED, STORAGE_STATUS_NOT_STORED, STORAGE_STATUS_EXISTS, STORAGE_STATUS_NOT_FOUND])
+STORAGE_STATUSES = set([
+    STORAGE_STATUS_STORED, STORAGE_STATUS_NOT_STORED, STORAGE_STATUS_EXISTS,
+    STORAGE_STATUS_NOT_FOUND])
 
 DELETION_STATUS_DELETED = 'DELETED'
 DELETION_STATUS_NOT_FOUND = 'NOT_FOUND'
 
 VALUE_READ_TIMEOUT = 60
 
-class ClientError(Exception): pass
-class ServerError(Exception): pass
+
+class ClientError(Exception):
+    pass
+
+
+class ServerError(Exception):
+    pass
+
 
 class Memcacheliked(object):
+
     """Abstract memcache interface object
 
     Inherit this class and implement command_* methods. Each needs
     verify / process the arguments properly.
     """
 
-    def __init__(self, timeout=60*60):
+    def __init__(self, timeout=60 * 60):
         self.timeout = timeout
 
     def _connection_handler(self, address):
         try:
             log.info('got incoming connection from <%s>' % (address,))
             while True:
-                ev, msg = first(until_eol = True, sleep = self.timeout)
+                ev, msg = first(until_eol=True, sleep=self.timeout)
                 if ev == 'sleep':
                     log.warn('connection to <%s> timed out' % (address,))
                     break
         self.app.add_service(Service(self._connection_handler, port))
         self.app.run()
 
+
 def ident(*args):
     return args
 
 
     @storage_command
     def command_set(self, command_name, key, flags, exptime, value, *opts):
-    
+
     Expected return type: one of STORAGE_STATUS_*
     """
 
     def process_storage_status(res):
-        if res not in STORAGE_STATUSES: 
+        if res not in STORAGE_STATUSES:
             raise ServerError("internal error")
         else:
             send(res + "\r\n")
 
     def add_value(*elements):
-        ev, msg = first(receive = int(elements[5])+2, sleep = VALUE_READ_TIMEOUT)
+        ev, msg = first(
+            receive=int(elements[5]) + 2, sleep=VALUE_READ_TIMEOUT)
         if ev == 'sleep':
             raise ClientError("reading timed out")
         else:
             new_elements[5] = msg[:-2]
             return tuple(new_elements)
 
-    return _register_command(f, process_storage_status, process_values=add_value, min_args=5)
+    return _register_command(
+        f, process_storage_status, process_values=add_value, min_args=5)
+
 
 def retrieval_command(f):
     """Decorator for retrieval commands (get...)
             # format each returned value
             for row in res:
                 if type(row) != tuple or len(row) < 3:
-                    log.crit("Engine didn't return proper tuple, but <%s> - skipping" % (row,))
+                    log.crit(
+                        "Engine didn't return proper tuple, but "
+                        "<%s> - skipping"
+                        % (row,))
                 elif row[2] is not None:
-                    send('VALUE %s %s %i%s\r\n%s\r\n' % (row[0], row[1], len(row[2]), '' if len(row)<4 else ' '+row[3], row[2]))
+                    send('VALUE %s %s %i%s\r\n%s\r\n' %
+                        (row[0], row[1], len(row[2]), ''
+                         if len(row) < 4 else ' ' + row[3], row[2]))
                 else:
                     pass
                     # key not present, no answer
             send('END\r\n')
-                    
+
     return _register_command(f, format_values, min_args=2)
 
+
 def deletion_command(f):
     """Decorator for deletion commands (delete...)
     Actual processing function can look like this:
 
     @deletion_command
     def command_delete(self, command_name, key, *opts):
-    
+
     Expected return type: one of DELETION_STATUS_*
     """
 
     def process_result(res):
-        if res not in DELETION_STATUSES: 
+        if res not in DELETION_STATUSES:
             raise ServerError("internal error")
         else:
             send(res + "\r\n")
     return _register_command(f, process_result, min_args=2)
-
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.