예제 #1
0
    def to_xml(self, f=None):
        """Get this domain as an XML DOM Document
        :param f: Optional File to dump directly to
        :type f: File or Stream

        :return: File object where the XML has been dumped to
        :rtype: file
        """
        if not f:
            from tempfile import TemporaryFile
            f = TemporaryFile()
        print('<?xml version="1.0" encoding="UTF-8"?>', file=f)
        print('<Domain id="%s">' % self.name, file=f)
        for item in self:
            print('\t<Item id="%s">' % item.name, file=f)
            for k in item:
                print('\t\t<attribute id="%s">' % k, file=f)
                values = item[k]
                if not isinstance(values, list):
                    values = [values]
                for value in values:
                    print('\t\t\t<value><![CDATA[', end=' ', file=f)
                    if isinstance(value, six.text_type):
                        value = value.encode('utf-8', 'replace')
                    else:
                        value = six.text_type(value, errors='replace').encode(
                            'utf-8', 'replace')
                    f.write(value)
                    print(']]></value>', file=f)
                print('\t\t</attribute>', file=f)
            print('\t</Item>', file=f)
        print('</Domain>', file=f)
        f.flush()
        f.seek(0)
        return f
예제 #2
0
    def marshal_object(self, obj, doc=None):
        if not doc:
            doc = self.new_doc()
        if not doc:
            doc = self.doc
        obj_node = doc.createElement('object')

        if obj.id:
            obj_node.setAttribute('id', obj.id)

        obj_node.setAttribute(
            'class',
            '%s.%s' % (obj.__class__.__module__, obj.__class__.__name__))
        root = doc.documentElement
        root.appendChild(obj_node)
        for property in obj.properties(hidden=False):
            prop_node = doc.createElement('property')
            prop_node.setAttribute('name', property.name)
            prop_node.setAttribute('type', property.type_name)
            value = property.get_value_for_datastore(obj)
            if value is not None:
                value = self.encode_value(property, value)
                if isinstance(value, list):
                    self.save_list(doc, value, prop_node)
                elif isinstance(value, Node):
                    prop_node.appendChild(value)
                else:
                    text_node = doc.createTextNode(
                        six.text_type(value).encode("ascii", "ignore"))
                    prop_node.appendChild(text_node)
            obj_node.appendChild(prop_node)

        return doc
예제 #3
0
파일: domain.py 프로젝트: 10sr/hue
    def to_xml(self, f=None):
        """Get this domain as an XML DOM Document
        :param f: Optional File to dump directly to
        :type f: File or Stream

        :return: File object where the XML has been dumped to
        :rtype: file
        """
        if not f:
            from tempfile import TemporaryFile
            f = TemporaryFile()
        print('<?xml version="1.0" encoding="UTF-8"?>', file=f)
        print('<Domain id="%s">' % self.name, file=f)
        for item in self:
            print('\t<Item id="%s">' % item.name, file=f)
            for k in item:
                print('\t\t<attribute id="%s">' % k, file=f)
                values = item[k]
                if not isinstance(values, list):
                    values = [values]
                for value in values:
                    print('\t\t\t<value><![CDATA[', end=' ', file=f)
                    if isinstance(value, six.text_type):
                        value = value.encode('utf-8', 'replace')
                    else:
                        value = six.text_type(value, errors='replace').encode('utf-8', 'replace')
                    f.write(value)
                    print(']]></value>', file=f)
                print('\t\t</attribute>', file=f)
            print('\t</Item>', file=f)
        print('</Domain>', file=f)
        f.flush()
        f.seek(0)
        return f
예제 #4
0
파일: xmlmanager.py 프로젝트: CashStar/boto
    def marshal_object(self, obj, doc=None):
        if not doc:
            doc = self.new_doc()
        if not doc:
            doc = self.doc
        obj_node = doc.createElement('object')

        if obj.id:
            obj_node.setAttribute('id', obj.id)

        obj_node.setAttribute('class', '%s.%s' % (obj.__class__.__module__,
                                                  obj.__class__.__name__))
        root = doc.documentElement
        root.appendChild(obj_node)
        for property in obj.properties(hidden=False):
            prop_node = doc.createElement('property')
            prop_node.setAttribute('name', property.name)
            prop_node.setAttribute('type', property.type_name)
            value = property.get_value_for_datastore(obj)
            if value is not None:
                value = self.encode_value(property, value)
                if isinstance(value, list):
                    self.save_list(doc, value, prop_node)
                elif isinstance(value, Node):
                    prop_node.appendChild(value)
                else:
                    text_node = doc.createTextNode(six.text_type(value).encode("ascii", "ignore"))
                    prop_node.appendChild(text_node)
            obj_node.appendChild(prop_node)

        return doc
예제 #5
0
 def test_create_health_check_failure_threshold(self):
     hc_params = self.health_check_params(failure_threshold=1)
     hc = HealthCheck(**hc_params)
     result = self.conn.create_health_check(hc)
     hc_config = (result[u'CreateHealthCheckResponse']
                  [u'HealthCheck'][u'HealthCheckConfig'])
     self.assertEquals(hc_config[u'FailureThreshold'],
                       six.text_type(hc_params['failure_threshold']))
     self.conn.delete_health_check(result['CreateHealthCheckResponse']['HealthCheck']['Id'])
