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 7CBF91381FA for ; Wed, 14 May 2014 23:49:57 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 4A265E0A03; Wed, 14 May 2014 23:49:56 +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 9143AE0A68 for ; Wed, 14 May 2014 23:49:55 +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 B9ABA33FF5B for ; Wed, 14 May 2014 23:49:54 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by spoonbill.gentoo.org (Postfix) with ESMTP id 867C6182DB for ; Wed, 14 May 2014 23:49:52 +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: <1400111263.dfbbf55260e78477d8ee5f6843f4f055d60c5433.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: dfbbf55260e78477d8ee5f6843f4f055d60c5433 X-VCS-Branch: gsoc2014 Date: Wed, 14 May 2014 23:49:52 +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: 90089878-2a87-48e5-9025-48067673563a X-Archives-Hash: e47efd9c36e46785436837a737b8bfa9 commit: dfbbf55260e78477d8ee5f6843f4f055d60c5433 Author: Devan Franchini gentoo org> AuthorDate: Wed May 14 21:10:50 2014 +0000 Commit: Devan Franchini gentoo org> CommitDate: Wed May 14 23:47:43 2014 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/layman.git;a=commit;h=dfbbf552 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: '