ó 9(Zc@sÞdZddlZddlZddlmZddlmZddlmZddlm Z m Z ddl m Z ej eƒZd„Zd efd „ƒYZdd „Zd efd „ƒYZdefd„ƒYZdS(sÿ Module for loading various model files. This module provides the classes that are used to load models used by botocore. This can include: * Service models (e.g. the model for EC2, S3, DynamoDB, etc.) * Service model extras which customize the service models * Other models associated with a service (pagination, waiters) * Non service-specific config (Endpoint data, retry config) Loading a module is broken down into several steps: * Determining the path to load * Search the data_path for files to load * The mechanics of loading the file * Searching for extras and applying them to the loaded file The last item is used so that other faster loading mechanism besides the default JSON loader can be used. The Search Path =============== Similar to how the PATH environment variable is to finding executables and the PYTHONPATH environment variable is to finding python modules to import, the botocore loaders have the concept of a data path exposed through AWS_DATA_PATH. This enables end users to provide additional search paths where we will attempt to load models outside of the models we ship with botocore. When you create a ``Loader``, there are two paths automatically added to the model search path: * /data/ * ~/.aws/models The first value is the path where all the model files shipped with botocore are located. The second path is so that users can just drop new model files in ``~/.aws/models`` without having to mess around with the AWS_DATA_PATH. The AWS_DATA_PATH using the platform specific path separator to separate entries (typically ``:`` on linux and ``;`` on windows). Directory Layout ================ The Loader expects a particular directory layout. In order for any directory specified in AWS_DATA_PATH to be considered, it must have this structure for service models:: | |-- servicename1 | |-- 2012-10-25 | |-- service-2.json |-- ec2 | |-- 2014-01-01 | | |-- paginators-1.json | | |-- service-2.json | | |-- waiters-2.json | |-- 2015-03-01 | |-- paginators-1.json | |-- service-2.json | |-- waiters-2.json | |-- service-2.sdk-extras.json That is: * The root directory contains sub directories that are the name of the services. * Within each service directory, there's a sub directory for each available API version. * Within each API version, there are model specific files, including (but not limited to): service-2.json, waiters-2.json, paginators-1.json The ``-1`` and ``-2`` suffix at the end of the model files denote which version schema is used within the model. Even though this information is available in the ``version`` key within the model, this version is also part of the filename so that code does not need to load the JSON model in order to determine which version to use. The ``sdk-extras`` and similar files represent extra data that needs to be applied to the model after it is loaded. Data in these files might represent information that doesn't quite fit in the original models, but is still needed for the sdk. For instance, additional operation parameters might be added here which don't represent the actual service api. iÿÿÿÿN(t BOTOCORE_ROOT(tjson(t OrderedDict(tDataNotFoundErrortUnknownServiceError(t deep_mergecs‡fd†}|S(sCache the result of a method on a per instance basis. This is not a general purpose caching decorator. In order for this to be used, it must be used on methods on an instance, and that instance *must* provide a ``self._cache`` dictionary. cstˆjf|}x$t|jƒƒD]}||7}q#W||jkrQ|j|Sˆ|||Ž}||j|<|S(N(t__name__tsortedtitemst_cache(tselftargstkwargstkeytpairtdata(tfunc(s2/tmp/pip-build-wDUJoH/botocore/botocore/loaders.pyt_wrapper~s  ((RR((Rs2/tmp/pip-build-wDUJoH/botocore/botocore/loaders.pytinstance_cacheus  tJSONFileLoadercBs eZdZd„Zd„ZRS(seLoader JSON files. This class can load the default format of models, which is a JSON file. cCstjj|dƒS(sæChecks if the file exists. :type file_path: str :param file_path: The full path to the file to load without the '.json' extension. :return: True if file path exists, False otherwise. s.json(tostpathtisfile(R t file_path((s2/tmp/pip-build-wDUJoH/botocore/botocore/loaders.pytexistss cCst|d}tjj|ƒs dSt|dƒ?}|jƒjdƒ}tjd|ƒtj |dt ƒSWdQXdS(síAttempt to load the file path. :type file_path: str :param file_path: The full path to the file to load without the '.json' extension. :return: The loaded data if it exists, otherwise None. s.jsonNtrbsutf-8sLoading JSON file: %stobject_pairs_hook( RRRtopentreadtdecodetloggertdebugRtloadsR(R Rt full_pathtfptpayload((s2/tmp/pip-build-wDUJoH/botocore/botocore/loaders.pyt load_fileœs (Rt __module__t__doc__RR$(((s2/tmp/pip-build-wDUJoH/botocore/botocore/loaders.pyRŠs cCst|dkrtƒSg}|jtjƒ}x9|D]1}tjjtjj|ƒƒ}|j|ƒq2Wtd|ƒS(sˆCreate a Loader class. This factory function creates a loader given a search string path. :type search_string_path: str :param search_string_path: The AWS_DATA_PATH value. A string of data path values separated by the ``os.path.pathsep`` value, which is typically ``:`` on POSIX platforms and ``;`` on windows. :return: A ``Loader`` instance. textra_search_pathsN( tNonetLoadertsplitRtpathsepRt expandusert expandvarstappend(tsearch_path_stringtpathst extra_pathsR((s2/tmp/pip-build-wDUJoH/botocore/botocore/loaders.pyt create_loader²s  R)cBsõeZdZeZejjedƒZ ejjejj dƒddƒZ dgZ dddeed„Zed„ƒZed„ƒZed „ƒZed „ƒZed „ƒZedd „ƒZd „Zed„ƒZdeed„ZRS(sôFind and load data models. This class will handle searching for and loading data models. The main method used here is ``load_service_model``, which is a convenience method over ``load_data`` and ``determine_latest_version``. Rt~s.awstmodelstsdkcCs¨i|_|dkr$|jƒ}n||_|dk rE||_n g|_|rs|jj|j|jgƒng|_|r˜|jj|j ƒnt ƒ|_ dS(N( R R(tFILE_LOADER_CLASSt file_loadert _search_pathstextendtCUSTOMER_DATA_PATHtBUILTIN_DATA_PATHt _extras_typestBUILTIN_EXTRAS_TYPEStExtrasProcessort_extras_processor(R R'R7tcachetinclude_default_search_pathstinclude_default_extras((s2/tmp/pip-build-wDUJoH/botocore/botocore/loaders.pyt__init__Ûs       cCs|jS(N(R8(R ((s2/tmp/pip-build-wDUJoH/botocore/botocore/loaders.pyt search_pathsðscCs|jS(N(R<(R ((s2/tmp/pip-build-wDUJoH/botocore/botocore/loaders.pyt extras_typesôsc Csîtƒ}xØ|jƒD]Ê}gtj|ƒD]-}tjjtjj||ƒƒr,|^q,}x~|D]v}tjj||ƒ}tj|ƒ}xI|D]A} tjj|| |ƒ} |jj| ƒr—|j |ƒPq—q—WqfWqWt |ƒS(spList all known services. This will traverse the search path and look for all known services. :type type_name: str :param type_name: The type of the service (service-2, paginators-1, waiters-2, etc). This is needed because the list of available services depends on the service type. For example, the latest API version available for a resource-1.json file may not be the latest API version available for a services-2.json file. :return: A list of all services. The list of services will be sorted. ( tsett_potential_locationsRtlistdirRtisdirtjoinR7RtaddR( R t type_nametservicest possible_pathtdtpossible_servicest service_namet full_dirnamet api_versionst api_versiontfull_load_path((s2/tmp/pip-build-wDUJoH/botocore/botocore/loaders.pytlist_available_servicesøs -     cCst|j||ƒƒS(s Find the latest API version available for a service. :type service_name: str :param service_name: The name of the service. :type type_name: str :param type_name: The type of the service (service-2, paginators-1, waiters-2, etc). This is needed because the latest API version available can depend on the service type. For example, the latest API version available for a resource-1.json file may not be the latest API version available for a services-2.json file. :rtype: str :return: The latest API version. If the service does not exist or does not have any available API data, then a ``DataNotFoundError`` exception will be raised. (tmaxtlist_api_versions(R RQRL((s2/tmp/pip-build-wDUJoH/botocore/botocore/loaders.pytdetermine_latest_version!scCs¥tƒ}xw|j|dtdtƒD]Z}xQtj|ƒD]@}tjj|||ƒ}|jj|ƒr;|j |ƒq;q;Wq%W|s›t d|ƒ‚nt |ƒS(syList all API versions available for a particular service type :type service_name: str :param service_name: The name of the service :type type_name: str :param type_name: The type name for the service (i.e service-2, paginators-1, etc.) :rtype: list :return: A list of API version strings in sorted order. t must_existtis_dirt data_path( RFRGtTrueRRHRRJR7RRKRR(R RQRLtknown_api_versionsRNtdirnameR!((s2/tmp/pip-build-wDUJoH/botocore/botocore/loaders.pyRX8s  cCs¶|j|ƒ}||krBtd|ddjt|ƒƒƒ‚n|dkrc|j||ƒ}ntjj|||ƒ}|j|ƒ}|j |||ƒ}|j j ||ƒ|S(sJLoad a botocore service model This is the main method for loading botocore models (e.g. a service model, pagination configs, waiter configs, etc.). :type service_name: str :param service_name: The name of the service (e.g ``ec2``, ``s3``). :type type_name: str :param type_name: The model type. Valid types include, but are not limited to: ``service-2``, ``paginators-1``, ``waiters-2``. :type api_version: str :param api_version: The API version to load. If this is not provided, then the latest API version will be used. :type load_extras: bool :param load_extras: Whether or not to load the tool extras which contain additional data to be added to the model. :raises: UnknownServiceError if there is no known service with the provided service_name. :raises: DataNotFoundError if no data could be found for the service_name/type_name/api_version. :return: The loaded data, as a python type (e.g. dict, list, etc). RQtknown_service_namess, N( RVRRJRR(RYRRt load_datat _find_extrasR?tprocess(R RQRLRTtknown_servicesR!tmodelt extras_data((s2/tmp/pip-build-wDUJoH/botocore/botocore/loaders.pytload_service_modelVs   ccsfx_|jD]T}d||f}tjj|||ƒ}y|j|ƒVWq tk r]q Xq WdS(s-Creates an iterator over all the extras data.s %s.%s-extrasN(RERRRJRaR(R RQRLRTt extras_typet extras_nameR!((s2/tmp/pip-build-wDUJoH/botocore/botocore/loaders.pyRb‡s cCsOx9|j|ƒD](}|jj|ƒ}|dk r|SqWtd|ƒ‚dS(s0Load data given a data path. This is a low level method that will search through the various search paths until it's able to load a value. This is typically only needed to load *non* model files (such as _endpoints and _retry). If you need to load model files, you should prefer ``load_service_model``. :type name: str :param name: The data path, i.e ``ec2/2015-03-01/service-2``. :return: The loaded data. If no data could be found then a DataNotFoundError is raised. R\N(RGR7R$R(R(R tnameRNtfound((s2/tmp/pip-build-wDUJoH/botocore/botocore/loaders.pyRa’s  ccsŸx˜|jD]}tjj|ƒr |}|dk rLtjj||ƒ}n|sZ|Vq—|rztjj|ƒrz|Vq—tjj|ƒr—|Vq—q q WdS(N(RDRRRIR(RJR(R RjRZR[RR!((s2/tmp/pip-build-wDUJoH/botocore/botocore/loaders.pyRGªs N(RR%R&RR6RRRJRR;R,R:R=R(R]RCtpropertyRDRERRVRYRXRgRbRatFalseRG(((s2/tmp/pip-build-wDUJoH/botocore/botocore/loaders.pyR)Ês(   )0 R>cBs eZdZd„Zd„ZRS(s5Processes data from extras files into service models.cCs%x|D]}|j||ƒqWdS(s$Processes data from a list of loaded extras files into a model :type original_model: dict :param original_model: The service model to load all the extras into. :type extra_models: iterable of dict :param extra_models: A list of loaded extras models. N(t_process(R toriginal_modelt extra_modelstextras((s2/tmp/pip-build-wDUJoH/botocore/botocore/loaders.pyRc¾s cCs$d|kr t||dƒndS(s3Process a single extras model into a service model.tmergeN(R(R Ret extra_model((s2/tmp/pip-build-wDUJoH/botocore/botocore/loaders.pyRnÊs (RR%R&RcRn(((s2/tmp/pip-build-wDUJoH/botocore/botocore/loaders.pyR>¼s (R&RtloggingtbotocoreRtbotocore.compatRRtbotocore.exceptionsRRtbotocore.utilsRt getLoggerRRRtobjectRR(R2R)R>(((s2/tmp/pip-build-wDUJoH/botocore/botocore/loaders.pytgs   ( ò