def change_location_tag(primary_xml_snippet, relpath): """ Transform the <location> tag to strip out leading directories so it puts all rpms in the same directory as 'repodata' @param primary_xml_snippet: snippet of primary xml text for a single package @type primary_xml_snippet: str @param relpath: Package's 'relativepath' @type relpath: str """ basename = os.path.basename(relpath) start_index = primary_xml_snippet.find("<location ") end_index = primary_xml_snippet.find("/>", start_index) + 2 # adjust to end of closing tag first_portion = util.string_to_unicode(primary_xml_snippet[:start_index]) end_portion = util.string_to_unicode(primary_xml_snippet[end_index:]) location = util.string_to_unicode("""<location href="%s"/>""" % (basename)) return first_portion + location + end_portion
def _decode_changelog(changelog_tuple): timestamp, email, description = changelog_tuple email = util.string_to_unicode(email) description = util.string_to_unicode(description) return timestamp, email, description
def test_latin1(self): data = '/usr/share/doc/man-pages-da-0.1.1/l\xe6smig' result = util.string_to_unicode(data) self.assertTrue(isinstance(result, unicode)) self.assertEqual(result, data.decode('iso-8859-1'))
def test_utf8(self): result = util.string_to_unicode(u'€'.encode('utf8')) self.assertTrue(isinstance(result, unicode)) self.assertEqual(result, u'€')
def test_ascii(self): result = util.string_to_unicode('abc') self.assertTrue(isinstance(result, unicode)) self.assertEqual(result, u'abc')
def test_empty(self): result = util.string_to_unicode('') self.assertTrue(isinstance(result, unicode)) self.assertEqual(result, u'')