예제 #6
0
 def test_create_health_check_request_interval(self):
     hc_params = self.health_check_params(request_interval=10)
     hc = HealthCheck(**hc_params)
     result = self.conn.create_health_check(hc)
     hc_config = (result[u'CreateHealthCheckResponse']
                  [u'HealthCheck'][u'HealthCheckConfig'])
     self.assertEquals(hc_config[u'RequestInterval'],
                       six.text_type(hc_params['request_interval']))
     self.conn.delete_health_check(result['CreateHealthCheckResponse']['HealthCheck']['Id'])
예제 #7
0
 def test_create_health_check_failure_threshold(self):
     hc_params = self.health_check_params(failure_threshold=1)
     hc = HealthCheck(**hc_params)
     result = self.conn.create_health_check(hc)
     hc_config = (result[u'CreateHealthCheckResponse']
                  [u'HealthCheck'][u'HealthCheckConfig'])
     self.assertEquals(hc_config[u'FailureThreshold'],
                       six.text_type(hc_params['failure_threshold']))
     self.conn.delete_health_check(result['CreateHealthCheckResponse']['HealthCheck']['Id'])
예제 #8
0
 def test_create_health_check_request_interval(self):
     hc_params = self.health_check_params(request_interval=10)
     hc = HealthCheck(**hc_params)
     result = self.conn.create_health_check(hc)
     hc_config = (result[u'CreateHealthCheckResponse']
                  [u'HealthCheck'][u'HealthCheckConfig'])
     self.assertEquals(hc_config[u'RequestInterval'],
                       six.text_type(hc_params['request_interval']))
     self.conn.delete_health_check(result['CreateHealthCheckResponse']['HealthCheck']['Id'])
예제 #9
0
def get_utf8_value(value):
    if not six.PY2 and isinstance(value, bytes):
        return value

    if not isinstance(value, six.string_types):
        value = six.text_type(value)

    if isinstance(value, six.text_type):
        value = value.encode('utf-8')

    return value
예제 #10
0
 def test_sign_canned_policy_unicode(self):
     """
     Test signing the canned policy from amazon's cloudfront documentation.
     """
     expected = ("Nql641NHEUkUaXQHZINK1FZ~SYeUSoBJMxjdgqrzIdzV2gyEXPDN"
                 "v0pYdWJkflDKJ3xIu7lbwRpSkG98NBlgPi4ZJpRRnVX4kXAJK6td"
                 "Nx6FucDB7OVqzcxkxHsGFd8VCG1BkC-Afh9~lOCMIYHIaiOB6~5j"
                 "t9w2EOwi6sIIqrg_")
     unicode_policy = six.text_type(self.canned_policy)
     sig = self.dist._sign_string(unicode_policy, private_key_string=self.pk_str)
     encoded_sig = self.dist._url_base64_encode(sig)
     self.assertEqual(expected, encoded_sig)
예제 #11
0
 def test_sign_canned_policy_unicode(self):
     """
     Test signing the canned policy from amazon's cloudfront documentation.
     """
     expected = ("Nql641NHEUkUaXQHZINK1FZ~SYeUSoBJMxjdgqrzIdzV2gyEXPDN"
                 "v0pYdWJkflDKJ3xIu7lbwRpSkG98NBlgPi4ZJpRRnVX4kXAJK6td"
                 "Nx6FucDB7OVqzcxkxHsGFd8VCG1BkC-Afh9~lOCMIYHIaiOB6~5j"
                 "t9w2EOwi6sIIqrg_")
     unicode_policy = six.text_type(self.canned_policy)
     sig = self.dist._sign_string(unicode_policy,
                                  private_key_string=self.pk_str)
     encoded_sig = self.dist._url_base64_encode(sig)
     self.assertEqual(expected, encoded_sig)
예제 #12
0
 def encode_string(self, value):
     """Convert ASCII, Latin-1 or UTF-8 to pure Unicode"""
     if not isinstance(value, str):
         return value
     try:
         return six.text_type(value, 'utf-8')
     except:
         # really, this should throw an exception.
         # in the interest of not breaking current
         # systems, however:
         arr = []
         for ch in value:
             arr.append(six.unichr(ord(ch)))
         return u"".join(arr)
예제 #13
0
파일: sdbmanager.py 프로젝트: 10sr/hue
 def encode_string(self, value):
     """Convert ASCII, Latin-1 or UTF-8 to pure Unicode"""
     if not isinstance(value, str):
         return value
     try:
         return six.text_type(value, 'utf-8')
     except:
         # really, this should throw an exception.
         # in the interest of not breaking current
         # systems, however:
         arr = []
         for ch in value:
             arr.append(six.unichr(ord(ch)))
         return u"".join(arr)
예제 #14
0
파일: blob.py 프로젝트: Rome84/AWS-BOTO1
 def __str__(self):
     return six.text_type(self).encode('utf-8')
예제 #15
0
파일: blob.py 프로젝트: 10sr/hue
 def __str__(self):
     return six.text_type(self).encode('utf-8')