diff --git a/imagefactory_plugins/EC2/EC2.py b/imagefactory_plugins/EC2/EC2.py index 9e927f99..bac6d894 100644 --- a/imagefactory_plugins/EC2/EC2.py +++ b/imagefactory_plugins/EC2/EC2.py @@ -61,7 +61,11 @@ def __init__(self): self.log = logging.getLogger('%s.%s' % (__name__, self.__class__.__name__)) config_obj = ApplicationConfiguration() self.app_config = config_obj.configuration - self.oz_config = configparser.SafeConfigParser() + try: + self.oz_config = configparser.SafeConfigParser() + except AttributeError: + # SafeConfigParser was deprecated in Python 3.2 + self.oz_config = configparser.ConfigParser() self.oz_config.read("/etc/oz/oz.cfg") self.oz_config.set('paths', 'output_dir', self.app_config["imgdir"]) self.guest = None diff --git a/imagefactory_plugins/IndirectionCloud/IndirectionCloud.py b/imagefactory_plugins/IndirectionCloud/IndirectionCloud.py index ff364db8..a41dc746 100644 --- a/imagefactory_plugins/IndirectionCloud/IndirectionCloud.py +++ b/imagefactory_plugins/IndirectionCloud/IndirectionCloud.py @@ -282,7 +282,11 @@ def oz_refresh_customizations(self, partial_tdl): def _init_oz(self): # populate a config object to pass to OZ; this allows us to specify our # own output dir but inherit other Oz behavior - self.oz_config = configparser.SafeConfigParser() + try: + self.oz_config = configparser.SafeConfigParser() + except AttributeError: + # SafeConfigParser was deprecated in Python 3.2 + self.oz_config = configparser.ConfigParser() if self.oz_config.read("/etc/oz/oz.cfg") != []: self.oz_config.set('paths', 'output_dir', self.app_config["imgdir"]) if "oz_data_dir" in self.app_config: diff --git a/imagefactory_plugins/Nova/Nova.py b/imagefactory_plugins/Nova/Nova.py index ff7cc08f..9a8c777d 100644 --- a/imagefactory_plugins/Nova/Nova.py +++ b/imagefactory_plugins/Nova/Nova.py @@ -28,7 +28,11 @@ from time import sleep from base64 import b64decode #TODO: remove dependency on Oz -from configparser import SafeConfigParser +try: + from configparser import SafeConfigParser as ConfigParser +except AttributeError: + # SafeConfigParser was deprecated in Python 3.2 + from configparser import ConfigParser from oz.TDL import TDL import oz.GuestFactory @@ -438,7 +442,7 @@ def _confirm_ssh_access(self, guest, addr, timeout=300): return confirmation def _oz_config(self, private_key_file): - config = SafeConfigParser() + config = ConfigParser() if config.read("/etc/oz/oz.cfg"): config.set('paths', 'output_dir', self.app_config['imgdir']) config.set('paths', 'sshprivkey', private_key_file) diff --git a/imagefactory_plugins/Rackspace/Rackspace.py b/imagefactory_plugins/Rackspace/Rackspace.py index e045d145..ae7fe998 100644 --- a/imagefactory_plugins/Rackspace/Rackspace.py +++ b/imagefactory_plugins/Rackspace/Rackspace.py @@ -64,7 +64,11 @@ def __init__(self): self.log = logging.getLogger('%s.%s' % (__name__, self.__class__.__name__)) config_obj = ApplicationConfiguration() self.app_config = config_obj.configuration - self.oz_config = configparser.SafeConfigParser() + try: + self.oz_config = configparser.SafeConfigParser() + except AttributeError: + # SafeConfigParser was deprecated in Python 3.2 + self.oz_config = configparser.ConfigParser() self.oz_config.read("/etc/oz/oz.cfg") self.oz_config.set('paths', 'output_dir', self.app_config["imgdir"]) self.active_image = None diff --git a/imagefactory_plugins/TinMan/TinMan.py b/imagefactory_plugins/TinMan/TinMan.py index 219a78e4..27b3d230 100644 --- a/imagefactory_plugins/TinMan/TinMan.py +++ b/imagefactory_plugins/TinMan/TinMan.py @@ -269,7 +269,11 @@ def _init_oz(self): # populate a config object to pass to OZ; this allows us to specify our # own output dir but inherit other Oz behavior - self.oz_config = configparser.SafeConfigParser() + try: + self.oz_config = configparser.SafeConfigParser() + except AttributeError: + # SafeConfigParser was deprecated in Python 3.2 + self.oz_config = configparser.ConfigParser() if self.oz_config.read("/etc/oz/oz.cfg") != []: if self.parameters.get("oz_overrides", None) != None: oz_overrides = json.loads(self.parameters.get("oz_overrides",None).replace("'", "\"")) diff --git a/imgfac/rest/bottle.py b/imgfac/rest/bottle.py index 58871098..b706e901 100644 --- a/imgfac/rest/bottle.py +++ b/imgfac/rest/bottle.py @@ -35,8 +35,8 @@ if _cmd_options.server and _cmd_options.server.startswith('gevent'): import gevent.monkey; gevent.monkey.patch_all() -import base64, cgi, email.utils, functools, hmac, imp, itertools, mimetypes,\ - os, re, subprocess, sys, tempfile, threading, time, warnings +import base64, cgi, email.utils, functools, hmac, itertools, mimetypes,\ + os, re, subprocess, sys, tempfile, threading, time, types, warnings from datetime import date as datedate, datetime, timedelta from tempfile import TemporaryFile @@ -842,17 +842,19 @@ def default_error_handler(self, res): return tob(template(ERROR_PAGE_TEMPLATE, e=res)) def _handle(self, environ): - path = environ['bottle.raw_path'] = environ['PATH_INFO'] - if py3k: - try: - environ['PATH_INFO'] = path.encode('latin1').decode('utf8') - except UnicodeError: - return HTTPError(400, 'Invalid path string. Expected UTF-8') - try: + environ['bottle.app'] = self request.bind(environ) response.bind() + + path = environ['bottle.raw_path'] = environ['PATH_INFO'] + if py3k: + try: + environ['PATH_INFO'] = path.encode('latin1').decode('utf8') + except UnicodeError: + return HTTPError(400, 'Invalid path string. Expected UTF-8') + try: self.trigger_hook('before_request') route, args = self.router.match(environ) @@ -1779,7 +1781,7 @@ def __init__(self, name, impmask): ''' Create a virtual package that redirects imports (see PEP 302). ''' self.name = name self.impmask = impmask - self.module = sys.modules.setdefault(name, imp.new_module(name)) + self.module = sys.modules.setdefault(name, types.ModuleType(name)) self.module.__dict__.update({'__file__': __file__, '__path__': [], '__all__': [], '__loader__': self}) sys.meta_path.append(self)