MCPcopy Create free account
hub / github.com/cdgriffith/Box / Box

Class Box

box/box.py:290–1649  ·  view source on GitHub ↗

Improved dictionary access through dot notation with additional tools. :param default_box: Similar to defaultdict, return a default value :param default_box_attr: Specify the default replacement. WARNING: If this is not the default 'Box', it will not be recursive :param def

Source from the content-addressed store, hash-verified

288
289
290class Box(dict):
291 """
292 Improved dictionary access through dot notation with additional tools.
293
294 :param default_box: Similar to defaultdict, return a default value
295 :param default_box_attr: Specify the default replacement.
296 WARNING: If this is not the default 'Box', it will not be recursive
297 :param default_box_none_transform: When using default_box, treat keys with none values as absent. True by default
298 :param default_box_create_on_get: On lookup of a key that doesn't exist, also store the default value.
299 False by default: lookups never change the Box, assigning through a missing key still creates it
300 :param frozen_box: After creation, the box cannot be modified
301 :param camel_killer_box: Convert CamelCase to snake_case
302 :param camel_killer_box_keep_keys: With camel_killer_box, keep the original keys and only add
303 snake_case attribute aliases for them (needs conversion_box)
304 :param conversion_box: Check for near matching keys as attributes
305 :param modify_tuples_box: Recreate incoming tuples with dicts into Boxes
306 :param box_safe_prefix: Conversion box prefix for unsafe attributes
307 :param box_duplicates: "ignore", "error" or "warn" when duplicates exists in a conversion_box
308 :param box_intact_types: tuple of types to ignore converting
309 :param box_recast: cast certain keys to a specified type
310 :param box_dots: access nested Boxes by period separated keys in string
311 :param box_dots_exclude: optional regular expression for dotted keys to exclude
312 :param box_class: change what type of class sub-boxes will be created as
313 :param box_namespace: the namespace this (possibly nested) Box lives within
314
315 Subclasses may set ``_box_internal_attrs`` to a tuple of attribute names that are stored on
316 the instance instead of in the dict data (see ``_box_internal_attrs`` below).
317 """
318
319 _box_config: dict[str, Any]
320
321 #: Names that subclasses can list to keep "internal-only" attributes.
322 #: Setting or deleting one of these names with attribute access stores it on the
323 #: instance (``object.__setattr__``) rather than in the dict data, so it is never
324 #: exported, iterated, compared or hashed. See the "Internal Attributes" docs.
325 _box_internal_attrs: tuple[str, ...] = ()
326
327 #: Box options this class uses when they are not passed explicitly, for example
328 #: ``_box_defaults = {"default_box": True}``. Subclasses inherit and extend them.
329 #: See the "Subclassing Box" docs.
330 _box_defaults: dict[str, Any] = {}
331 _box_resolved_defaults: dict[str, Any] = {}
332
333 _protected_keys = [
334 "to_dict",
335 "to_json",
336 "to_yaml",
337 "from_yaml",
338 "from_json",
339 "from_toml",
340 "to_toml",
341 "to_msgpack",
342 "from_msgpack",
343 "to_toon",
344 "from_toon",
345 "merge_update",
346 "get_comment",
347 "set_comment",

Calls

no outgoing calls