From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (unknown [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 5AB941381FA for ; Fri, 16 May 2014 01:07:10 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id BFDCEE0A0B; Fri, 16 May 2014 01:07:09 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 28C3BE0A0B for ; Fri, 16 May 2014 01:07:09 +0000 (UTC) Received: from spoonbill.gentoo.org (unknown [81.93.255.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 1E6ED34006B for ; Fri, 16 May 2014 01:07:08 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by spoonbill.gentoo.org (Postfix) with ESMTP id C5E61182D4 for ; Fri, 16 May 2014 01:07:06 +0000 (UTC) From: "Devan Franchini" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Devan Franchini" Message-ID: <1400202406.e21d636e07a1f6875ae916b87a4cb8c23f0de6cf.twitch153@gentoo> Subject: [gentoo-commits] proj/layman:gsoc2014 commit in: layman/ X-VCS-Repository: proj/layman X-VCS-Files: layman/dbbase.py X-VCS-Directories: layman/ X-VCS-Committer: twitch153 X-VCS-Committer-Name: Devan Franchini X-VCS-Revision: e21d636e07a1f6875ae916b87a4cb8c23f0de6cf X-VCS-Branch: gsoc2014 Date: Fri, 16 May 2014 01:07:06 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 6773d9b4-5388-4f1b-9b65-2bbea6352761 X-Archives-Hash: 11788fdcfc365ee185d2d09eed54953a commit: e21d636e07a1f6875ae916b87a4cb8c23f0de6cf Author: Devan Franchini gentoo org> AuthorDate: Wed May 14 21:10:50 2014 +0000 Commit: Devan Franchini gentoo org> CommitDate: Fri May 16 01:06:46 2014 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/layman.git;a=commit;h=e21d636e dbbase.py: Adds unicode compatibility to ElementTree When writing the database to installed.xml, ElementTree needs to have an encoding type specified or run time errors will occur. To ensure compatibility between py2/py3 a check has been made to see which python version is running and to set the _unicode variable accordingly. --- layman/dbbase.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/layman/dbbase.py b/layman/dbbase.py index ff99965..3632a57 100644 --- a/layman/dbbase.py +++ b/layman/dbbase.py @@ -37,6 +37,14 @@ from layman.utils import indent from layman.compatibility import fileopen from layman.overlays.overlay import Overlay +#py3.2 +if sys.hexversion >= 0x30200f0: + _unicode = 'unicode' +else: + _unicode = 'UTF-8' + + + #=============================================================================== # # Class UnknownOverlayException @@ -220,16 +228,13 @@ class DbBase(object): >>> os.rmdir(tmpdir) ''' - tree = ET.Element('repositories', version="1.0") + tree = ET.Element('repositories', version="1.0", encoding="unicode") tree[:] = [e.to_xml() for e in list(self.overlays.values())] indent(tree) tree = ET.ElementTree(tree) try: f = fileopen(path, 'w') - f.write("""\ - -""") - tree.write(f, encoding='utf-8') + tree.write(f, encoding=_unicode) f.close() except Exception as error: raise Exception('Failed to write to local overlays file: '