Move helper functions into more coherent locations
Put together all the util functions into one single module, whenever possible.
This commit is contained in:
parent
1adaa68be9
commit
4cd9b74379
|
@ -14,7 +14,7 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from ooi.wsgi import utils
|
||||
from ooi import utils
|
||||
|
||||
import webob.exc
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
# under the License.
|
||||
|
||||
from ooi.occi.core import attribute
|
||||
from ooi.occi import helpers
|
||||
from ooi import utils
|
||||
|
||||
|
||||
class Category(object):
|
||||
|
@ -44,4 +44,4 @@ class Category(object):
|
|||
|
||||
@property
|
||||
def type_id(self):
|
||||
return helpers.join_url(self.scheme, "#%s" % self.term)
|
||||
return utils.join_url(self.scheme, "#%s" % self.term)
|
||||
|
|
|
@ -22,6 +22,7 @@ from ooi.occi.core import attribute
|
|||
from ooi.occi.core import kind
|
||||
from ooi.occi.core import mixin
|
||||
from ooi.occi import helpers
|
||||
from ooi import utils
|
||||
|
||||
|
||||
class EntityMeta(type):
|
||||
|
@ -94,4 +95,4 @@ class Entity(object):
|
|||
|
||||
@property
|
||||
def location(self):
|
||||
return helpers.join_url(self.kind.location, self.id)
|
||||
return utils.join_url(self.kind.location, self.id)
|
||||
|
|
|
@ -30,13 +30,3 @@ def check_type(obj_list, obj_type):
|
|||
|
||||
if not all([isinstance(i, obj_type) for i in obj_list]):
|
||||
raise TypeError('object must be of class %s' % obj_type)
|
||||
|
||||
|
||||
def join_url(base, parts):
|
||||
url = base
|
||||
if not isinstance(parts, (list, tuple)):
|
||||
parts = [parts]
|
||||
|
||||
for p in parts:
|
||||
url = urlparse.urljoin(url, p)
|
||||
return url
|
||||
|
|
|
@ -22,7 +22,7 @@ from ooi.occi.core import collection
|
|||
from ooi.occi.core import kind
|
||||
from ooi.occi.core import mixin
|
||||
from ooi.occi.core import resource
|
||||
from ooi.occi import helpers
|
||||
from ooi import utils
|
||||
|
||||
|
||||
class HeaderRenderer(object):
|
||||
|
@ -59,7 +59,7 @@ class ActionRenderer(CategoryRenderer):
|
|||
# We have an instance id, render it as a link
|
||||
if instance is not None:
|
||||
url = env.get("application_url", "")
|
||||
url = helpers.join_url(url, [instance, self.obj.location])
|
||||
url = utils.join_url(url, [instance, self.obj.location])
|
||||
d = {"location": url,
|
||||
"rel": self.obj.type_id}
|
||||
link = "<%(location)s>; rel=%(rel)s" % d
|
||||
|
|
|
@ -20,8 +20,8 @@ import uuid
|
|||
import webob.dec
|
||||
import webob.exc
|
||||
|
||||
from ooi import utils
|
||||
import ooi.wsgi
|
||||
import ooi.wsgi.utils
|
||||
|
||||
|
||||
tenants = {
|
||||
|
@ -184,7 +184,7 @@ class FakeOpenStackFault(ooi.wsgi.Fault):
|
|||
fault_name: {
|
||||
'code': code,
|
||||
'message': explanation}}
|
||||
self.wrapped_exc.body = ooi.wsgi.utils.utf8(json.dumps(fault_data))
|
||||
self.wrapped_exc.body = utils.utf8(json.dumps(fault_data))
|
||||
self.wrapped_exc.content_type = "application/json"
|
||||
return self.wrapped_exc
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
# under the License.
|
||||
|
||||
import six
|
||||
import six.moves.urllib.parse as urlparse
|
||||
|
||||
|
||||
def utf8(value):
|
||||
|
@ -28,3 +29,18 @@ def utf8(value):
|
|||
return value.encode('utf-8')
|
||||
assert isinstance(value, str)
|
||||
return value
|
||||
|
||||
|
||||
def join_url(base, parts):
|
||||
"""Join several parts into a url.
|
||||
|
||||
:param base: the base url
|
||||
:parts: parts to join into the url
|
||||
"""
|
||||
url = base
|
||||
if not isinstance(parts, (list, tuple)):
|
||||
parts = [parts]
|
||||
|
||||
for p in parts:
|
||||
url = urlparse.urljoin(url, p)
|
||||
return url
|
|
@ -23,8 +23,8 @@ import ooi.api.compute
|
|||
from ooi.api import query
|
||||
from ooi import exception
|
||||
from ooi.occi.core import collection
|
||||
from ooi import utils
|
||||
from ooi.wsgi import serializers
|
||||
from ooi.wsgi import utils
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
|
Loading…
Reference in New Issue