예제 #1
0
파일: etree.py 프로젝트: newtoncorp/swift3
 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')
예제 #2
0
파일: etree.py 프로젝트: ichi-shin/swift3
    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 = ''
예제 #3
0
 def text(self, value):
     lxml.etree.ElementBase.text.__set__(self, utf8decode(value))