From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1Qg1hP-0007rO-DT for garchives@archives.gentoo.org; Sun, 10 Jul 2011 21:38:02 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 8FA9721C0FC; Sun, 10 Jul 2011 21:37:51 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 5E38521C0FC for ; Sun, 10 Jul 2011 21:37:51 +0000 (UTC) Received: from pelican.gentoo.org (unknown [66.219.59.40]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id D46572AC155 for ; Sun, 10 Jul 2011 21:37:50 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id E802480042 for ; Sun, 10 Jul 2011 21:37:49 +0000 (UTC) From: "Michał Górny" To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Michał Górny" Message-ID: <780400ffe4ed184315686cca84244b8ad0f10c94.mgorny@gentoo> Subject: [gentoo-commits] proj/gentoopm:master commit in: gentoopm/bash/ X-VCS-Repository: proj/gentoopm X-VCS-Files: gentoopm/bash/bashserver.py X-VCS-Directories: gentoopm/bash/ X-VCS-Committer: mgorny X-VCS-Committer-Name: Michał Górny X-VCS-Revision: 780400ffe4ed184315686cca84244b8ad0f10c94 Date: Sun, 10 Jul 2011 21:37:49 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: X-Archives-Hash: 22d4be76ced2776cdd1aeff8cb65e860 commit: 780400ffe4ed184315686cca84244b8ad0f10c94 Author: Micha=C5=82 G=C3=B3rny gentoo org> AuthorDate: Sun Jul 10 21:38:21 2011 +0000 Commit: Micha=C5=82 G=C3=B3rny gentoo org> CommitDate: Sun Jul 10 21:38:21 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/gentoopm.git;= a=3Dcommit;h=3D780400ff BashServer: implement optimised get_env(). --- gentoopm/bash/bashserver.py | 19 +++++++++++++++---- 1 files changed, 15 insertions(+), 4 deletions(-) diff --git a/gentoopm/bash/bashserver.py b/gentoopm/bash/bashserver.py index 7e490ee..8fb8e09 100644 --- a/gentoopm/bash/bashserver.py +++ b/gentoopm/bash/bashserver.py @@ -51,12 +51,23 @@ class BashServer(BashParser): self._bashproc.stdin.write('\n'.encode('ASCII')) self._bashproc.stdin.flush() =20 - def __getitem__(self, k): - self._bashproc.stdin.write(('${%s}\n' % k).encode('ASCII')) - self._bashproc.stdin.flush() - + def _read1(self): f =3D self._bashproc.stdout buf =3D ' ' while buf[-1] !=3D '\0': buf +=3D f.read(1) return buf[1:-1].decode('utf-8') + + def __getitem__(self, k): + self._bashproc.stdin.write(('${%s}\n' % k).encode('ASCII')) + self._bashproc.stdin.flush() + + return self._read1() + + def get_env(self, *varlist): + q =3D ' '.join(['"${%s}"' % v for v in varlist]) + self._bashproc.stdin.write(('%s\n' % q).encode('ASCII')) + self._bashproc.stdin.flush() + + ret =3D [self._read1() for v in varlist] + return dict(zip(varlist, ret))