summaryrefslogtreecommitdiff
path: root/obsapi/null.py
diff options
context:
space:
mode:
Diffstat (limited to 'obsapi/null.py')
-rw-r--r--obsapi/null.py42
1 files changed, 42 insertions, 0 deletions
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