blob: bbfce6eaf2f8316dc07629ff79a920fdd2ebfe0a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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
|