Python3: Add support for raise and urlparse

Replaced raise exc_type, exc_value, exc_tb with
six.reraise(exc_type, exc_value, exc_tb)

Replaced urlparse to use from six.moves.urllib2.urlparse.urlparse

Blueprint murano-python-3-support

Change-Id: I293337889f15afbcb1f95ea37c80d5c8e88d037e
This commit is contained in:
Ravi Shekhar Jethani 2016-01-20 23:23:49 -08:00
parent b50564d65d
commit 3da14256ac
4 changed files with 11 additions and 8 deletions

View File

@ -125,7 +125,7 @@ def parallel_select(collection, func, limit=1000):
except StopIteration:
return map(lambda t: t[0], result)
else:
raise exception[0], None, exception[2]
six.reraise(exception[0], None, exception[2])
def enum(**enums):

View File

@ -76,7 +76,8 @@ class PropertySpec(Spec):
except exceptions.ContractViolationException as e:
msg = u'[{0}.{1}{2}] {3}'.format(
self.class_name, self.property_name, e.path, six.text_type(e))
raise exceptions.ContractViolationException, msg, sys.exc_info()[2]
six.reraise(exceptions.ContractViolationException,
msg, sys.exc_info()[2])
class ArgumentSpec(Spec):
@ -93,4 +94,5 @@ class ArgumentSpec(Spec):
msg = u'[{0}::{1}({2}{3})] {4}'.format(
self.class_name, self.method_name, self.arg_name,
e.path, six.text_type(e))
raise exceptions.ContractViolationException, msg, sys.exc_info()[2]
six.reraise(exceptions.ContractViolationException,
msg, sys.exc_info()[2])

View File

@ -82,7 +82,8 @@ class ApiPackageLoader(package_loader.MuranoPackageLoader):
package_definition = self._get_definition(filter_opts)
except LookupError:
exc_info = sys.exc_info()
raise exceptions.NoPackageFound(package_name), None, exc_info[2]
six.reraise(exceptions.NoPackageFound(package_name),
None, exc_info[2])
return self._to_dsl_package(
self._get_package_by_definition(package_definition))
@ -156,7 +157,7 @@ class ApiPackageLoader(package_loader.MuranoPackageLoader):
package_id, str(e)
)
exc_info = sys.exc_info()
raise pkg_exc.PackageLoadError(msg), None, exc_info[2]
six.reraise(pkg_exc.PackageLoadError(msg), None, exc_info[2])
package_file = None
try:
with tempfile.NamedTemporaryFile(delete=False) as package_file:
@ -170,7 +171,7 @@ class ApiPackageLoader(package_loader.MuranoPackageLoader):
except IOError:
msg = 'Unable to extract package data for %s' % package_id
exc_info = sys.exc_info()
raise pkg_exc.PackageLoadError(msg), None, exc_info[2]
six.reraise(pkg_exc.PackageLoadError(msg), None, exc_info[2])
finally:
try:
if package_file:

View File

@ -16,12 +16,12 @@
import copy
import datetime
import os
import urlparse
import uuid
import eventlet.event
from oslo_config import cfg
from oslo_log import log as logging
from six.moves import urllib
from yaql import specs
import murano.common.exceptions as exceptions
@ -258,7 +258,7 @@ class Agent(object):
def _is_url(self, file):
file = self._get_url(file)
parts = urlparse.urlsplit(file)
parts = urllib.parse.urlsplit(file)
if not parts.scheme or not parts.netloc:
return False
else: