Esempio n. 1
0
 def test_toUnicode_utf8(self):
     """Tests converting and parsing an utf-8 encoded string."""
     #======================================================================
     # with BOM
     #======================================================================
     # with encoding
     temp = codecs.BOM_UTF8 + unicode(TEST_W_ENC % 'UTF-8').encode('UTF-8')
     # with cutting declaration
     data, enc = toUnicode(temp, True)
     assert data == TEST_BASE
     assert enc == 'utf-8'
     # without cutting declaration
     data, enc = toUnicode(temp, False)
     assert data == TEST_W_ENC % 'UTF-8'
     assert enc == 'utf-8'
     
     # without encoding
     temp = codecs.BOM_UTF8 + unicode(TEST_WO_ENC).encode('UTF-8')
     # with cutting declaration
     data, enc = toUnicode(temp, True)
     assert data == TEST_BASE
     assert enc == 'utf-8'
     # without cutting declaration
     data, enc = toUnicode(temp, False)
     assert data == TEST_WO_ENC
     assert enc == 'utf-8'
     
     #======================================================================
     # without BOM
     #======================================================================
     # witch encoding
     temp = unicode(TEST_W_ENC % 'UTF-8').encode('UTF-8')
     # with cutting declaration
     data, enc = parseXMLDeclaration(temp, True)
     assert data == TEST_BASE
     assert enc == 'utf-8'
     # without cutting declaration
     data, enc = parseXMLDeclaration(temp, False)
     assert data == TEST_W_ENC % 'UTF-8'
     assert enc == 'utf-8'
     
     # without encoding
     temp = unicode(TEST_WO_ENC).encode('UTF-8')
     # with cutting declaration
     data, enc = parseXMLDeclaration(temp, True)
     assert data == TEST_BASE
     assert enc == 'utf-8'
     # without cutting declaration
     data, enc = parseXMLDeclaration(temp, False)
     assert data == TEST_WO_ENC
     assert enc == 'utf-8'
Esempio n. 2
0
    def test_toUnicode_utf8(self):
        """Tests converting and parsing an utf-8 encoded string."""
        #======================================================================
        # with BOM
        #======================================================================
        # with encoding
        temp = codecs.BOM_UTF8 + unicode(TEST_W_ENC % 'UTF-8').encode('UTF-8')
        # with cutting declaration
        data, enc = toUnicode(temp, True)
        assert data == TEST_BASE
        assert enc == 'utf-8'
        # without cutting declaration
        data, enc = toUnicode(temp, False)
        assert data == TEST_W_ENC % 'UTF-8'
        assert enc == 'utf-8'

        # without encoding
        temp = codecs.BOM_UTF8 + unicode(TEST_WO_ENC).encode('UTF-8')
        # with cutting declaration
        data, enc = toUnicode(temp, True)
        assert data == TEST_BASE
        assert enc == 'utf-8'
        # without cutting declaration
        data, enc = toUnicode(temp, False)
        assert data == TEST_WO_ENC
        assert enc == 'utf-8'

        #======================================================================
        # without BOM
        #======================================================================
        # witch encoding
        temp = unicode(TEST_W_ENC % 'UTF-8').encode('UTF-8')
        # with cutting declaration
        data, enc = parseXMLDeclaration(temp, True)
        assert data == TEST_BASE
        assert enc == 'utf-8'
        # without cutting declaration
        data, enc = parseXMLDeclaration(temp, False)
        assert data == TEST_W_ENC % 'UTF-8'
        assert enc == 'utf-8'

        # without encoding
        temp = unicode(TEST_WO_ENC).encode('UTF-8')
        # with cutting declaration
        data, enc = parseXMLDeclaration(temp, True)
        assert data == TEST_BASE
        assert enc == 'utf-8'
        # without cutting declaration
        data, enc = parseXMLDeclaration(temp, False)
        assert data == TEST_WO_ENC
        assert enc == 'utf-8'
