def to_obj(self): attr_obj = self._binding_class() attr_obj.set_valueOf_(normalize_to_xml(self.serialized_value)) # For now, don't output the datatype, as it is not required and is # usually not needed, as it can be inferred from the context. #attr_obj.set_datatype(self.datatype) if self.id_ is not None: attr_obj.set_id(self.id_) if self.idref is not None: attr_obj.set_idref(self.idref) if self.appears_random is not None: attr_obj.set_appears_random(self.appears_random) if self.is_obfuscated is not None: attr_obj.set_is_obfuscated(self.is_obfuscated) if self.obfuscation_algorithm_ref is not None: attr_obj.set_obfuscation_algorithm_ref(self.obfuscation_algorithm_ref) if self.is_defanged is not None: attr_obj.set_is_defanged(self.is_defanged) if self.defanging_algorithm_ref is not None: attr_obj.set_defanging_algorithm_ref(self.defanging_algorithm_ref) if self.refanging_transform_type is not None: attr_obj.set_refanging_transform_type(self.refanging_transform_type) if self.refanging_transform is not None: attr_obj.set_refanging_transform(self.refanging_transform) #Datatype output logic if self._force_datatype: attr_obj.set_datatype(self.datatype) else: attr_obj.set_datatype(None) PatternFieldGroup.to_obj(self, attr_obj) return attr_obj
def to_dict(self): if self.is_plain(): return self.serialized_value attr_dict = {} if self.value is not None: attr_dict['value'] = self.serialized_value if self.datatype is not None and (self.datatype != self.default_datatype): attr_dict['datatype'] = self.datatype if self.id_ is not None: attr_dict['id'] = self.id_ if self.idref is not None: attr_dict['idref'] = self.idref if self.appears_random is not None: attr_dict['appears_random'] = self.appears_random if self.is_obfuscated is not None: attr_dict['is_obfuscated'] = self.is_obfuscated if self.obfuscation_algorithm_ref is not None: attr_dict['obfuscation_algorithm_ref'] = self.obfuscation_algorithm_ref if self.is_defanged is not None: attr_dict['is_defanged'] = self.is_defanged if self.defanging_algorithm_ref is not None: attr_dict['defanging_algorithm_ref'] = self.defanging_algorithm_ref if self.refanging_transform_type is not None: attr_dict['refanging_transform_type'] = self.refanging_transform_type if self.refanging_transform is not None: attr_dict['refanging_transform'] = self.refanging_transform if self.observed_encoding is not None: attr_dict['observed_encoding'] = self.observed_encoding PatternFieldGroup.to_dict(self, attr_dict) return attr_dict
def to_dict(self): if self.is_plain(): return self.serialized_value attr_dict = {} if self.value is not None: attr_dict['value'] = self.serialized_value # For now, don't output the datatype, as it is not required and is # usually not needed, as it can be inferred from the context. #if self.datatype is not None: # attr_dict['datatype'] = self.datatype if self.id_ is not None: attr_dict['id'] = self.id_ if self.idref is not None: attr_dict['idref'] = self.idref if self.appears_random is not None: attr_dict['appears_random'] = self.appears_random if self.is_obfuscated is not None: attr_dict['is_obfuscated'] = self.is_obfuscated if self.obfuscation_algorithm_ref is not None: attr_dict['obfuscation_algorithm_ref'] = self.obfuscation_algorithm_ref if self.is_defanged is not None: attr_dict['is_defanged'] = self.is_defanged if self.defanging_algorithm_ref is not None: attr_dict['defanging_algorithm_ref'] = self.defanging_algorithm_ref if self.refanging_transform_type is not None: attr_dict['refanging_transform_type'] = self.refanging_transform_type if self.refanging_transform is not None: attr_dict['refanging_transform'] = self.refanging_transform PatternFieldGroup.to_dict(self, attr_dict) return attr_dict
def _populate_from_dict(self, attr_dict): # If this attribute is "plain", use it as the value and assume the # datatype was set correctly by the constructor of the particular # BaseProperty Subclass. if not isinstance(attr_dict, dict): self.value = attr_dict else: # This key should always be present self.value = attr_dict.get('value') # This defaults to False if missing self._force_datatype = attr_dict.get('force_datatype', False) # 'None' is fine if these keys are missing self.id_ = attr_dict.get('id') self.idref = attr_dict.get('idref') self.appears_random = attr_dict.get('appears_random') self.datatype = attr_dict.get('datatype') self.is_obfuscated = attr_dict.get('is_obfuscated') self.obfuscation_algorithm_ref = attr_dict.get('obfuscation_algorithm_ref') self.is_defanged = attr_dict.get('is_defanged') self.defanging_algorithm_ref = attr_dict.get('defanging_algorithm_ref') self.refanging_transform_type = attr_dict.get('refanging_transform_type') self.refanging_transform = attr_dict.get('refanging_transform') self.observed_encoding = attr_dict.get('observed_encoding') PatternFieldGroup.from_dict(attr_dict, self)
def _populate_from_dict(self, attr_dict): # If this attribute is "plain", use it as the value and assume the # datatype was set correctly by the constructor of the particular # BaseProperty Subclass. if not isinstance(attr_dict, dict): self.value = attr_dict else: # This key should always be present self.value = attr_dict.get('value') # This defaults to False if missing self._force_datatype = attr_dict.get('force_datatype', False) # 'None' is fine if these keys are missing self.id_ = attr_dict.get('id') self.idref = attr_dict.get('idref') self.appears_random = attr_dict.get('appears_random') self.datatype = attr_dict.get('datatype') self.is_obfuscated = attr_dict.get('is_obfuscated') self.obfuscation_algorithm_ref = attr_dict.get( 'obfuscation_algorithm_ref') self.is_defanged = attr_dict.get('is_defanged') self.defanging_algorithm_ref = attr_dict.get( 'defanging_algorithm_ref') self.refanging_transform_type = attr_dict.get( 'refanging_transform_type') self.refanging_transform = attr_dict.get('refanging_transform') self.observed_encoding = attr_dict.get('observed_encoding') PatternFieldGroup.from_dict(attr_dict, self)
def to_obj(self): vocab_obj = common_binding.ControlledVocabularyStringType() vocab_obj.set_valueOf_(normalize_to_xml(self.value)) vocab_obj.set_xsi_type(self.xsi_type) if self.vocab_name is not None: vocab_obj.set_vocab_name(self.vocab_name) if self.vocab_reference is not None: vocab_obj.set_vocab_reference(self.vocab_reference) PatternFieldGroup.to_obj(self, vocab_obj) return vocab_obj
def to_obj(self): vocab_obj = common_binding.ControlledVocabularyStringType() vocab_obj.set_valueOf_(normalize_to_xml(self.value, self.delimiter)) vocab_obj.set_xsi_type(self.xsi_type) if self.vocab_name is not None: vocab_obj.set_vocab_name(self.vocab_name) if self.vocab_reference is not None: vocab_obj.set_vocab_reference(self.vocab_reference) PatternFieldGroup.to_obj(self, vocab_obj) return vocab_obj
def from_obj(cls, vocab_obj): if not vocab_obj: return None vocab_str = cls() # xsi_type should be set automatically by the class's constructor. vocab_str.value = denormalize_from_xml(vocab_obj.get_valueOf_()) vocab_str.vocab_name = vocab_obj.get_vocab_name() vocab_str.vocab_reference = vocab_obj.get_vocab_reference() vocab_str.xsi_type = vocab_obj.get_xsi_type() PatternFieldGroup.from_obj(vocab_obj, vocab_str) return vocab_str
def _populate_from_obj(self, attr_obj): self.value = denormalize_from_xml(attr_obj.get_valueOf_()) self.id_ = attr_obj.get_id() self.idref = attr_obj.get_idref() self.datatype = attr_obj.get_datatype() self.appears_random = attr_obj.get_appears_random() self.is_obfuscated = attr_obj.get_is_obfuscated() self.obfuscation_algorithm_ref = attr_obj.get_obfuscation_algorithm_ref() self.is_defanged = attr_obj.get_is_defanged() self.defanging_algorithm_ref = attr_obj.get_defanging_algorithm_ref() self.refanging_transform_type = attr_obj.get_refanging_transform_type() self.refanging_transform = attr_obj.get_refanging_transform() PatternFieldGroup.from_obj(attr_obj, self)
def is_plain(self): """Whether the Property can be represented as a single value. The `datatype` can be inferred by the particular BaseProperty subclass, so if `datatype` and `value` are the only non-None properties, the BaseProperty can be represented by a single value rather than a dictionary. This makes the JSON representation simpler without losing any data fidelity. """ return ( # ignore value self.id_ is None and self.idref is None and # ignore datatype self.appears_random is None and self.is_obfuscated is None and self.obfuscation_algorithm_ref is None and self.is_defanged is None and self.defanging_algorithm_ref is None and self.refanging_transform_type is None and self.refanging_transform is None and self.observed_encoding is None and PatternFieldGroup.is_plain(self) )
def _populate_from_obj(self, attr_obj): self.value = denormalize_from_xml(attr_obj.get_valueOf_()) self.id_ = attr_obj.get_id() self.idref = attr_obj.get_idref() self.datatype = attr_obj.get_datatype() self.appears_random = attr_obj.get_appears_random() self.is_obfuscated = attr_obj.get_is_obfuscated() self.obfuscation_algorithm_ref = attr_obj.get_obfuscation_algorithm_ref() self.is_defanged = attr_obj.get_is_defanged() self.defanging_algorithm_ref = attr_obj.get_defanging_algorithm_ref() self.refanging_transform_type = attr_obj.get_refanging_transform_type() self.refanging_transform = attr_obj.get_refanging_transform() self.observed_encoding = attr_obj.get_observed_encoding() PatternFieldGroup.from_obj(attr_obj, self)
def is_plain(self): """Whether the VocabString can be represented as a single value. """ return (self.xsi_type is None and self.vocab_name is None and self.vocab_reference is None and PatternFieldGroup.is_plain(self))
def __eq__(self, other): # None-type checking if not other: return False # It is possible to compare a Property to a single value if # the Property defines only the "value" property. if not isinstance(other, BaseProperty) and self.is_plain(): return self.value == other return ( self.value == other.value and self.id_ == other.id_ and self.idref == other.idref and self.datatype == other.datatype and self.appears_random == other.appears_random and self.is_obfuscated == other.is_obfuscated and self.obfuscation_algorithm_ref == other.obfuscation_algorithm_ref and self.is_defanged == other.is_defanged and self.defanging_algorithm_ref == other.defanging_algorithm_ref and self.refanging_transform_type == other.refanging_transform_type and self.refanging_transform == other.refanging_transform and self.observed_encoding == other.observed_encoding and PatternFieldGroup._conditions_equal(self, other) and self.bit_mask == other.bit_mask and self.pattern_type == other.pattern_type and self.regex_syntax == other.regex_syntax and self.is_case_sensitive == other.is_case_sensitive and self.has_changed == other.has_changed and self.trend == other.trend )
def __eq__(self, other): # None-type checking if not other: return False # It is possible to compare a Property to a single value if # the Property defines only the "value" property. if not isinstance(other, BaseProperty) and self.is_plain(): return self.value == other return ( self.value == other.value and self.id_ == other.id_ and self.idref == other.idref and self.datatype == other.datatype and self.appears_random == other.appears_random and self.is_obfuscated == other.is_obfuscated and self.obfuscation_algorithm_ref == other.obfuscation_algorithm_ref and self.is_defanged == other.is_defanged and self.defanging_algorithm_ref == other.defanging_algorithm_ref and self.refanging_transform_type == other.refanging_transform_type and self.refanging_transform == other.refanging_transform and self.observed_encoding == other.observed_encoding and PatternFieldGroup._conditions_equal(self, other) and self.bit_mask == other.bit_mask and self.pattern_type == other.pattern_type and self.regex_syntax == other.regex_syntax and self.is_case_sensitive == other.is_case_sensitive and self.has_changed == other.has_changed and self.trend == other.trend)
def to_obj(self, return_obj=None, ns_info=None): self._collect_ns_info(ns_info) if not return_obj: return_obj = self._binding_class() return_obj.valueOf_ = normalize_to_xml(self.value, self.delimiter) return_obj.xsi_type = self.xsi_type if self.vocab_name is not None: return_obj.vocab_name = self.vocab_name if self.vocab_reference is not None: return_obj.vocab_reference = self.vocab_reference PatternFieldGroup.to_obj(self, return_obj=return_obj, ns_info=ns_info) return return_obj
def to_dict(self): if self.is_plain(): return self.value vocab_dict = {} if self.value is not None: vocab_dict['value'] = self.value if self.xsi_type: vocab_dict['xsi:type'] = self.xsi_type if self.vocab_name is not None: vocab_dict['vocab_name'] = self.vocab_name if self.vocab_reference is not None: vocab_dict['vocab_reference'] = self.vocab_reference PatternFieldGroup.to_dict(self, vocab_dict) return vocab_dict
def to_obj(self): if not self.is_valid(): raise ValueError("Vocab being used has not been specified") vocab_obj = common_binding.ControlledVocabularyStringType() vocab_obj.set_valueOf_(normalize_to_xml(self.value, self.delimiter)) vocab_obj.set_xsi_type(self.xsi_type) if self.vocab_name is not None: vocab_obj.set_vocab_name(self.vocab_name) if self.vocab_reference is not None: vocab_obj.set_vocab_reference(self.vocab_reference) PatternFieldGroup.to_obj(self, vocab_obj) return vocab_obj
def to_obj(self, return_obj=None, ns_info=None): if not self.is_valid(): raise ValueError("Vocab being used has not been specified") self._collect_ns_info(ns_info) vocab_obj = common_binding.ControlledVocabularyStringType() vocab_obj.valueOf_ = normalize_to_xml(self.value, self.delimiter) vocab_obj.xsi_type = self.xsi_type if self.vocab_name is not None: vocab_obj.vocab_name = self.vocab_name if self.vocab_reference is not None: vocab_obj.vocab_reference = self.vocab_reference PatternFieldGroup.to_obj(self, return_obj=vocab_obj, ns_info=ns_info) return vocab_obj
def is_plain(self): """Whether the VocabString can be represented as a single value. """ return ( self.xsi_type is None and self.vocab_name is None and self.vocab_reference is None and PatternFieldGroup.is_plain(self) )
def from_dict(cls, vocab_dict): if not vocab_dict: return None vocab_str = cls() # xsi_type should be set automatically by the class's constructor. # In case this is a "plain" string, just set it. if not isinstance(vocab_dict, dict): vocab_str.value = vocab_dict else: vocab_str.xsi_type = vocab_dict.get('xsi:type', cls._XSI_TYPE) vocab_str.value = vocab_dict.get('value') vocab_str.vocab_name = vocab_dict.get('vocab_name') vocab_str.vocab_reference = vocab_dict.get('vocab_reference') PatternFieldGroup.from_dict(vocab_dict, vocab_str) return vocab_str
def _populate_from_obj(self, attr_obj): self.id_ = attr_obj.id self.idref = attr_obj.idref self.datatype = attr_obj.datatype self.appears_random = attr_obj.appears_random self.is_obfuscated = attr_obj.is_obfuscated self.obfuscation_algorithm_ref = attr_obj.obfuscation_algorithm_ref self.is_defanged = attr_obj.is_defanged self.defanging_algorithm_ref = attr_obj.defanging_algorithm_ref self.refanging_transform_type = attr_obj.refanging_transform_type self.refanging_transform = attr_obj.refanging_transform self.observed_encoding = attr_obj.observed_encoding PatternFieldGroup.from_obj(attr_obj, self) # We need to check for a non-default delimiter before trying to parse # the value. self.value = denormalize_from_xml(attr_obj.valueOf_, self.delimiter)
def from_obj(cls, vocab_obj): if not vocab_obj: return None vocab_str = cls() # xsi_type should be set automatically by the class's constructor. vocab_str.vocab_name = vocab_obj.vocab_name vocab_str.vocab_reference = vocab_obj.vocab_reference vocab_str.xsi_type = vocab_obj.xsi_type PatternFieldGroup.from_obj(vocab_obj, vocab_str) # We need to check for a non-default delimiter before trying to parse # the value. vocab_str.value = denormalize_from_xml(vocab_obj.valueOf_, vocab_str.delimiter) return vocab_str
def to_dict(self): if not self.is_valid(): raise ValueError("Vocab being used has not been specified") if self.is_plain(): return self.value vocab_dict = {} if self.value is not None: vocab_dict['value'] = self.value if self.xsi_type != self._XSI_TYPE: vocab_dict['xsi:type'] = self.xsi_type if self.vocab_name is not None: vocab_dict['vocab_name'] = self.vocab_name if self.vocab_reference is not None: vocab_dict['vocab_reference'] = self.vocab_reference PatternFieldGroup.to_dict(self, vocab_dict) return vocab_dict
def to_obj(self, return_obj=None, ns_info=None): self._collect_ns_info(ns_info) attr_obj = self._binding_class() attr_obj.set_valueOf_(normalize_to_xml(self.serialized_value, self.delimiter)) # For now, don't output the datatype, as it is not required and is # usually not needed, as it can be inferred from the context. #attr_obj.datatype = self.datatype if self.id_ is not None: attr_obj.id = self.id_ if self.idref is not None: attr_obj.idref = self.idref if self.appears_random is not None: attr_obj.appears_random = self.appears_random if self.is_obfuscated is not None: attr_obj.is_obfuscated = self.is_obfuscated if self.obfuscation_algorithm_ref is not None: attr_obj.obfuscation_algorithm_ref = self.obfuscation_algorithm_ref if self.is_defanged is not None: attr_obj.is_defanged = self.is_defanged if self.defanging_algorithm_ref is not None: attr_obj.defanging_algorithm_ref = self.defanging_algorithm_ref if self.refanging_transform_type is not None: attr_obj.refanging_transform_type = self.refanging_transform_type if self.refanging_transform is not None: attr_obj.refanging_transform = self.refanging_transform if self.observed_encoding is not None: attr_obj.observed_encoding = self.observed_encoding #Datatype output logic if self._force_datatype or (self.datatype != self.default_datatype): attr_obj.datatype = self.datatype else: attr_obj.datatype = None PatternFieldGroup.to_obj(self, return_obj=attr_obj, ns_info=ns_info) return attr_obj
def to_obj(self, return_obj=None, ns_info=None): self._collect_ns_info(ns_info) attr_obj = self._binding_class() attr_obj.set_valueOf_( normalize_to_xml(self.serialized_value, self.delimiter)) # For now, don't output the datatype, as it is not required and is # usually not needed, as it can be inferred from the context. #attr_obj.datatype = self.datatype if self.id_ is not None: attr_obj.id = self.id_ if self.idref is not None: attr_obj.idref = self.idref if self.appears_random is not None: attr_obj.appears_random = self.appears_random if self.is_obfuscated is not None: attr_obj.is_obfuscated = self.is_obfuscated if self.obfuscation_algorithm_ref is not None: attr_obj.obfuscation_algorithm_ref = self.obfuscation_algorithm_ref if self.is_defanged is not None: attr_obj.is_defanged = self.is_defanged if self.defanging_algorithm_ref is not None: attr_obj.defanging_algorithm_ref = self.defanging_algorithm_ref if self.refanging_transform_type is not None: attr_obj.refanging_transform_type = self.refanging_transform_type if self.refanging_transform is not None: attr_obj.refanging_transform = self.refanging_transform if self.observed_encoding is not None: attr_obj.observed_encoding = self.observed_encoding #Datatype output logic if self._force_datatype or (self.datatype != self.default_datatype): attr_obj.datatype = self.datatype else: attr_obj.datatype = None PatternFieldGroup.to_obj(self, return_obj=attr_obj, ns_info=ns_info) return attr_obj
def from_obj(cls, vocab_obj, return_obj=None): if not vocab_obj: return None if not return_obj: klass = VocabString.lookup_class(vocab_obj.xsi_type) return_obj = klass() # xsi_type should be set automatically by the class's constructor. return_obj.vocab_name = vocab_obj.vocab_name return_obj.vocab_reference = vocab_obj.vocab_reference return_obj.xsi_type = vocab_obj.xsi_type PatternFieldGroup.from_obj(vocab_obj, return_obj) # We need to check for a non-default delimiter before trying to parse # the value. return_obj.value = denormalize_from_xml(value=vocab_obj.valueOf_, delimiter=return_obj.delimiter) return return_obj
def is_plain(self): """Whether the VocabString can be represented as a single value. If `value` is the only non-None properties and a custom XSI type has not been set, the VocabString can be represented by a single value rather than a dictionary. This makes the JSON representation simpler without losing any data fidelity. """ return ( # ignore value self.vocab_name is None and self.vocab_reference is None and self.xsi_type == self._XSI_TYPE and PatternFieldGroup.is_plain(self))
def to_obj(self): attr_obj = self._binding_class() attr_obj.set_valueOf_(normalize_to_xml(self.serialized_value, self.delimiter)) # For now, don't output the datatype, as it is not required and is # usually not needed, as it can be inferred from the context. #attr_obj.set_datatype(self.datatype) if self.id_ is not None: attr_obj.set_id(self.id_) if self.idref is not None: attr_obj.set_idref(self.idref) if self.appears_random is not None: attr_obj.set_appears_random(self.appears_random) if self.is_obfuscated is not None: attr_obj.set_is_obfuscated(self.is_obfuscated) if self.obfuscation_algorithm_ref is not None: attr_obj.set_obfuscation_algorithm_ref(self.obfuscation_algorithm_ref) if self.is_defanged is not None: attr_obj.set_is_defanged(self.is_defanged) if self.defanging_algorithm_ref is not None: attr_obj.set_defanging_algorithm_ref(self.defanging_algorithm_ref) if self.refanging_transform_type is not None: attr_obj.set_refanging_transform_type(self.refanging_transform_type) if self.refanging_transform is not None: attr_obj.set_refanging_transform(self.refanging_transform) if self.observed_encoding is not None: attr_obj.set_observed_encoding(self.observed_encoding) #Datatype output logic if self._force_datatype or (self.datatype != self.default_datatype): attr_obj.set_datatype(self.datatype) else: attr_obj.set_datatype(None) PatternFieldGroup.to_obj(self, attr_obj) return attr_obj
def from_dict(cls, vocab_dict, return_obj=None): if not vocab_dict: return None if not return_obj: if isinstance(vocab_dict, dict): klass = VocabString.lookup_class(vocab_dict.get('xsi:type')) return_obj = klass() else: return_obj = cls() # In case this is a "plain" string, just set it. if not isinstance(vocab_dict, dict): return_obj.value = vocab_dict else: return_obj.xsi_type = vocab_dict.get('xsi:type', cls._XSI_TYPE) return_obj.value = vocab_dict.get('value') return_obj.vocab_name = vocab_dict.get('vocab_name') return_obj.vocab_reference = vocab_dict.get('vocab_reference') PatternFieldGroup.from_dict(vocab_dict, return_obj) return return_obj
def from_obj(cls, vocab_obj, return_obj=None): if not vocab_obj: return None if not return_obj: klass = VocabString.lookup_class(vocab_obj.xsi_type) return_obj = klass() # xsi_type should be set automatically by the class's constructor. return_obj.vocab_name = vocab_obj.vocab_name return_obj.vocab_reference = vocab_obj.vocab_reference return_obj.xsi_type = vocab_obj.xsi_type PatternFieldGroup.from_obj(vocab_obj, return_obj) # We need to check for a non-default delimiter before trying to parse # the value. return_obj.value = denormalize_from_xml( value=vocab_obj.valueOf_, delimiter=return_obj.delimiter ) return return_obj
def is_plain(self): """Whether the VocabString can be represented as a single value. If `xsi:type` and `value` are the only non-None properties, the VocabString can be represented by a single value rather than a dictionary. This makes the JSON representation simpler without losing any data fidelity. """ return ( # ignore value and xsi_type self.vocab_name is None and self.vocab_reference is None and PatternFieldGroup.is_plain(self) )
def is_plain(self): """Whether the VocabString can be represented as a single value. If `value` is the only non-None properties and a custom XSI type has not been set, the VocabString can be represented by a single value rather than a dictionary. This makes the JSON representation simpler without losing any data fidelity. """ return ( # ignore value self.vocab_name is None and self.vocab_reference is None and self.xsi_type == self._XSI_TYPE and PatternFieldGroup.is_plain(self) )