def new_setter(self, val, *args, **kwargs): # Do this regardless, for validation purposes fset(self, val, *args, **kwargs) if not self._xml_node: return # Convert from API value to XML value val = fget(self) if set_converter: val = set_converter(self, val) elif default_converter and val == "default": val = default_converter(self) nodexpath = xpath if xml_set_xpath: nodexpath = xml_set_xpath(self) if nodexpath is None: return nodes = _util.listify(_get_xpath_node(self._xml_ctx, nodexpath, is_multi)) xpath_list = nodexpath if xml_set_list: xpath_list = xml_set_list(self) node_map = map(lambda x, y, z: (x, y, z), _util.listify(nodes), _util.listify(val), _util.listify(xpath_list)) for node, val, usexpath in node_map: if node: usexpath = node.nodePath() if val not in [None, False]: if not node: node = _build_xpath_node(self._xml_node, usexpath) if val is True: # Boolean property, creating the node is enough pass else: node.setContent(_util.xml_escape(str(val))) else: _remove_xpath_node(self._xml_node, usexpath)
def new_setter(self, val, *args, **kwargs): # Do this regardless, for validation purposes fset(self, val, *args, **kwargs) if not self._xml_node: return # Convert from API value to XML value val = fget(self) if set_converter: val = set_converter(self, val) elif default_converter and val == "default": val = default_converter(self) nodexpath = xpath if xml_set_xpath: nodexpath = xml_set_xpath(self) if nodexpath is None: return nodes = _util.listify( _get_xpath_node(self._xml_ctx, nodexpath, is_multi)) xpath_list = nodexpath if xml_set_list: xpath_list = xml_set_list(self) node_map = map(lambda x, y, z: (x, y, z), _util.listify(nodes), _util.listify(val), _util.listify(xpath_list)) for node, val, usexpath in node_map: if node: usexpath = node.nodePath() if val not in [None, False]: if not node: node = _build_xpath_node(self._xml_node, usexpath) if val is True: # Boolean property, creating the node is enough pass else: node.setContent(str(val)) else: _remove_xpath_node(self._xml_node, usexpath)
def new_getter(self, *args, **kwargs): val = None getval = fget(self, *args, **kwargs) if not self._xml_node: return getval if default_converter and getval == "default": return getval usexpath = xpath if xml_get_xpath: usexpath = xml_get_xpath(self) if usexpath is None: return getval nodes = _util.listify( _get_xpath_node(self._xml_ctx, usexpath, is_multi)) if nodes: ret = [] for node in nodes: val = node.content if get_converter: val = get_converter(self, val) elif is_bool: val = True if not is_multi: return val # If user is querying multiple nodes, return a list of results ret.append(val) return ret elif is_bool: return False elif get_converter: getval = get_converter(self, None) return getval
def new_getter(self, *args, **kwargs): val = None getval = fget(self, *args, **kwargs) if not self._xml_node: return getval if default_converter and getval == "default": return getval usexpath = xpath if xml_get_xpath: usexpath = xml_get_xpath(self) if usexpath is None: return getval nodes = _util.listify(_get_xpath_node(self._xml_ctx, usexpath, is_multi)) if nodes: ret = [] for node in nodes: val = node.content if get_converter: val = get_converter(self, val) elif is_bool: val = True if not is_multi: return val # If user is querying multiple nodes, return a list of results ret.append(val) return ret elif is_bool: return False elif get_converter: getval = get_converter(self, None) return getval