Commits

ViciousRedBeam committed 9a79553 Merge

Merged in msabramo/memcacheliked/pep8_python3 (pull request #5)

Miscellaneous PEP8 and Python 3 (print function) cleanup

  • Participants
  • Parent commits 2ce988a, a349668

Comments (0)

Files changed (2)

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)
-

memcacheliked/sample.py

 
 from . import Memcacheliked, retrieval_command, storage_command, deletion_command, STORAGE_STATUS_STORED, DELETION_STATUS_DELETED, DELETION_STATUS_NOT_FOUND
 
+
 class SampleServer(Memcacheliked):
     def __init__(self):
         Memcacheliked.__init__(self)
 
     @retrieval_command
     def command_get(self, command_name, *keys):
-        print 'getting keys <%s>' % (keys,)
+        print('getting keys <%s>' % (keys,))
         return [(k, self.flags.get(k), self.data.get(k)) for k in keys]
 
     @storage_command
     def command_set(self, command_name, key, flags, exptime, value, *opts):
-        print 'setting key <%s> to <%s>' % (key, value,)
+        print('setting key <%s> to <%s>' % (key, value,))
         self.data[key] = value
         self.flags[key] = flags
         return STORAGE_STATUS_STORED
-    
+
     @deletion_command
     def command_delete(self, command_name, key, *opts):
-        print 'deleting key <%s>' % (key,)
+        print('deleting key <%s>' % (key,))
         if key not in self.data:
             return DELETION_STATUS_NOT_FOUND
         del self.data[key]
         del self.flags[key]
         return DELETION_STATUS_DELETED
-    
+
+
 if __name__ == "__main__":
     SampleServer().start()
-