
    vKgI                         S r SSKrSSKrSSKJr  SSKJrJrJr  SSK	J
r
Jr  SSKJr  S\0r\(       a  SSKJr  \\S	'   \R$                  " \5      rS
 r " S S5      rSS jr " S S5      r " S S5      rg)a  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.
    N)BOTOCORE_ROOT)HAS_GZIPOrderedDictjson)DataNotFoundErrorUnknownServiceError
deep_mergez.json)openz.json.gzc                    ^  U 4S jnU$ )zCache 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                    > TR                   4U-   n[        UR                  5       5       H  nX4-  nM	     X0R                  ;   a  U R                  U   $ T" U /UQ70 UD6nXPR                  U'   U$ N)__name__sorteditems_cache)selfargskwargskeypairdatafuncs         P/var/www/highfloat_scraper/venv/lib/python3.13/site-packages/botocore/loaders.py_wrapper instance_cache.<locals>._wrapper   sn    }}%6<<>*DKC +++;;s##D*4*6*C     )r   r   s   ` r   instance_cacher      s     Or   c                   *    \ rS rSrSrS rS rS rSrg)JSONFileLoader   z]Loader JSON files.

This class can load the default format of models, which is a JSON file.

c                 n    [          H+  n[        R                  R                  X-   5      (       d  M+    g   g)zChecks 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.

TF)_JSON_OPEN_METHODSospathisfile)r   	file_pathexts      r   existsJSONFileLoader.exists   s+     &Cww~~io.. & r   c                 .   [         R                  R                  U5      (       d  g U" US5       nUR                  5       R	                  S5      nS S S 5        [
        R                  SU5        [        R                  " W[        S9$ ! , (       d  f       N== f)Nrbzutf-8zLoading JSON file: %s)object_pairs_hook)
r%   r&   r'   readdecodeloggerdebugr   loadsr   )r   	full_pathopen_methodfppayloads        r   
_load_fileJSONFileLoader._load_file   sl    ww~~i(( D)Rggi&&w/G * 	,i8zz'[AA	 *)s    B
Bc                 t    [         R                  5        H   u  p#U R                  X-   U5      nUc  M  Us  $    g)zAttempt 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.

N)r$   r   r8   )r   r(   r)   r5   r   s        r   	load_fileJSONFileLoader.load_file   s<     !3 8 8 :C??9?K@D !; r   r   N)	r   
__module____qualname____firstlineno____doc__r*   r8   r;   __static_attributes__r   r   r   r!   r!      s    
Br   r!   c                    U c
  [        5       $ / nU R                  [        R                  5      nU HP  n[        R                  R                  [        R                  R                  U5      5      nUR                  U5        MR     [        US9$ )ah  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.

)extra_search_paths)Loadersplitr%   pathsepr&   
expanduser
expandvarsappend)search_path_stringpathsextra_pathsr&   s       r   create_loaderrM      sp     !xE$**2::6Kww!!"''"4"4T":;T  U++r   c                   j   \ rS rSrSr\r\R                  R                  \
S5      r\R                  R                  \R                  R                  S5      SS5      rS/r     SS	 jr\S
 5       r\S 5       r\S 5       r\S 5       r\S 5       r\SS j5       rS r\S 5       rS rSS jrS rSrg)rD      zFind 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   ~z.awsmodelssdkNc                 Z   0 U l         Uc  U R                  5       nX l        Ub  Xl        O/ U l        U(       a1  U R                  R	                  U R
                  U R                  /5        / U l        U(       a%  U R                  R	                  U R                  5        [        5       U l
        g r   )r   FILE_LOADER_CLASSfile_loader_search_pathsextendCUSTOMER_DATA_PATHBUILTIN_DATA_PATH_extras_typesBUILTIN_EXTRAS_TYPESExtrasProcessor_extras_processor)r   rC   rU   cacheinclude_default_search_pathsinclude_default_extrass         r   __init__Loader.__init__   s     002K&)!3!#D'%%(($*@*@A  !%%d&?&?@!0!2r   c                     U R                   $ r   )rV   r   s    r   search_pathsLoader.search_paths      !!!r   c                     U R                   $ r   )rZ   rd   s    r   extras_typesLoader.extras_types  rg   r   c           
      n   [        5       nU R                  5        GH  n[        R                  " U5       Vs/ sHH  n[        R                  R                  [        R                  R                  X45      5      (       d  MF  UPMJ     nnU H  n[        R                  R                  X65      n[        R                  " U5      nU HW  n	[        R                  R                  XyU5      n
U R                  R                  U
5      (       d  ME  UR                  U5          M     M     GM
     [        U5      $ s  snf )a  List 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.

)set_potential_locationsr%   listdirr&   isdirjoinrU   r*   addr   )r   	type_nameservicespossible_pathdpossible_servicesservice_namefull_dirnameapi_versionsapi_versionfull_load_paths              r   list_available_servicesLoader.list_available_services  s    & 5!668M M2!2A77==m!?@ 2  !
 !2!ww||MH!zz,7#/K%'WW\\$9&N ''..~>> \2 $0 !2 9* h!s   AD2?D2c                 6    [        U R                  X5      5      $ )a  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.

)maxlist_api_versions)r   rw   rr   s      r   determine_latest_versionLoader.determine_latest_versionB  s    * 4)),BCCr   c                 \   [        5       nU R                  USSS9 Hs  n[        R                  " U5       HV  n[        R                  R                  XEU5      nU R                  R                  U5      (       d  ME  UR                  U5        MX     Mu     U(       d	  [        US9e[        U5      $ )a9  List 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_existis_dir	data_path)rl   rm   r%   rn   r&   rp   rU   r*   rq   r   r   )r   rw   rr   known_api_versionsrt   dirnamer4   s          r   r   Loader.list_api_versionsY  s     !U!66T$ 7 
M ::m4GGLLK	 ##**955&**73 5
 "#l;;())r   c                 Z   U R                  U5      nX;  a"  [        USR                  [        U5      5      S9eUc  U R	                  X5      n[
        R                  R                  XU5      nU R                  U5      nU R                  XU5      nU R                  R                  Xg5        U$ )a  Load 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).
z, )rw   known_service_names)r|   r   rp   r   r   r%   r&   	load_data_find_extrasr]   process)r   rw   rr   rz   known_servicesr4   modelextras_datas           r   load_service_modelLoader.load_service_modelw  s    @ 55i@-%)$(IIf^.D$E  77K GGLLIF	y) ''M&&u:r   c              #      #    U R                    H?  nU SU S3n[        R                  R                  XU5      n U R	                  U5      v   MA     g! [
         a     MQ  f = f7f)z-Creates an iterator over all the extras data..z-extrasN)ri   r%   r&   rp   r   r   )r   rw   rr   rz   extras_typeextras_namer4   s          r   r   Loader._find_extras  sb     ,,K&KqW=K\LInnY// - % s(   8A$AA$
