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 1680F1393E9 for ; Wed, 14 May 2014 21:15:11 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 2D331E0A61; Wed, 14 May 2014 21:15:10 +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 99A48E0A61 for ; Wed, 14 May 2014 21:15: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 936B933FA4C for ; Wed, 14 May 2014 21:15:08 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by spoonbill.gentoo.org (Postfix) with ESMTP id 42BA0182D3 for ; Wed, 14 May 2014 21:15:07 +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: <1400101850.ea812ff32370c426fb9c266b8824ba9338264c7c.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: ea812ff32370c426fb9c266b8824ba9338264c7c X-VCS-Branch: gsoc2014 Date: Wed, 14 May 2014 21:15:07 +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: ed4f30ba-12a2-4fcc-9d23-acc074d3faf4 X-Archives-Hash: 34012baeaf34988f6bb4a230831b5ea8 commit: ea812ff32370c426fb9c266b8824ba9338264c7c Author: Devan Franchini gentoo org> AuthorDate: Wed May 14 21:10:50 2014 +0000 Commit: Devan Franchini gentoo org> CommitDate: Wed May 14 21:10:50 2014 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/layman.git;a=commit;h=ea812ff3 layman/dbbase.py: Adds py3 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: '