# Path: awsshell/utils.py
# class FSLayer(object):
#     """Abstraction over common OS commands.
# 
#     Provides a simpler interface given the operations needed
#     by the AWS Shell.
# 
#     """
#     def file_contents(self, filename, binary=False):
#         """Return the file for a given filename.
# 
#         If you want binary content use ``mode='rb'``.
# 
#         """
#         if binary:
#             mode = 'rb'
#         else:
#             mode = 'r'
#         try:
#             with open(filename, mode) as f:
#                 return f.read()
#         except (OSError, IOError) as e:
#             raise FileReadError(str(e))
# 
#     def file_exists(self, filename):
#         """Check if a file exists.
# 
#         This method returns true if:
# 
#             * The file exists.
#             * The filename is a file (not a directory).
# 
#         """
#         return os.path.isfile(filename)
# 
# class FileReadError(Exception):
#     pass
# 
# def build_config_file_path(file_name):
#     return os.path.join(os.path.expanduser('~'), '.aws', 'shell', file_name)
# 
# Path: awsshell/utils.py
# AWSCLI_VERSION = awscli.__version__
# class FileReadError(Exception):
# class DataOnly(HTMLParser):
# class FSLayer(object):
# class InMemoryFSLayer(object):
# def remove_html(html):
# def build_config_file_path(file_name):
# def temporary_file(mode):
#     def __init__(self):
#     def handle_data(self, data):
#     def get_data(self):
#     def file_contents(self, filename, binary=False):
#     def file_exists(self, filename):
#     def __init__(self, file_mapping):
#     def file_contents(self, filename, binary=False):
#     def file_exists(self, filename):


import os
import json
from awsshell.utils import FSLayer, FileReadError, build_config_file_path
from awsshell import utils

    def load_index(self, version_string):
        """Load the completion index for a given CLI version.

        :type version_string: str
        :param version_string: The AWS CLI version, e.g "1.9.2".

        :raises: :class:`IndexLoadError <exceptions.IndexLoadError>`
        """
        filename = self._filename_for_version(version_string)
        try:
            contents = self._fslayer.file_contents(filename)
        except FileReadError as e:
            raise IndexLoadError(str(e))
        return contents

    def _filename_for_version(self, version_string):
        return os.path.join(
            self._cache_dir, 'completions-%s.json' % version_string)

    def load_completions(self):
        """Load completions from the completion index.

        Updates the following attributes:
            * commands
            * subcommands
            * global_opts
            * args_opts
        """
        try:

# Path: awsshell/utils.py
# class FSLayer(object):
#     """Abstraction over common OS commands.
# 
#     Provides a simpler interface given the operations needed
#     by the AWS Shell.
# 
#     """
#     def file_contents(self, filename, binary=False):
#         """Return the file for a given filename.
# 
#         If you want binary content use ``mode='rb'``.
# 
#         """
#         if binary:
#             mode = 'rb'
#         else:
#             mode = 'r'
#         try:
#             with open(filename, mode) as f:
#                 return f.read()
#         except (OSError, IOError) as e:
#             raise FileReadError(str(e))
# 
#     def file_exists(self, filename):
#         """Check if a file exists.
# 
#         This method returns true if:
# 
#             * The file exists.
#             * The filename is a file (not a directory).
# 
#         """
#         return os.path.isfile(filename)
# 
# class FileReadError(Exception):
#     pass
# 
# def build_config_file_path(file_name):
#     return os.path.join(os.path.expanduser('~'), '.aws', 'shell', file_name)
# 
# Path: awsshell/utils.py
# AWSCLI_VERSION = awscli.__version__
# class FileReadError(Exception):
# class DataOnly(HTMLParser):
# class FSLayer(object):
# class InMemoryFSLayer(object):
# def remove_html(html):
# def build_config_file_path(file_name):
# def temporary_file(mode):
#     def __init__(self):
#     def handle_data(self, data):
#     def get_data(self):
#     def file_contents(self, filename, binary=False):
#     def file_exists(self, filename):
#     def __init__(self, file_mapping):
#     def file_contents(self, filename, binary=False):
#     def file_exists(self, filename):


# Path: awsshell/index/completion.py
import os
import json
from awsshell.utils import FSLayer, FileReadError, build_config_file_path
from awsshell import utils


    def load_index(self, version_string):
        """Load the completion index for a given CLI version.

        :type version_string: str
        :param version_string: The AWS CLI version, e.g "1.9.2".

        :raises: :class:`IndexLoadError <exceptions.IndexLoadError>`
        """
        filename = self._filename_for_version(version_string)
        try:
            contents = self._fslayer.file_contents(filename)
        except FileReadError as e:
            raise IndexLoadError(str(e))
        return contents

    def _filename_for_version(self, version_string):
        return os.path.join(
            self._cache_dir, 'completions-%s.json' % version_string)

    def load_completions(self):
        """Load completions from the completion index.

        Updates the following attributes:
            * commands
            * subcommands
            * global_opts
            * args_opts
        """
        try:

            index_str = self.load_index(utils.AWSCLI_VERSION)