Esempio n. 3
0
 def test_parseXMLDeclaration_str(self):
     """Tests parsing the XML declaration of a str object."""
     # with cutting declaration
     data, enc = parseXMLDeclaration(TEST_W_ENC % 'UTF-8', True)
     assert data == TEST_BASE
     assert enc == 'utf-8'
     data, enc = parseXMLDeclaration(TEST_WO_ENC, True)
     assert data == TEST_BASE
     assert enc == 'utf-8'
     # without cutting declaration
     data, enc = parseXMLDeclaration(TEST_W_ENC % 'UTF-8', False)
     assert data == TEST_W_ENC % 'UTF-8'
     assert enc == 'utf-8'
     data, enc = parseXMLDeclaration(TEST_WO_ENC, False)
     assert data == TEST_WO_ENC
     assert enc == 'utf-8'
Esempio n. 4
0
 def test_parseXMLDeclaration_unicode(self):
     """Tests parsing the XML declaration of an unicode object."""
     # with cutting declaration
     data, enc = parseXMLDeclaration(unicode(TEST_W_ENC % 'UTF-8'), True)
     assert data == TEST_BASE
     assert enc == 'utf-8'
     data, enc = parseXMLDeclaration(unicode(TEST_WO_ENC), True)
     assert data == TEST_BASE
     assert enc == 'utf-8'
     # without cutting declaration
     data, enc = parseXMLDeclaration(unicode(TEST_W_ENC % 'UTF-8'), False)
     assert data == TEST_W_ENC % 'UTF-8'
     assert enc == 'utf-8'
     data, enc = parseXMLDeclaration(unicode(TEST_WO_ENC), False)
     assert data == TEST_WO_ENC
     assert enc == 'utf-8'
Esempio n. 5
0
 def test_parseXMLDeclaration_str(self):
     """Tests parsing the XML declaration of a str object."""
     # with cutting declaration
     data, enc = parseXMLDeclaration(TEST_W_ENC % 'UTF-8', True)
     assert data == TEST_BASE
     assert enc == 'utf-8'
     data, enc = parseXMLDeclaration(TEST_WO_ENC, True)
     assert data == TEST_BASE
     assert enc == 'utf-8'
     # without cutting declaration
     data, enc = parseXMLDeclaration(TEST_W_ENC % 'UTF-8', False)
     assert data == TEST_W_ENC % 'UTF-8'
     assert enc == 'utf-8'
     data, enc = parseXMLDeclaration(TEST_WO_ENC, False)
     assert data == TEST_WO_ENC
     assert enc == 'utf-8'
Esempio n. 6
0
 def test_parseXMLDeclaration_unicode(self):
     """Tests parsing the XML declaration of an unicode object."""
     # with cutting declaration
     data, enc = parseXMLDeclaration(unicode(TEST_W_ENC % 'UTF-8'), True)
     assert data == TEST_BASE
     assert enc == 'utf-8'
     data, enc = parseXMLDeclaration(unicode(TEST_WO_ENC), True)
     assert data == TEST_BASE
     assert enc == 'utf-8'
     # without cutting declaration
     data, enc = parseXMLDeclaration(unicode(TEST_W_ENC % 'UTF-8'), False)
     assert data == TEST_W_ENC % 'UTF-8'
     assert enc == 'utf-8'
     data, enc = parseXMLDeclaration(unicode(TEST_WO_ENC), False)
     assert data == TEST_WO_ENC
     assert enc == 'utf-8'
Esempio n. 7
0
def newXMLDocument(data, id=None, uid=None):
    """
    Returns a new XmlDocument object.

    Data will be converted to unicode and a possible XML declaration will be
    removed. Use this method whenever you wish to create a XmlDocument 
    manually!
    """
    # check for data
    if len(data) == 0:
        raise InvalidParameterError("XML document is empty.")
    # convert data to unicode and remove XML declaration
    if isinstance(data, unicode):
        data, _ = parseXMLDeclaration(data, remove_decl=True)
    else:
        data, _ = toUnicode(data, remove_decl=True)
    return XmlDocument(data, id, uid)
Esempio n. 8
0
def newXMLDocument(data, id=None, uid=None):
    """
    Returns a new XmlDocument object.

    Data will be converted to unicode and a possible XML declaration will be
    removed. Use this method whenever you wish to create a XmlDocument 
    manually!
    """
    # check for data
    if len(data) == 0:
        raise InvalidParameterError("XML document is empty.")
    # convert data to unicode and remove XML declaration
    if isinstance(data, unicode):
        data, _ = parseXMLDeclaration(data, remove_decl=True)
    else:
        data, _ = toUnicode(data, remove_decl=True)
    return XmlDocument(data, id, uid)