Submit
Path:
~
/
/
proc
/
thread-self
/
root
/
proc
/
thread-self
/
root
/
usr
/
lib
/
python2.7
/
site-packages
/
botocore
/
File Content:
loaders.pyc
� ?��Xc @ s� d Z d d l Z d d l Z d d l m Z d d l m Z d d l m Z d d l m Z m Z d d l m Z e j e � Z d � Z d e f d � � YZ d d � Z d e f d � � YZ d e f d � � YZ d S( 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: * <botocore root>/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:: <root> | |-- 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( t json( t OrderedDict( t DataNotFoundErrort UnknownServiceError( t deep_mergec s � f d � } | S( s Cache 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. c st � j f | } x$ t | j � � D] } | | 7} q# W| | j k rQ | j | S� | | | � } | | j | <| S( N( t __name__t sortedt itemst _cache( t selft argst kwargst keyt pairt data( t func( s2 /tmp/pip-build-uEGWVr/botocore/botocore/loaders.pyt _wrapper~ s ( ( R R ( ( R s2 /tmp/pip-build-uEGWVr/botocore/botocore/loaders.pyt instance_cacheu s t JSONFileLoaderc B s e Z d Z d � Z d � Z RS( se Loader JSON files. This class can load the default format of models, which is a JSON file. c C s t j j | 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( t ost patht isfile( R t file_path( ( s2 /tmp/pip-build-uEGWVr/botocore/botocore/loaders.pyt exists� s c C st | d } t j j | � s d St | d � �? } | j � j d � } t j d | � t j | d t �SWd QXd S( 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 .jsonNt rbs utf-8s Loading JSON file: %st object_pairs_hook( R R R t opent readt decodet loggert debugR t loadsR ( R R t full_patht fpt payload( ( s2 /tmp/pip-build-uEGWVr/botocore/botocore/loaders.pyt load_file� s ( R t __module__t __doc__R R$ ( ( ( s2 /tmp/pip-build-uEGWVr/botocore/botocore/loaders.pyR � s c C st | d k r t � Sg } | j t j � } x9 | D]1 } t j j t j j | � � } | j | � q2 Wt d | � 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. t extra_search_pathsN( t Nonet Loadert splitR t pathsepR t expandusert expandvarst append( t search_path_stringt pathst extra_pathsR ( ( s2 /tmp/pip-build-uEGWVr/botocore/botocore/loaders.pyt create_loader� s R) c B s� e Z d Z e Z e j j e d � Z e j j e j j d � d d � Z d g Z d d d e e d � Z e d � � Z e d � � Z e d � � Z e d � � Z e d � � Z e d d � � Z d � Z e d � � Z d e e d � Z RS( 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``. R t ~s .awst modelst sdkc C s� i | _ | d k r$ | j � } n | | _ | d k rE | | _ n g | _ | rs | j j | j | j g � n g | _ | r� | j j | j � n t � | _ d S( N( R R( t FILE_LOADER_CLASSt file_loadert _search_pathst extendt CUSTOMER_DATA_PATHt BUILTIN_DATA_PATHt _extras_typest BUILTIN_EXTRAS_TYPESt ExtrasProcessort _extras_processor( R R'