A!A$ A!!A$c                     U R                  U5       H&  nU R                  R                  U5      nUc  M#  X24s  $    [        US9e)a:  Same as ``load_data`` but returns file path as second return value.

:type name: str
:param name: The data path, i.e ``ec2/2015-03-01/service-2``.

:return: Tuple of the loaded data and the path to the data file
    where the data was loaded from. If no data could be found then a
    DataNotFoundError is raised.
r   )rm   rU   r;   r   )r   namert   founds       r   load_data_with_pathLoader.load_data_with_path  sK     "66t<M$$..}=E ++ =  $//r   c                 ,    U R                  U5      u  p#U$ )a9  Load 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``.  Use ``load_data_with_path`` to get the
data path of the data file as second return value.

: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   )r   r   r   _s       r   r   Loader.load_data  s      **40r   c              #     #    U R                    H  n[        R                  R                  U5      (       d  M)  UnUb  [        R                  R	                  XA5      nU(       d  Uv   MZ  U(       a*  [        R                  R                  U5      (       a  Uv   M  [        R                  R                  U5      (       d  M  Uv   M     g 7fr   )re   r%   r&   ro   rp   r*   )r   r   r   r   r&   r4   s         r   rm   Loader._potential_locations  s      %%Dww}}T"" 	# "T 8I!#O"''--	":":'	22' &s   2C	BC	 	C	c                     [         R                  R                  [         R                  R                  U5      5      nUR	                  U R
                  5      $ )au  Whether a given path is within the package's data directory.

This method can be used together with load_data_with_path(name)
to determine if data has been loaded from a file bundled with the
package, as opposed to a file in a separate location.

:type path: str
:param path: The file path to check.

:return: Whether the given path is within the package's data directory.
)r%   r&   rG   rH   
startswithrY   )r   r&   s     r   is_builtin_pathLoader.is_builtin_path  s<     ww!!"''"4"4T":;t5566r   )r   r]   rZ   rV   rU   )NNNTTr   )NFF)r   r=   r>   r?   r@   r!   rT   r%   r&   rp   r   rY   rG   rX   r[   ra   propertyre   ri   r   r|   r   r   r   r   r   r   rm   r   rA   r   r   r   rD   rD      s    ']F;
3 "7  %)#36 " " " " (  ( T D D, * *: 0 0d	 0 0$&( 7r   rD   c                   $    \ rS rSrSrS rS rSrg)r\   i  z5Processes data from extras files into service models.c                 8    U H  nU R                  X5        M     g)zProcesses 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)_process)r   original_modelextra_modelsextrass       r   r   ExtrasProcessor.process  s     #FMM.1 #r   c                 .    SU;   a  [        XS   5        gg)z3Process a single extras model into a service model.mergeNr	   )r   r   extra_models      r   r   ExtrasProcessor._process
  s    k!u'23 "r   r   N)r   r=   r>   r?   r@   r   r   rA   r   r   r   r\   r\     s    ?
24r   r\   r   )r@   loggingr%   botocorer   botocore.compatr   r   r   botocore.exceptionsr   r   botocore.utilsr
   r   r$   gzip	gzip_open	getLoggerr   r1   r   r!   rM   rD   r\   r   r   r   <module>r      s   Zx  	 " 7 7 F % T 
 &%.z" 
		8	$.0 0f,0W7 W7t4 4r   