From ee51997334672b2d4a4813c4e4ae2e4a21683fa7 Mon Sep 17 00:00:00 2001 From: Scott Bahling Date: Wed, 14 Sep 2016 12:11:47 +0200 Subject: Implement locking api; refactor ObsSourceApi get/put/post calls --- obsapi/null.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 obsapi/null.py (limited to 'obsapi/null.py') diff --git a/obsapi/null.py b/obsapi/null.py new file mode 100644 index 0000000..bbfce6e --- /dev/null +++ b/obsapi/null.py @@ -0,0 +1,42 @@ +# -*- coding: utf-8 -*- +""" + Null object + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + Simple implementation of the Null Object Pattern. + Taken from "Implementing the Null Object Pattern" recipe from + the Python CookBook. + + :url: https://www.safaribooksonline.com/library/view/python-cookbook/0596001673/ch05s24.html + :credit: Dinu C. Gherman + + :copyright: Copyright (c) 2012-2015 Scott Bahling, SUSE Linux GmbH + :license: GPL-2.0, see COPYING for details +""" + + +class Null: + """ Null objects always and reliably "do nothing." """ + + def __init__(self, *args, **kwargs): + pass + + def __call__(self, *args, **kwargs): + return self + + def __repr__(self): + return "Null( )" + + def __str__(self): + return "" + + def __nonzero__(self): + return 0 + + def __getattr__(self, name): + return self + + def __setattr__(self, name, value): + return self + + def __delattr__(self, name): + return self -- cgit v1.2.3