# Path: contrail_api_cli/utils.py
# class Singleton(type):
# 
#     def __init__(cls, name, bases, dict):
#         super(Singleton, cls).__init__(name, bases, dict)
#         cls.instance = None
# 
#     def __call__(cls, *args, **kw):
#         if cls.instance is None:
#             cls.instance = super(Singleton, cls).__call__(*args, **kw)
#         return cls.instance
# 
# class Path(PurePosixPath):
#     _flavour = APIFlavour()
# 
#     @classmethod
#     def _from_parsed_parts(cls, drv, root, parts, init=True):
#         if parts:
#             parts = [root] + os.path.relpath(os.path.join(*parts),
#                                              start=root).split(os.path.sep)
#             parts = [p for p in parts if p not in (".", "")]
#         return super(cls, Path)._from_parsed_parts(drv, root, parts, init)
# 
#     def __init__(self, *args):
#         self.meta = {}
# 
#     @property
#     def base(self):
#         try:
#             return self.parts[1]
#         except IndexError:
#             pass
#         return ''
# 
#     @property
#     def is_root(self):
#         return len(self.parts) == 1 and self.root == "/"
# 
#     @property
#     def is_fq_name(self):
#         return not self.is_uuid
# 
#     @property
#     def is_uuid(self):
#         try:
#             UUID(self.name, version=4)
#         except (ValueError, IndexError):
#             return False
#         return True
# 
#     @property
#     def is_resource(self):
#         """The path is a resource if it is not a Collection
# 
#         :raises AbsPathRequired: path doesn't start with '/'
#         """
#         return not self.is_collection
# 
#     @property
#     def is_collection(self):
#         """The path is a Collection if there is only one part in the path. Be
#         careful, the root is a Collection.
# 
#         :raises AbsPathRequired: path doesn't start with '/'
#         """
#         if not self.is_absolute():
#             raise AbsPathRequired()
#         return self.base == self.name
# 
#     def relative_to(self, path):
#         try:
#             return PurePosixPath.relative_to(self, path)
#         except ValueError:
#             return self


from six import add_metaclass
from .utils import Singleton, Path
# -*- coding: utf-8 -*-
from __future__ import unicode_literals



class SchemaNotInitialized(Exception):
    pass


class SessionNotInitialized(Exception):
    pass


class ShellContext(object):
    current_path = Path("/")


@add_metaclass(Singleton)
class Context(object):
    _schema = None
    _shell = ShellContext
    _session = None

    @property
    def schema(self):
        if self._schema is None:
            raise SchemaNotInitialized("The schema must be first initialized")
        else:

# Path: contrail_api_cli/utils.py
# class Singleton(type):
# 
#     def __init__(cls, name, bases, dict):
#         super(Singleton, cls).__init__(name, bases, dict)
#         cls.instance = None
# 
#     def __call__(cls, *args, **kw):
#         if cls.instance is None:
#             cls.instance = super(Singleton, cls).__call__(*args, **kw)
#         return cls.instance
# 
# class Path(PurePosixPath):
#     _flavour = APIFlavour()
# 
#     @classmethod
#     def _from_parsed_parts(cls, drv, root, parts, init=True):
#         if parts:
#             parts = [root] + os.path.relpath(os.path.join(*parts),
#                                              start=root).split(os.path.sep)
#             parts = [p for p in parts if p not in (".", "")]
#         return super(cls, Path)._from_parsed_parts(drv, root, parts, init)
# 
#     def __init__(self, *args):
#         self.meta = {}
# 
#     @property
#     def base(self):
#         try:
#             return self.parts[1]
#         except IndexError:
#             pass
#         return ''
# 
#     @property
#     def is_root(self):
#         return len(self.parts) == 1 and self.root == "/"
# 
#     @property
#     def is_fq_name(self):
#         return not self.is_uuid
# 
#     @property
#     def is_uuid(self):
#         try:
#             UUID(self.name, version=4)
#         except (ValueError, IndexError):
#             return False
#         return True
# 
#     @property
#     def is_resource(self):
#         """The path is a resource if it is not a Collection
# 
#         :raises AbsPathRequired: path doesn't start with '/'
#         """
#         return not self.is_collection
# 
#     @property
#     def is_collection(self):
#         """The path is a Collection if there is only one part in the path. Be
#         careful, the root is a Collection.
# 
#         :raises AbsPathRequired: path doesn't start with '/'
#         """
#         if not self.is_absolute():
#             raise AbsPathRequired()
#         return self.base == self.name
# 
#     def relative_to(self, path):
#         try:
#             return PurePosixPath.relative_to(self, path)
#         except ValueError:
#             return self


# Path: contrail_api_cli/context.py
from six import add_metaclass
from .utils import Singleton, Path

# -*- coding: utf-8 -*-
from __future__ import unicode_literals



class SchemaNotInitialized(Exception):
    pass


class SessionNotInitialized(Exception):
    pass


class ShellContext(object):
    current_path = Path("/")


@add_metaclass(Singleton)
class Context(object):
    _schema = None
    _shell = ShellContext
    _session = None

    @property
    def schema(self):
        if self._schema is None:
            raise SchemaNotInitialized("The schema must be first initialized")
        else:

            return self._schema