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 1Skaoi-0007zI-M8 for garchives@archives.gentoo.org; Fri, 29 Jun 2012 13:00:57 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 259DFE055C; Fri, 29 Jun 2012 13:00:49 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id D9404E055C for ; Fri, 29 Jun 2012 13:00:48 +0000 (UTC) Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id E9C781B409B for ; Fri, 29 Jun 2012 13:00:47 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id C24B3E543E for ; Fri, 29 Jun 2012 13:00:45 +0000 (UTC) From: "Anthony G. Basile" To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Anthony G. Basile" Message-ID: <1340974225.70b36b1615bf83b30d164a674b7ae8c3968d45f6.blueness@gentoo> Subject: [gentoo-commits] proj/webapp-config:master commit in: WebappConfig/ X-VCS-Repository: proj/webapp-config X-VCS-Files: WebappConfig/config.py X-VCS-Directories: WebappConfig/ X-VCS-Committer: blueness X-VCS-Committer-Name: Anthony G. Basile X-VCS-Revision: 70b36b1615bf83b30d164a674b7ae8c3968d45f6 X-VCS-Branch: master Date: Fri, 29 Jun 2012 13:00:45 +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: e46f5c89-5fd4-466f-8b8d-452c1bc36af9 X-Archives-Hash: 7b7940bdd4046754683f55848e8f363e commit: 70b36b1615bf83b30d164a674b7ae8c3968d45f6 Author: Arfrever Frehtes Taifersar Arahesis Apache Org> AuthorDate: Thu Jun 28 23:53:47 2012 +0000 Commit: Anthony G. Basile gentoo org> CommitDate: Fri Jun 29 12:50:25 2012 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/webapp-config= .git;a=3Dcommit;h=3D70b36b16 Update configparser imports for compatibility with Python 3. Signed-off-by: Anthony G. Basile gentoo.org> --- WebappConfig/config.py | 39 +++++++++++++++++++++++---------------- 1 files changed, 23 insertions(+), 16 deletions(-) diff --git a/WebappConfig/config.py b/WebappConfig/config.py index 371602e..37fb0e2 100644 --- a/WebappConfig/config.py +++ b/WebappConfig/config.py @@ -19,12 +19,19 @@ # Dependencies # ----------------------------------------------------------------------= -- =20 -import sys, os, os.path, ConfigParser, re, socket, time - -from ConfigParser import MAX_INTERPOLATION_DEPTH, = \ - ParsingError, InterpolationMissingOptionError, = \ - InterpolationSyntaxError, = \ - InterpolationDepthError +import sys, os, os.path, re, socket, time + +try: + # Python 3 + import configparser + if sys.version_info >=3D (3, 2): + from configparser import ConfigParser as configparser_ConfigPars= er + else: + from configparser import SafeConfigParser as configparser_Config= Parser +except ImportError: + # Python 2 + import ConfigParser as configparser + from ConfigParser import SafeConfigParser as configparser_ConfigPars= er =20 import WebappConfig.server import WebappConfig.permissions as Perm @@ -40,20 +47,20 @@ from WebappConfig.permissions import PermissionMap # BashParser class # ----------------------------------------------------------------------= -- =20 -class BashConfigParser(ConfigParser.SafeConfigParser): +class BashConfigParser(configparser_ConfigParser): =20 _interpvar_match =3D re.compile(r"(%\(([^)]+)\)s|\$\{([^}]+)\})").ma= tch =20 def __init__(self, defaults=3DNone): self.error_action =3D 1 - ConfigParser.SafeConfigParser.__init__(self, defaults) + configparser_ConfigParser.__init__(self, defaults) =20 def on_error(self, action =3D 0): self.error_action =3D action =20 def get(self, section, option): try: - return ConfigParser.SafeConfigParser.get(self, section, opti= on) + return configparser_ConfigParser.get(self, section, option) except Exception as e: error =3D '\nThere is a problem with your configuration file= or' \ ' an environment variable.\n' \ @@ -69,8 +76,8 @@ class BashConfigParser(ConfigParser.SafeConfigParser): return '' =20 def _interpolate_some(self, option, accum, rest, section, map, depth= ): - if depth > MAX_INTERPOLATION_DEPTH: - raise InterpolationDepthError(option, section, rest) + if depth > configparser.MAX_INTERPOLATION_DEPTH: + raise configparser.InterpolationDepthError(option, section, = rest) while rest: p =3D rest.find("%") if p < 0: @@ -92,7 +99,7 @@ class BashConfigParser(ConfigParser.SafeConfigParser): elif c =3D=3D "(" or c =3D=3D "{": m =3D self._interpvar_match(rest) if m is None: - raise InterpolationSyntaxError(option, section, + raise configparser.InterpolationSyntaxError(option, = section, "bad interpolation variable reference %r" % rest= ) var =3D m.group(2) if not var: @@ -102,7 +109,7 @@ class BashConfigParser(ConfigParser.SafeConfigParser)= : try: v =3D map[var] except KeyError: - raise InterpolationMissingOptionError( + raise configparser.InterpolationMissingOptionError( option, section, rest, var) if "%" in v or "$" in v: self._interpolate_some(option, accum, v, @@ -110,7 +117,7 @@ class BashConfigParser(ConfigParser.SafeConfigParser)= : else: accum.append(v) else: - raise InterpolationSyntaxError( + raise configparser.InterpolationSyntaxError( option, section, "'" + c + "' must be followed by '" + c + "', '{', o= r '(', found: %r" % (rest,)) =20 @@ -187,7 +194,7 @@ class BashConfigParser(ConfigParser.SafeConfigParser)= : # raised at the end of the file and will contain a # list of all bogus lines if not e: - e =3D ParsingError(fpname) + e =3D configparser.ParsingError(fpname) e.append(lineno, repr(line)) # if any parsing errors occurred, raise an exception if e: @@ -1056,7 +1063,7 @@ class Config: if not i in ['pn', 'pvr']: try: print(i.upper() + '=3D"' + self.config.get('USER= ', i) + '"') - except InterpolationSyntaxError: + except configparser.InterpolationSyntaxError: print('# Failed to evaluate: ' + i.upper()) =20 sys.exit(0)