def unescapeOldTitle(setuptool):
    """ Upgrade quintagroup.seoptimizer title and comments properties.
    """
    portal = getToolByName(setuptool, "portal_url").getPortalObject()
    types = ISEOConfigletSchema(portal).types_seo_enabled

    catalog = getToolByName(portal, "portal_catalog")
    brains = catalog(portal_type=types)

    for b in brains:
        obj = b.getObject()
        obj_enc = getSiteEncoding(obj)

        if obj.hasProperty("qSEO_title"):
            uni_qSEO_title = safe_unicode(obj.qSEO_title, encoding=obj_enc)
            fixed_title = unescape(uni_qSEO_title).encode(obj_enc)
            obj._updateProperty("qSEO_title", fixed_title)

        if obj.hasProperty("qSEO_html_comment"):
            uni_qSEO_html_comment = safe_unicode(obj.qSEO_html_comment,
                                                 encoding=obj_enc)
            fixed_comment = unescape(uni_qSEO_html_comment).encode(obj_enc)
            obj._updateProperty("qSEO_html_comment", fixed_comment)
def unescapeOldTitle(setuptool):
    """ Upgrade quintagroup.seoptimizer title and comments properties.
    """
    portal = getToolByName(setuptool, "portal_url").getPortalObject()
    types = ISEOConfigletSchema(portal).types_seo_enabled

    catalog = getToolByName(portal, "portal_catalog")
    brains = catalog(portal_type=types)

    for b in brains:
        obj = b.getObject()
        obj_enc = getSiteEncoding(obj)

        if obj.hasProperty("qSEO_title"):
            uni_qSEO_title = safe_unicode(obj.qSEO_title, encoding=obj_enc)
            fixed_title = unescape(uni_qSEO_title).encode(obj_enc)
            obj._updateProperty("qSEO_title", fixed_title)

        if obj.hasProperty("qSEO_html_comment"):
            uni_qSEO_html_comment = safe_unicode(obj.qSEO_html_comment,
                                                 encoding=obj_enc)
            fixed_comment = unescape(uni_qSEO_html_comment).encode(obj_enc)
            obj._updateProperty("qSEO_html_comment", fixed_comment)
 def test_unicode_str_unescaping(self):
     self.assertEqual(unescape("&&-/["), "&&-/[")
 def test_aentity_unescaping(self):
     self.assertEqual(unescape("—").encode('utf-8'),
                      u"—".encode('utf-8'))
 def test_fake_entity_unescaping(self):
     self.assertEqual(unescape("&asd;"), "&asd;")
 def test_entity_dec_hex_unescaping(self):
     self.assertEqual(unescape('['), '[')
 def test_intity_dec_unescaping(self):
     self.assertEqual(unescape('['), '[')
 def test_simple_text_unescaping(self):
     self.assertEqual(unescape("Simple text."), "Simple text.")
 def test_hex_unescaping(self):
     self.assertEqual(unescape('['), '[')
 def test_entity_unicode_unescaping(self):
     self.assertEqual(unescape(u"&&ї".encode('utf-8')),
                      u"&&ї".encode('utf-8'))