2222 import yaml
2323 yaml_support = True
2424except ImportError :
25- yaml = None
25+ try :
26+ import ruamel .yaml as yaml
27+ yaml_support = True
28+ except ImportError :
29+ yaml = None
2630
2731if sys .version_info >= (3 , 0 ):
2832 basestring = str
2933
3034__all__ = ['Box' , 'ConfigBox' , 'LightBox' , 'BoxList' ]
3135__author__ = "Chris Griffith"
32- __version__ = "2.1 .0"
36+ __version__ = "2.2 .0"
3337
3438
3539class LightBox (dict ):
@@ -163,8 +167,8 @@ def to_dict(self, in_dict=None):
163167
164168 def to_json (self , filename = None , indent = 4 , ** json_kwargs ):
165169 """
166- Transform the Box object into a JSON string.
167-
170+ Transform the Box object into a JSON string.
171+
168172 :param filename: If provided will save to file
169173 :param indent: Automatic formatting by indent size in spaces
170174 :param json_kwargs: additional arguments to pass to json.dump(s)
@@ -181,8 +185,8 @@ def to_json(self, filename=None, indent=4, **json_kwargs):
181185 def to_yaml (self , filename = None , default_flow_style = False ,
182186 ** yaml_kwargs ):
183187 """
184- Transform the Box object into a YAML string.
185-
188+ Transform the Box object into a YAML string.
189+
186190 :param filename: If provided will save to file
187191 :param default_flow_style: False will recursively dump dicts
188192 :param yaml_kwargs: additional arguments to pass to yaml.dump
@@ -210,13 +214,12 @@ def _recursive_create(self, iterable, include_lists=False, box_class=LightBox):
210214
211215class Box (LightBox ):
212216 """
213- Same as LightBox,
217+ Same as LightBox,
214218 but also goes into lists and makes dicts within into Boxes.
215219
216220 The lists are turned into BoxLists
217221 so that they can also intercept incoming items and turn
218222 them into Boxes.
219-
220223 """
221224
222225 def __init__ (self , * args , ** kwargs ):
@@ -295,7 +298,7 @@ def update(self, item=None, **kwargs):
295298 def setdefault (self , item , default = None ):
296299 if item in self :
297300 return self [item ]
298-
301+
299302 if isinstance (default , dict ):
300303 default = Box (default )
301304 elif isinstance (default , list ):
@@ -307,7 +310,7 @@ def setdefault(self, item, default=None):
307310class BoxList (list ):
308311 """
309312 Drop in replacement of list, that converts added objects to Box or BoxList
310- objects as necessary.
313+ objects as necessary.
311314 """
312315 __box_class__ = Box
313316
@@ -363,7 +366,6 @@ class ConfigBox(LightBox):
363366 cns.bool('my_bool') # True
364367 cns.int('my_int') # 5
365368 cns.list('my_list', mod=lambda x: int(x)) # [5, 4, 3, 3, 2]
366-
367369 """
368370
369371 _protected_keys = dir ({}) + ['to_dict' , 'bool' , 'int' , 'float' ,
0 commit comments