Moved Closing from hooke.driver.jpk to hooke.util.util
authorW. Trevor King <wking@drexel.edu>
Thu, 17 Jun 2010 19:52:31 +0000 (15:52 -0400)
committerW. Trevor King <wking@drexel.edu>
Thu, 17 Jun 2010 19:52:31 +0000 (15:52 -0400)
hooke/driver/jpk.py
hooke/util/util.py [new file with mode: 0644]

index 8879c85d3d3f5fab326aaac0bf4a9be73ab209d8..218e4b897d21aa206b7afb750da7636e47ee4f23 100644 (file)
@@ -28,29 +28,10 @@ import numpy
 
 from .. import curve as curve
 from .. import experiment as experiment
+from ..util.util import Closing as Closing
 from . import Driver as Driver
 
 
-class Closing (object):
-    """Add .__enter__() .__exit__() for `with` statements.
-
-    See :pep:`343`.
-    """
-    def __init__(self, obj):
-        self.obj = obj
-
-    def __enter__(self):
-        return self.obj
-
-    def __exit__(self, *exc_info):
-        try:
-            close_it = self.obj.close
-        except AttributeError:
-            pass
-        else:
-            close_it()
-
-
 class JPKDriver (Driver):
     """Handle JPK ForceRobot's data format.
     """
@@ -70,9 +51,9 @@ class JPKDriver (Driver):
                 headlines = []
                 for i in range(3):
                     headlines.append(f.readline())
-                if headlines[0].startswith('# xPosition') \
-                        and headlines[1].startswith('# yPosition'):
-                    return True
+            if headlines[0].startswith('# xPosition') \
+                    and headlines[1].startswith('# yPosition'):
+                return True
         return False
 
     def read(self, path, info=None):
diff --git a/hooke/util/util.py b/hooke/util/util.py
new file mode 100644 (file)
index 0000000..49b0a21
--- /dev/null
@@ -0,0 +1,21 @@
+# Copyright
+
+
+class Closing (object):
+    """Add .__enter__() .__exit__() for `with` statements.
+
+    See :pep:`343`.
+    """
+    def __init__(self, obj):
+        self.obj = obj
+
+    def __enter__(self):
+        return self.obj
+
+    def __exit__(self, *exc_info):
+        try:
+            close_it = self.obj.close
+        except AttributeError:
+            pass
+        else:
+            close_it()