From: W. Trevor King Date: Thu, 17 Jun 2010 19:52:31 +0000 (-0400) Subject: Moved Closing from hooke.driver.jpk to hooke.util.util X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=9a938c3ae16a34346f4eded372c818b855332836;p=hooke.git Moved Closing from hooke.driver.jpk to hooke.util.util --- diff --git a/hooke/driver/jpk.py b/hooke/driver/jpk.py index 8879c85..218e4b8 100644 --- a/hooke/driver/jpk.py +++ b/hooke/driver/jpk.py @@ -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 index 0000000..49b0a21 --- /dev/null +++ b/hooke/util/util.py @@ -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()