summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--ranger/ext/openstruct.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/ranger/ext/openstruct.py b/ranger/ext/openstruct.py
index 5881fd9f..55dd0a40 100644
--- a/ranger/ext/openstruct.py
+++ b/ranger/ext/openstruct.py
@@ -1,6 +1,8 @@
 # Copyright (C) 2009-2013  Roman Zimbelmann <hut@hut.pm>
 # This software is distributed under the terms of the GNU GPL version 3.
 
+import collections
+
 # prepend __ to arguments because one might use "args"
 # or "keywords" as a keyword argument.
 
@@ -9,3 +11,16 @@ class OpenStruct(dict):
     def __init__(self, *__args, **__keywords):
         dict.__init__(self, *__args, **__keywords)
         self.__dict__ = self
+
+
+class DefaultOpenStruct(collections.defaultdict):
+    """The fusion of dict and struct, with default values"""
+    def __init__(self, *__args, **__keywords):
+        collections.defaultdict.__init__(self, None, *__args, **__keywords)
+        self.__dict__ = self
+
+    def __getattr__(self, name):
+        if name not in self.__dict__:
+            return None
+        else:
+            return self.__dict__[name]