def text(self, value): decoded = utf8decode(value) try: lxml.etree.ElementBase.text.__set__(self, decoded) except ValueError: root = self.getroottree().getroot() # URL encoding is usually done at the end, but sometimes we get # control characters that are rejected by the XML encoder. # If we are going to urlencode the value, do it now. if root.encoding_type != 'url' or \ self.tag in URLENCODE_BLACKLIST: raise lxml.etree.ElementBase.text.__set__(self, quote(decoded)) # The deepcopy seems to not copy custom fields, thus we use # an attribute which will be deleted when marshalling. self.set('urlencoded', 'True')
def text(self, value): blacklist = ['LastModified', 'ID', 'DisplayName', 'Initiated'] try: if value is None: self._element.text = None elif isinstance(value, basestring) and value == '': self._element.text = None else: if not isinstance(value, basestring): value = str(value) if self.encoding_type == 'url' and self.tag not in blacklist: self._element.text = quote(value) else: self._element.text = utils.utf8decode(value) except ValueError: # We tried to set an invalid string for XML self._element.text = ''
def text(self, value): lxml.etree.ElementBase.text.__set__(self, utf8decode(value))