]> git.llucax.com Git - software/pymin.git/commitdiff
Make magic methods of procman.ProcessManager aliases of normal methods.
authorLeandro Lucarella <llucax@gmail.com>
Mon, 19 May 2008 03:42:52 +0000 (00:42 -0300)
committerLeandro Lucarella <llucax@gmail.com>
Wed, 21 May 2008 16:01:57 +0000 (13:01 -0300)
Add a simple testcase too.

pymin/procman.py

index 170d29093b8811670b5a0f29737af6fd596291e5..554fdbada88629222e889b77d6b01b180caeab63 100644 (file)
@@ -185,6 +185,8 @@ class ProcessManager:
             if name in self.pidmap:
                 return self.pidmap[name]
         raise KeyError, name
+    # Syntax sugar for self[name]
+    __getitem__ = get
 
     def has(self, name):
         if isinstance(name, basestring): # is a name
@@ -196,12 +198,8 @@ class ProcessManager:
             if name in self.pidmap:
                 return True
         return False
-
-    def __getitem__(self, name):
-        return self.get(name)
-
-    def __contains__(self, name):
-        return self.has(name)
+    # Syntax sugar for name in self
+    __contains__ = has
 
 
 if __name__ == '__main__':
@@ -257,6 +255,9 @@ if __name__ == '__main__':
     assert 'test-service' in manager.services
     assert 'test-service' not in manager.namemap
     assert not get('test-service').running
+    assert manager['test-service'] == get('test-service')
+    assert has('test-service')
+    assert 'test-service' in manager
 
     register('test-service-2', ('sleep', '3'), notify, False)
     assert 'test-service-2' in manager.services