From 9a938c3ae16a34346f4eded372c818b855332836 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Thu, 17 Jun 2010 15:52:31 -0400 Subject: [PATCH] Moved Closing from hooke.driver.jpk to hooke.util.util --- hooke/driver/jpk.py | 27 ++++----------------------- hooke/util/util.py | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+), 23 deletions(-) create mode 100644 hooke/util/util.py 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() -- 2.26.2