Package yapydata :: Package datatree :: Module synjson4627

Source Code for Module yapydata.datatree.synjson4627

  1  # -*- coding: utf-8 -*- 
  2  """The *YapyData.json4627* module provides *JSON* access in compliance to RFC-4627 [RFC4627]_. 
  3  """ 
  4   
  5  from yapydata.datatree.synjson import DataTreeJSON, YapyDataJSONError 
  6   
  7  __author__ = 'Arno-Can Uestuensoez' 
  8  __license__ = "Artistic-License-2.0 + Forced-Fairplay-Constraints" 
  9  __copyright__ = "Copyright (C) 2019 Arno-Can Uestuensoez" \ 
 10                  " @Ingenieurbuero Arno-Can Uestuensoez" 
 11  __version__ = '0.1.1' 
 12  __uuid__ = "60cac28d-efe6-4a8d-802f-fa4fc94fa741" 
 13   
 14  __docformat__ = "restructuredtext en" 
15 16 17 -class YapyDataJSON4627Error(YapyDataJSONError):
18 """Basic JSON syntax error. 19 """ 20 pass
21
22 23 -class DataTreeJSON4627(DataTreeJSON):
24 """Provides additional constraints for JSON based on RFC-4627. 25 26 The main point is here probably the required *object* or *array* 27 as the root node, while RFC-7159 permits in general values. 28 """ 29 30 @staticmethod
31 - def isvalid_top(value, **kargs):
32 """Validate conformance of top-node to RFC-4627. 33 """ 34 35 if not isinstance(value, (dict, list,)): 36 raise YapyDataJSON4627Error( 37 "top 'node' must be a valid JSON-RFC-4627 type, got: " 38 + str(type(value)) 39 )
40
41 - def __init__(self, data, **kargs):
42 """ 43 Args: 44 data: 45 Configuration data in accordance to RFC-4627:: 46 47 data := <RFC-4627-type-for-json> 48 49 RFC-4627-type-for-json := ( 50 dict | list # see: object, list 51 ) 52 53 The initial data defines the permitted type of the first item 54 within the *subpath* of the spanned data tree. 55 56 Thus atomic data types define a single node data tree only - new in RFC-7159. 57 58 Returns: 59 None / initialized object 60 61 Raises: 62 YapyDataDataTreeError 63 64 pass-through 65 66 """ 67 DataTreeJSON4627.isvalid_top(data) 68 super(DataTreeJSON4627, self).__init__(data)
69
70 - def __setattr__(self, name, value):
71 """Validates types of own data attributes. 72 73 Args: 74 name: 75 Name of the attribute. Following are reserved and 76 treated special: 77 78 * type: str - 'data' 79 The value is treated as the replacement of the internal 80 data attribute. Replaces or creates the complete data 81 of teh current instance. 82 83 value: 84 The value of the attribute. This by default superposes 85 present values by replacement. Non-present are created. 86 87 Returns: 88 89 Raises: 90 YapyDataDataTreeError 91 92 """ 93 if name == 'data': 94 # 95 # replacement of current managed data 96 # 97 DataTreeJSON4627.isvalid_top(value) 98 self.__dict__[name] = value 99 100 else: 101 # 102 # any standard attribute with standard behavior 103 # 104 return object.__setattr__(self, name, value)
105