
    IihU                       S r SSKrSSKrSSKrSSKrSSKrSSKrSSKJrJr  SSKJ	r	  SSK
Jr  SSKJr  SSKJr  SSKJrJrJrJrJrJrJrJr  \R2                  " \5      r/ S	QrS
rSrSrSr Sr!Sr"Sr#Sr$Sr%Sr&Sr'Sr(Sr)Sr*Sr+Sr,Sr-Sr.Sr/Sr0Sr1Sr2S r3S!r4S"r5S#r6\6S$-  r7\6S%-  r8\7 S&\8 S'3r9 " S( S)\:5      r; " S* S+\:5      r< " S, S-\=5      r> " S. S/\:5      r? " S0 S1\:5      r@ " S2 S3\:5      rA " S4 S5\:5      rBS6 rCS7 rDS8 rESS9 jrFS: rGS; rHS< rIS= rJS> rK " S? S@\5      rL " SA SB\L5      rM " SC SD5      rN " SE SF\N5      rO " SG SH\N5      rP " SI SJ\P5      rQ " SK SL\Q5      rR " SM SN\Q5      rS " SO SP\O5      rT " SQ SR\O5      rU " SS ST\Q5      rV " SU SV\O5      rW " SW SX\Q5      rX " SY SZ\O5      rY " S[ S\\O5      rZ " S] S^\Q5      r[ " S_ S`\O5      r\ " Sa Sb\Q5      r] " Sc Sd\Q5      r^ " Se Sf\O5      r_ " Sg Sh\O5      r` " Si Sj\O5      ra " Sk Sl\Q5      rb " Sm Sn\O5      rc " So Sp\Q5      rd " Sq Sr\O5      re " Ss St\O5      rf " Su Sv\Q5      rg " Sw Sx\O5      rh " Sy Sz\Q5      ri " S{ S|\O5      rj " S} S~\Q5      rk " S S\O5      rl " S S5      rmg)a  The **splunklib.client** module provides a Pythonic interface to the
`Splunk REST API <http://docs.splunk.com/Documentation/Splunk/latest/RESTAPI/RESTcontents>`_,
allowing you programmatically access Splunk's resources.

**splunklib.client** wraps a Pythonic layer around the wire-level
binding of the **splunklib.binding** module. The core of the library is the
:class:`Service` class, which encapsulates a connection to the server, and
provides access to the various aspects of Splunk's functionality, which are
exposed via the REST API. Typically you connect to a running Splunk instance
with the :func:`connect` function::

    import splunklib.client as client
    service = client.connect(host='localhost', port=8089,
                       username='admin', password='...')
    assert isinstance(service, client.Service)

:class:`Service` objects have fields for the various Splunk resources (such as apps,
jobs, saved searches, inputs, and indexes). All of these fields are
:class:`Collection` objects::

    appcollection = service.apps
    my_app = appcollection.create('my_app')
    my_app = appcollection['my_app']
    appcollection.delete('my_app')

The individual elements of the collection, in this case *applications*,
are subclasses of :class:`Entity`. An ``Entity`` object has fields for its
attributes, and methods that are specific to each kind of entity. For example::

    print(my_app['author'])  # Or: print(my_app.author)
    my_app.package()  # Creates a compressed package of this application
    N)datetime	timedelta)sleep)parse)data)record)AuthenticationErrorContext	HTTPError
UrlEncoded_encode_make_cookie_header_NoAuthenticationToken	namespace)connectNotSupportedErrorOperationErrorIncomparableExceptionServicer   r	   zapps/local/zauthorization/capabilities/zconfigs/conf-%s/zproperties/zdeployment/client/zdeployment/tenants/zdeployment/server/zdeployment/serverclass/zsaved/eventtypes/zalerts/fired_alerts/zdata/indexes/zdata/inputs/zsearch/jobs/zsearch/v2/jobs/z/services/server/logger/zconfigs/conf-macros/z	messages/zdata/modular-inputszauthorization/roles/zsaved/searches/zconfigs/conf-%s/%szauthentication/users/z/services/receivers/streamz/services/receivers/simplezstorage/passwordsz{http://www.w3.org/2005/Atom}%sentrycontent/z/*c                       \ rS rSrSrSrg)IllegalOperationExceptionz   zoThrown when an operation is not possible on the Splunk instance that a
:class:`Service` object is connected to. N__name__
__module____qualname____firstlineno____doc____static_attributes__r       6/venv/lib/python3.13/site-packages/splunklib/client.pyr   r   z   s    0r$   r   c                       \ rS rSrSrSrg)r      zpThrown when trying to compare objects (using ``==``, ``<``, ``>``, and
so on) of a type that doesn't support it.r   Nr   r   r$   r%   r   r      s    1r$   r   c                       \ rS rSrSrSrg)AmbiguousReferenceException   zJThrown when the name used to fetch an entity matches more than one entity.r   Nr   r   r$   r%   r)   r)      s    Tr$   r)   c                       \ rS rSrSrSrg)InvalidNameException   z_Thrown when the specified name contains characters that are not allowed
in Splunk entity names.r   Nr   r   r$   r%   r,   r,      s    r$   r,   c                       \ rS rSrSrSrg)NoSuchCapability   zCThrown when the capability that has been referred to doesn't exist.r   Nr   r   r$   r%   r/   r/      s    Mr$   r/   c                       \ rS rSrSrSrg)r      z1Raised for a failed operation, such as a timeout.r   Nr   r   r$   r%   r   r      s    ;r$   r   c                       \ rS rSrSrSrg)r      z?Raised for operations that are not supported on a given object.r   Nr   r   r$   r%   r   r      s    Ir$   r   c                     U nU H;  nUR                  U5      nUS:X  a  [        SU-   S-   5      eX$[        U5      -   S nM=     U$ )a  Substring of *template* following all *targets*.

**Example**::

    template = "this is a test of the bunnies."
    _trailing(template, "is", "est", "the") == " bunnies"

Each target is matched successively in the string, and the string
remaining after the last target is returned. If one of the targets
fails to match, a ValueError is raised.

:param template: Template to extract a trailing string from.
:type template: ``string``
:param targets: Strings to successively match in *template*.
:type targets: list of ``string``s
:return: Trailing string after all targets are matched.
:rtype: ``string``
:raises ValueError: Raised when one of the targets does not match.
zTarget z not found in template.N)find
ValueErrorlen)templatetargetsstns        r%   	_trailingr?      sT    ( 	AFF1I7Y]-FFGG#a&jkN	 
 Hr$   c                    ^  [        U5      S:  a  [        U 4S jU 5       5      $ [        S T R                  5        5       5      $ )Nr   c              3   0   >#    U  H  oTU   4v   M     g 7fNr   ).0kr   s     r%   	<genexpr>"_filter_content.<locals>.<genexpr>   s     4t!'!*ots   c              3   <   #    U  H  u  pUS ;  d  M  X4v   M     g7f))eai:acleai:attributestypeNr   rC   rD   vs      r%   rE   rF      s%      E_TQCC 1&_   
)r9   r   items)r   argss   ` r%   _filter_contentrP      sB    
4y1}4t444 EW]]_ E E Er$   c                 @    U R                  S5      (       d  U S-   n X-   $ )Nr   )endswith)basenames     r%   _pathrU      s!    ==dSjt;r$   c                     [         R                  " U R                  R                  5       R	                  SS5      U5      $ )Nutf-8xmlcharrefreplace)r   loadbodyreaddecode)responsematchs     r%   
_load_atomr_      s3    99X]]'')fW&9:EC Cr$   c                 :   [        U 5      nSU;   a[  UR                  R                  S5      S;   a  / $ UR                  R                  SS 5      nUc  g [        U[        5      (       a  U$ U/$ UR                  SS 5      nUc  g [        U[        5      (       a  U$ U/$ )NfeedtotalResults)r   0r   )r_   ra   get
isinstancelist)r]   rentriess      r%   _load_atom_entriesri      s    8A{66::n%1I&&**Wd+?4$Wd33wB'B
 eeGT"Gt $//7>gY>r$   c                     US:X  a?  [         R                  " U R                  R                  5       5      nUR	                  S5      $ [        U 5      R                  R                  $ )Njsonsid)rk   loadsrZ   r[   rd   r_   r]   rl   )r]   output_modejson_objs      r%   	_load_sidrp      sK    f::hmm0023||E""h((,,,r$   c           
         U R                  SS 5      nU R                  S/ 5      n[        U[        5      (       a  UOU/n[        S U 5       5      nU R                  S0 5      n[	        U5      n[        S UR                  5        5       5      nSU;   a  [        US   [        5      (       ab  US    Vs/ s H  ofS:w  d  M
  UPM     snUS'   [        US   5      S:X  a  UR                  SS 5        [        US   5      S	:X  a  US   S   US'   OUR                  SS 5        [        UUUR                  UR                  UU R                  S
5      S.5      $ s  snf )Ntitlelinkc              3   P   #    U  H  oR                   UR                  4v   M     g 7frB   )relhref)rC   rs   s     r%   rE   $_parse_atom_entry.<locals>.<genexpr>   s     ;UTHHdii(Us   $&r   c              3   <   #    U  H  u  pUS ;  d  M  X4v   M     g7f))rH   rI   Nr   rK   s      r%   rE   rw      s%      @!>> aVrM   rJ   ztext/xmlr      updated)rr   linksaccessfieldsr   rz   )
rd   re   rf   r   _parse_atom_metadatarN   r9   popr|   r}   )r   rr   elinkr{   r   metadatar=   s          r%   _parse_atom_entryr      sM   IIgt$EIIfb!Et,,E5'E;U;;E ii	2&G $G,H  @ @ @G gfot,,*1&/M/Q*_q/MGFO76?#q(FD)76?#q(")&/!"4KK%////99Y'   Ns   3	E Ec                     U R                  SS 5      nU R                  S0 5      n[        UR                  S/ 5      UR                  S/ 5      UR                  S/ 5      S.5      n[        XS.5      $ )NrH   rI   requiredFieldsoptionalFieldswildcardFields)requiredoptionalwildcard)r|   r}   )rd   r   )r   r|   
attributesr}   s       r%   r~   r~     sq    [[D)F -r2JNN#3R8NN#3R8NN#3R8: ;F
 V677r$   c                  <    [        S0 U D6nUR                  5         U$ )a  This function connects and logs in to a Splunk instance.

This function is a shorthand for :meth:`Service.login`.
The ``connect`` function makes one round trip to the server (for logging in).

:param host: The host name (the default is "localhost").
:type host: ``string``
:param port: The port number (the default is 8089).
:type port: ``integer``
:param scheme: The scheme for accessing the service (the default is "https").
:type scheme: "https" or "http"
:param verify: Enable (True) or disable (False) SSL verification for
               https connections. (optional, the default is True)
:type verify: ``Boolean``
:param `owner`: The owner context of the namespace (optional).
:type owner: ``string``
:param `app`: The app context of the namespace (optional).
:type app: ``string``
:param sharing: The sharing mode for the namespace (the default is "user").
:type sharing: "global", "system", "app", or "user"
:param `token`: The current session token (optional). Session tokens can be
                shared across multiple service instances.
:type token: ``string``
:param cookie: A session cookie. When provided, you don't need to call :meth:`login`.
    This parameter is only supported for Splunk 6.2+.
:type cookie: ``string``
:param autologin: When ``True``, automatically tries to log in again if the
    session terminates.
:type autologin: ``boolean``
:param `username`: The Splunk account username, which is used to
                   authenticate the Splunk instance.
:type username: ``string``
:param `password`: The password for the Splunk account.
:type password: ``string``
:param retires: Number of retries for each HTTP connection (optional, the default is 0).
                NOTE THAT THIS MAY INCREASE THE NUMBER OF ROUND TRIP CONNECTIONS TO THE SPLUNK SERVER.
:type retries: ``int``
:param retryDelay: How long to wait between connection attempts if `retries` > 0 (optional, defaults to 10s).
:type retryDelay: ``int`` (in seconds)
:param `context`: The SSLContext that can be used when setting verify=True (optional)
:type context: ``SSLContext``
:return: An initialized :class:`Service` connection.

**Example**::

    import splunklib.client as client
    s = client.connect(...)
    a = s.apps["my_app"]
    ...
r   )r   login)kwargsr<   s     r%   r   r     s     f 	&AGGIHr$   c                       \ rS rSrSrg)_BaseServicei]  r   N)r   r   r    r!   r#   r   r$   r%   r   r   ]  s    r$   r   c                     ^  \ rS rSrSrU 4S jr\S 5       r\S 5       r\S 5       r	\S 5       r
\S 5       r\S	 5       r\S
 5       rS#S jr\S 5       rS r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       rS rS#S jr\S 5       r\S 5       rS r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r \S 5       r!\!RD                  S 5       r!\S  5       r#\S! 5       r$S"r%U =r&$ )$r   ia  a  A Pythonic binding to Splunk instances.

A :class:`Service` represents a binding to a Splunk instance on an
HTTP or HTTPS port. It handles the details of authentication, wire
formats, and wraps the REST API endpoints into something more
Pythonic. All of the low-level operations on the instance from
:class:`splunklib.binding.Context` are also available in case you need
to do something beyond what is provided by this class.

After creating a ``Service`` object, you must call its :meth:`login`
method before you can issue requests to Splunk.
Alternately, use the :func:`connect` function to create an already
authenticated :class:`Service` object, or provide a session token
when creating the :class:`Service` object explicitly (the same
token may be shared by multiple :class:`Service` objects).

:param host: The host name (the default is "localhost").
:type host: ``string``
:param port: The port number (the default is 8089).
:type port: ``integer``
:param scheme: The scheme for accessing the service (the default is "https").
:type scheme: "https" or "http"
:param verify: Enable (True) or disable (False) SSL verification for
               https connections. (optional, the default is True)
:type verify: ``Boolean``
:param `owner`: The owner context of the namespace (optional; use "-" for wildcard).
:type owner: ``string``
:param `app`: The app context of the namespace (optional; use "-" for wildcard).
:type app: ``string``
:param `token`: The current session token (optional). Session tokens can be
                shared across multiple service instances.
:type token: ``string``
:param cookie: A session cookie. When provided, you don't need to call :meth:`login`.
    This parameter is only supported for Splunk 6.2+.
:type cookie: ``string``
:param `username`: The Splunk account username, which is used to
                   authenticate the Splunk instance.
:type username: ``string``
:param `password`: The password, which is used to authenticate the Splunk
                   instance.
:type password: ``string``
:param retires: Number of retries for each HTTP connection (optional, the default is 0).
                NOTE THAT THIS MAY INCREASE THE NUMBER OF ROUND TRIP CONNECTIONS TO THE SPLUNK SERVER.
:type retries: ``int``
:param retryDelay: How long to wait between connection attempts if `retries` > 0 (optional, defaults to 10s).
:type retryDelay: ``int`` (in seconds)
:return: A :class:`Service` instance.

**Example**::

    import splunklib.client as client
    s = client.Service(username="boris", password="natasha", ...)
    s.login()
    # Or equivalently
    s = client.connect(username="boris", password="natasha")
    # Or if you already have a session token
    s = client.Service(token="atg232342aa34324a")
    # Or if you already have a valid cookie
    s = client.Service(cookie="splunkd_8089=...")
c                 P   > [         TU ]  " S0 UD6  S U l        S U l        S U l        g Nr   )super__init___splunk_version_kvstore_owner_instance_type)selfr   	__class__s     r%   r   Service.__init__  s+    "6"#""r$   c                 (    [        U [        [        S9$ )zReturns the collection of applications that are installed on this instance of Splunk.

:return: A :class:`Collection` of :class:`Application` entities.
item)
Collection	PATH_APPSApplicationr   s    r%   appsService.apps  s     $	<<r$   c                     [        U 5      $ )zReturns the collection of configuration files for this Splunk instance.

:return: A :class:`Configurations` collection of
    :class:`ConfigurationFile` entities.
)Configurationsr   s    r%   confsService.confs  s     d##r$   c                 `    U R                  [        5      n[        U[        5      R                  $ )zOReturns the list of system capabilities.

:return: A ``list`` of capabilities.
)rd   PATH_CAPABILITIESr_   MATCH_ENTRY_CONTENTcapabilitiesr   r]   s     r%   r   Service.capabilities  s'     88-.($78EEEr$   c                 "    [        U [        5      $ )zReturns the collection of event types defined in this Splunk instance.

:return: An :class:`Entity` containing the event types.
)r   PATH_EVENT_TYPESr   s    r%   event_typesService.event_types  s     $ 011r$   c                 (    [        U [        [        S9$ )zReturns the collection of alerts that have been fired on the Splunk
instance, grouped by saved search.

:return: A :class:`Collection` of :class:`AlertGroup` entities.
r   )r   PATH_FIRED_ALERTS
AlertGroupr   s    r%   fired_alertsService.fired_alerts  s     $ 1
CCr$   c                 (    [        U [        [        S9$ )zReturns the collection of indexes for this Splunk instance.

:return: An :class:`Indexes` collection of :class:`Index` entities.
r   )IndexesPATH_INDEXESIndexr   s    r%   indexesService.indexes  s     t\66r$   c                 V    U R                  S5      n[        [        U[        5      5      $ )z~Returns the information about this instance of Splunk.

:return: The system information, as key-value pairs.
:rtype: ``dict``
z/services/server/info)rd   rP   r_   r   r   s     r%   infoService.info  s&     8834z(4GHIIr$   c                 2    [        XUS9R                  5       $ )zTRetrieves an input by path, and optionally kind.

:return: A :class:`Input` object.
kind)Inputrefresh)r   pathr   s      r%   inputService.input  s    
 Td+3355r$   c                     [        U 5      $ )zReturns the collection of inputs configured on this Splunk instance.

:return: An :class:`Inputs` collection of :class:`Input` entities.
)Inputsr   s    r%   inputsService.inputs  s     d|r$   c                 4    [        X5      R                  5       $ )z@Retrieves a search job by sid.

:return: A :class:`Job` object.
)Jobr   )r   rl   s     r%   jobService.job  s    
 4~%%''r$   c                     [        U 5      $ )znReturns the collection of current search jobs.

:return: A :class:`Jobs` collection of :class:`Job` entities.
)Jobsr   s    r%   jobsService.jobs  s     Dzr$   c                     [        U 5      $ )zReturns the collection of logging level categories and their status.

:return: A :class:`Loggers` collection of logging levels.
)Loggersr   s    r%   loggersService.loggers   s     t}r$   c                 (    [        U [        [        S9$ )zjReturns the collection of service messages.

:return: A :class:`Collection` of :class:`Message` entities.
r   )r   PATH_MESSAGESMessager   s    r%   messagesService.messages  s     $G<<r$   c                 ^    U R                   S:  a  [        U [        [        S9$ [	        S5      e)zReturns the collection of the modular input kinds on this Splunk instance.

:return: A :class:`ReadOnlyCollection` of :class:`ModularInputKind` entities.
   r   z9Modular inputs are not supported before Splunk version 5.)splunk_versionReadOnlyCollectionPATH_MODULAR_INPUTSModularInputKindr   r   s    r%   modular_input_kindsService.modular_input_kinds  s/     $&%d,?FVWW'(cddr$   c                     [        U 5      $ )zReturns the collection of the storage passwords on this Splunk instance.

:return: A :class:`ReadOnlyCollection` of :class:`StoragePasswords` entities.
)StoragePasswordsr   s    r%   storage_passwordsService.storage_passwords  s      %%r$   c                 t    U R                   (       d  U R                  " SSU0UD6$ U R                  " SSU0UD6$ )a  Parses a search query and returns a semantic map of the search.

:param query: The search query to parse.
:type query: ``string``
:param kwargs: Arguments to pass to the ``search/parser`` endpoint
    (optional). Valid arguments are:

    * "enable_lookups" (``boolean``): If ``True``, performs reverse lookups
      to expand the search expression.

    * "output_mode" (``string``): The output format (XML or JSON).

    * "parse_only" (``boolean``): If ``True``, disables the expansion of
      search due to evaluation of subsearches, time term expansion,
      lookups, tags, eventtypes, and sourcetype alias.

    * "reload_macros" (``boolean``): If ``True``, reloads macro
      definitions from macros.conf.

:type kwargs: ``dict``
:return: A semantic map of the parsed search query.
q)zsearch/v2/parser)zsearch/parser)disable_v2_apipostrd   r   queryr   s      r%   r   Service.parse#  s;    . ""99C5CFCCxx;5;F;;r$   c                    SSU R                   -   S-   0nU R                  R                  " SSS0UD6  U R                  S5      nUc  U$ [        R
                  " 5       n[        US9n[        R
                  " 5       U-
  U:  aC   U R                  5         U R                  (       d  U$  [        R
                  " 5       U-
  U:  a  MC  [        S
5      e! [         a  n[        S	5         SnANCSnAff = f)aP  Restarts this Splunk instance.

The service is unavailable until it has successfully restarted.

If a *timeout* value is specified, ``restart`` blocks until the service
resumes or the timeout period has been exceeded. Otherwise, ``restart`` returns
immediately.

:param timeout: A timeout period, in seconds.
:type timeout: ``integer``
valuezRestart requested by zvia the Splunk SDK for PythonrT   restart_requiredz /services/server/control/restartNsecondsry   zOperation time out.r   )usernamer   creater   r   nowr   r   r   	Exceptionr   )r   timeoutmsgresultstartdiffes          r%   restartService.restart>  s     /$--?Baab<"4<<=>?M)llnu$t+

,,!M - llnu$t+ -..  as   "C 
C0C++C0c                 $   U R                  S5      R                  R                  5       n[        R                  " U5      S   nSU;  a  SnU$ [        US   [        5      (       a
  US   S   /nOUS    Vs/ s H  oUS   PM	     nnSU;   nU$ s  snf )zIndicates whether splunkd is in a state that requires a restart.

:return: A ``boolean`` that indicates whether a restart is required.

r   ra   r   Frr   r   )rd   rZ   r[   r   rY   re   dict)r   r]   r   r   titlesxs         r%   r   Service.restart_required[  s     88J',,11399X&v.("F  (7+T22"7+G45.6w.?@.?G*.?@'61F As   6Bc                     [        U 5      $ )zgReturns the collection of user roles.

:return: A :class:`Roles` collection of :class:`Role` entities.
)Rolesr   s    r%   rolesService.rolesn       T{r$   c                 <    U R                   R                  " U40 UD6$ )a  Runs a search using a search query and any optional arguments you
provide, and returns a `Job` object representing the search.

:param query: A search query.
:type query: ``string``
:param kwargs: Arguments for the search (optional):

    * "output_mode" (``string``): Specifies the output format of the
      results.

    * "earliest_time" (``string``): Specifies the earliest time in the
      time range to
      search. The time string can be a UTC time (with fractional
      seconds), a relative time specifier (to now), or a formatted
      time string.

    * "latest_time" (``string``): Specifies the latest time in the time
      range to
      search. The time string can be a UTC time (with fractional
      seconds), a relative time specifier (to now), or a formatted
      time string.

    * "rf" (``string``): Specifies one or more fields to add to the
      search.

:type kwargs: ``dict``
:rtype: class:`Job`
:returns: An object representing the created job.
)r   r   r   s      r%   searchService.searchv  s    < yy000r$   c                     [        U 5      $ )z~Returns the collection of saved searches.

:return: A :class:`SavedSearches` collection of :class:`SavedSearch`
    entities.
)SavedSearchesr   s    r%   saved_searchesService.saved_searches  s     T""r$   c                     [        U 5      $ )ziReturns the collection of macros.

:return: A :class:`Macros` collection of :class:`Macro`
    entities.
)Macrosr   s    r%   macrosService.macros  s     d|r$   c                     [        U 5      $ )zReturns the configuration settings for this instance of Splunk.

:return: A :class:`Settings` object containing configuration settings.
)Settingsr   s    r%   settingsService.settings  s     ~r$   c                     U R                   c3  [        S U R                  S   R                  S5       5       5      U l         U R                   $ )zReturns the version of the splunkd instance this object is attached
to.

The version is returned as a tuple of the version components as
integers (for example, `(4,3,3)` or `(5,)`).

:return: A ``tuple`` of ``integers``.
c              3   8   #    U  H  n[        U5      v   M     g 7frB   )int)rC   ps     r%   rE   )Service.splunk_version.<locals>.<genexpr>  s     (Y9XAQ9Xs   version.)r   tupler   splitr   s    r%   r   Service.splunk_version  sD     '#((Y99M9S9STW9X(Y#YD ###r$   c                     U R                   c:  U R                  n[        US5      (       a  US   U l         U R                   $ SU l         U R                   $ )Ninstance_type )r   r   hasattr)r   splunk_infos     r%   splunk_instanceService.splunk_instance  sU    &))K{O44&1/&B# """ ')#"""r$   c                 z    U R                   R                  5       S:X  a  U R                  S:  $ U R                  S:  $ )Ncloud)	   r   i  )r.  r      )r*  lowerr   r   s    r%   r   Service.disable_v2_api  s;    %%'72&&33""W,,r$   c                 B    U R                   c  SU l         U R                   $ )zReturns the KVStore owner for this instance of Splunk.

By default is the kvstore owner is not set, it will return "nobody"
:return: A string with the KVStore owner.
nobody)r   r   s    r%   kvstore_ownerService.kvstore_owner  s$     &"*D"""r$   c                 (    Xl         U R                    g)z7
kvstore is refreshed, when the owner value is changed
N)r   kvstorer   r   s     r%   r4  r5    s    
 $r$   c                 J    U R                   U R                  S'   [        U 5      $ )zReturns the collection of KV Store collections.

sets the owner for the namespace, before retrieving the KVStore Collection

:return: A :class:`KVStoreCollections` collection of :class:`KVStoreCollection` entities.
owner)r4  r   KVStoreCollectionsr   s    r%   r7  Service.kvstore  s#     #'"4"4w!$''r$   c                     [        U 5      $ )zbReturns the collection of users.

:return: A :class:`Users` collection of :class:`User` entities.
)Usersr   s    r%   usersService.users  r  r$   )r   r   r   rB   )'r   r   r    r!   r"   r   propertyr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r	  r  r  r  r  r   r*  r   r4  setterr7  r?  r#   __classcell__r   s   @r%   r   r   a  s*   ;z# = = $ $ F F 2 2 D D 7 7 J J6  (     = = e e & &<6/:  $  1@ # #     $ $ # # - -
 # #   ( (  r$   r   c                   8    \ rS rSrSrS rS rS	S jrS	S jrSr	g)
Endpointi  a  This class represents individual Splunk resources in the Splunk REST API.

An ``Endpoint`` object represents a URI, such as ``/services/saved/searches``.
This class provides the common functionality of :class:`Collection` and
:class:`Entity` (essentially HTTP GET and POST methods).
c                     Xl         X l        g rB   )servicer   r   rH  r   s      r%   r   Endpoint.__init__  s    	r$   c                 z    Sn[         R                  " SU5      nU(       a  [        UR                  S5      5      nU$ )zReturn the API version of the service used in the provided path.

Args:
    path (str): A fully-qualified endpoint path (for example, "/services/search/jobs").

Returns:
    int: Version of the API (for example, 1)
ry   z6(?:servicesNS\/[^/]+\/[^/]+|services)\/[^/]+\/v(\d+)\/)rer  r  group)r   r   api_versionversionSearchs       r%   get_api_versionEndpoint.get_api_version  s9     		"Z\`am11!45Kr$   Nc                 
   UR                  S5      (       a  UnObU R                  R                  S5      (       d  US:w  a  U R                  S-   U l        U R                  R	                  U R                  U-   UX4S9nU R                  U5      nUS:X  aR  [        U[        5      (       a#  [        UR                  [        [        5      SS9nOUR                  [        [        5      nU R                  R                  " U4X#US.UD6$ )a  Performs a GET operation on the path segment relative to this endpoint.

This method is named to match the HTTP method. This method makes at least
one roundtrip to the server, one additional round trip for
each 303 status returned, plus at most two additional round
trips if
the ``autologin`` field of :func:`connect` is set to ``True``.

If *owner*, *app*, and *sharing* are omitted, this method takes a
default namespace from the :class:`Service` object for this :class:`Endpoint`.
All other keyword arguments are included in the URL as query parameters.

:raises AuthenticationError: Raised when the ``Service`` is not logged in.
:raises HTTPError: Raised when an error in the request occurs.
:param path_segment: A path segment relative to this endpoint.
:type path_segment: ``string``
:param owner: The owner context of the namespace (optional).
:type owner: ``string``
:param app: The app context of the namespace (optional).
:type app: ``string``
:param sharing: The sharing mode for the namespace (optional).
:type sharing: "global", "system", "app", or "user"
:param query: All other keyword arguments, which are used as query
    parameters.
:type query: ``string``
:return: The response from the server.
:rtype: ``dict`` with keys ``body``, ``headers``, ``reason``,
        and ``status``

**Example**::

    import splunklib.client
    s = client.service(...)
    apps = s.apps
    apps.get() == \
        {'body': ...a response reader object...,
         'headers': [('content-length', '26208'),
                     ('expires', 'Fri, 30 Oct 1998 00:00:00 GMT'),
                     ('server', 'Splunkd'),
                     ('connection', 'close'),
                     ('cache-control', 'no-store, max-age=0, must-revalidate, no-cache'),
                     ('date', 'Fri, 11 May 2012 16:30:35 GMT'),
                     ('content-type', 'text/xml; charset=utf-8')],
         'reason': 'OK',
         'status': 200}
    apps.get('nonexistant/path') # raises HTTPError
    s.logout()
    apps.get() # raises AuthenticationError
r   r'  r:  appsharingry   Tskip_encode)
startswithr   rR   rH  _abspathrP  re   r   replacePATH_JOBS_V2	PATH_JOBSrd   r   path_segmentr:  rT  rU  r   r   rN  s           r%   rd   Endpoint.get  s    j ""3''D99%%c**|r/A IIO	<<((\)A-0 ) CD **40 !$
++!$,,|Y"GUYZ||L)<|| )&+g)"') 	)r$   c                 
   UR                  S5      (       a  UnObU R                  R                  S5      (       d  US:w  a  U R                  S-   U l        U R                  R	                  U R                  U-   X#US9nU R                  U5      nUS:X  aR  [        U[        5      (       a#  [        UR                  [        [        5      SS9nOUR                  [        [        5      nU R                  R                  " U4X#US.UD6$ )a  Performs a POST operation on the path segment relative to this endpoint.

This method is named to match the HTTP method. This method makes at least
one roundtrip to the server, one additional round trip for
each 303 status returned, plus at most two additional round trips if
the ``autologin`` field of :func:`connect` is set to ``True``.

If *owner*, *app*, and *sharing* are omitted, this method takes a
default namespace from the :class:`Service` object for this :class:`Endpoint`.
All other keyword arguments are included in the URL as query parameters.

:raises AuthenticationError: Raised when the ``Service`` is not logged in.
:raises HTTPError: Raised when an error in the request occurs.
:param path_segment: A path segment relative to this endpoint.
:type path_segment: ``string``
:param owner: The owner context of the namespace (optional).
:type owner: ``string``
:param app: The app context of the namespace (optional).
:type app: ``string``
:param sharing: The sharing mode of the namespace (optional).
:type sharing: ``string``
:param query: All other keyword arguments, which are used as query
    parameters.
:type query: ``string``
:return: The response from the server.
:rtype: ``dict`` with keys ``body``, ``headers``, ``reason``,
        and ``status``

**Example**::

    import splunklib.client
    s = client.service(...)
    apps = s.apps
    apps.post(name='boris') == \
        {'body': ...a response reader object...,
         'headers': [('content-length', '2908'),
                     ('expires', 'Fri, 30 Oct 1998 00:00:00 GMT'),
                     ('server', 'Splunkd'),
                     ('connection', 'close'),
                     ('cache-control', 'no-store, max-age=0, must-revalidate, no-cache'),
                     ('date', 'Fri, 11 May 2012 18:34:50 GMT'),
                     ('content-type', 'text/xml; charset=utf-8')],
         'reason': 'Created',
         'status': 201}
    apps.get('nonexistant/path') # raises HTTPError
    s.logout()
    apps.get() # raises AuthenticationError
r   r'  rS  ry   TrV  )rX  r   rR   rH  rY  rP  re   r   rZ  r[  r\  r   r]  s           r%   r   Endpoint.postf  s    b ""3''D99%%c**|r/A IIO	<<((\)Aah(iD **40 !$
++!$,,|Y"GUYZ||L)<||  VUWVPUVVr$   )r   rH  r'  NNN)
r   r   r    r!   r"   r   rP  rd   r   r#   r   r$   r%   rF  rF    s    &P)dGWr$   rF  c                     ^  \ rS rSrSr0 rS rS rS rS r	S r
S rS	 rS
 rSS jrS rSU 4S jjrSU 4S jjrSS jr\S 5       r\S 5       rS rS r\S 5       r\S 5       r\S 5       rS rS rS r\S 5       rS rSr U =r!$ ) Entityi  a  This class is a base class for Splunk entities in the REST API, such as
saved searches, jobs, indexes, and inputs.

``Entity`` provides the majority of functionality required by entities.
Subclasses only implement the special cases for individual entities.
For example for saved searches, the subclass makes fields like ``action.email``,
``alert_type``, and ``search`` available.

An ``Entity`` is addressed like a dictionary, with a few extensions,
so the following all work, for example in saved searches::

    ent['action.email']
    ent['alert_type']
    ent['search']

You can also access the fields as though they were the fields of a Python
object, as in::

    ent.alert_type
    ent.search

However, because some of the field names are not valid Python identifiers,
the dictionary-like syntax is preferable.

The state of an :class:`Entity` object is cached, so accessing a field
does not contact the server. If you think the values on the
server have changed, call the :meth:`Entity.refresh` method.
c                     [         R                  XU5        S U l        UR                  SS5      (       d"  U R	                  UR                  SS 5      5        g g )Nskip_refreshFstate)rF  r   _staterd   r   r   rH  r   r   s       r%   r   Entity.__init__  sF    $.zz.%00LLGT23 1r$   c                 :     X     g! [         [        4 a     gf = f)NTF)KeyErrorAttributeError)r   r   s     r%   __contains__Entity.__contains__  s&    	J.) 		s    c                 F    [        SU R                  R                   35      e)aO  Raises IncomparableException.

Since Entity objects are snapshots of times on the server, no
simple definition of equality will suffice beyond instance
equality, and instance equality leads to strange situations
such as::

    import splunklib.client as client
    c = client.connect(...)
    saved_searches = c.saved_searches
    x = saved_searches['asearch']

but then ``x != saved_searches['asearch']``.

whether or not there was a change on the server. Rather than
try to do something fancy, we simply declare that equality is
undefined for Entities.

Makes no roundtrips to the server.
z+Equality is undefined for objects of class )r   r   r   )r   others     r%   __eq__Entity.__eq__  s%    * $&QRVR`R`RiRiQj$kllr$   c                     XR                   R                  ;   a  U R                   R                  U   $ XR                  ;   a  U R                  U   $ [        U5      erB   )rg  r   defaultsrm  r   keys     r%   __getattr__Entity.__getattr__  sM     **$$$::%%c**--==%%S!!r$   c                     [        X5      $ rB   )getattrrv  s     r%   __getitem__Entity.__getitem__  s     t!!r$   c                 (   [        U[        5      n[        U[        5      (       a]  U Vs/ s H'  o3R                  R
                  R                  S5      PM)     nn[        SUS   R                  R                   SU S35      eUR                  $ s  snf )Nzeai:appNamez6Fetch from server returned multiple entries for name 'r   z
' in apps r!  )	r_   XNAME_ENTRYre   rf   r   r   rd   r)   rr   )r   r]   elemeler   s        r%   _load_atom_entryEntity._load_atom_entry"  s    (K0dD!!DHIDSII%%))-8DDI-HaI\I\H]]ghlgmmnoq qzz	 Js   .Bc                 :    U R                  U5      n[        U5      $ rB   )r  r   )r   r]   r   s      r%   _load_stateEntity._load_state,  s    %%h/ ''r$   c                 x    U R                   " U40 UD6nU R                  U5      n[        U5      nUR                  $ )aU  Run a method and return the content Record from the returned XML.

A method is a relative path from an Entity that is not itself
an Entity. _run_action assumes that the returned XML is an
Atom field containing one Entry, and the contents of Entry is
what should be the return value. This is right in enough cases
to make this method useful.
)rd   r  r   r   )r   r^  r   r]   r   recs         r%   _run_actionEntity._run_action0  s;     88L3F3$$X.%{{r$   c                    Uc  Uc  Uc  U R                   bo  SU R                   ;   a_  U R                   R                  R                  U R                   R                  R                  U R                   R                  R                  4$ U R
                  R                  S   U R
                  R                  S   U R
                  R                  S   4$ XU4$ )a  Produce a namespace sans wildcards for use in entity requests.

This method tries to fill in the fields of the namespace which are `None`
or wildcard (`'-'`) from the entity's namespace. If that fails, it uses
the service's namespace.

:param owner:
:param app:
:param sharing:
:return:
r|   r:  rT  rU  )rh  r|   r:  rT  rU  rH  r   r   r:  rT  rU  s       r%   _proper_namespaceEntity._proper_namespace>  s     =S[W_{{&8t{{+B**00**..**224 4 LL**73..u5..y9; ; 7""r$   c                 r    U R                  5       u  pnU R                  R                  U R                  XUS9$ NrS  )r  rH  deleter   r  s       r%   r  Entity.deleteT  s5    "446G||""499EG"TTr$   c                 V   > U R                  X#U5      u  p#n[        TU ]  " U4X#US.UD6$ r  )r  r   rd   r   r^  r:  rT  rU  r   r   s         r%   rd   
Entity.getX  s6    "44UIGw{<XuwXRWXXr$   c                 V   > U R                  X#U5      u  p#n[        TU ]  " U4X#US.UD6$ r  )r  r   r   r  s         r%   r   Entity.post\  s6    "44UIGw|LYYSXYYr$   c                 d    Ub  Xl         U $ U R                  U R                  5       5      U l         U $ )ap  Refreshes the state of this entity.

If *state* is provided, load it as the new state for this
entity. Otherwise, make a roundtrip to the server (by calling
the :meth:`read` method of ``self``) to fetch an updated state,
plus at most two additional round trips if
the ``autologin`` field of :func:`connect` is set to ``True``.

:param state: Entity-specific arguments (optional).
:type state: ``dict``
:raises EntityDeletedException: Raised if the entity no longer exists on
    the server.

**Example**::

    import splunklib.client as client
    s = client.connect(...)
    search = s.apps['search']
    search.refresh()
)rh  r[   rd   r   rg  s     r%   r   Entity.refresh`  s3    * K  ))DHHJ/DKr$   c                 .    U R                   R                  $ )zReturns the access metadata for this entity.

:return: A :class:`splunklib.data.Record` object with three keys:
    ``owner``, ``app``, and ``sharing``.
)rg  r|   r   s    r%   r|   Entity.access{       zz   r$   c                 .    U R                   R                  $ )zLReturns the contents of the entity.

:return: A ``dict`` containing values.
rg  r   r   s    r%   r   Entity.content  s     zz!!!r$   c                 (    U R                  S5        U $ )z%Disables the entity at this endpoint.disabler   r   s    r%   r  Entity.disable      		)r$   c                 (    U R                  S5        U $ )z$Enables the entity at this endpoint.enabler  r   s    r%   r  Entity.enable  s    		(r$   c                 .    U R                   R                  $ )zReturns the content metadata for this entity.

:return: A :class:`splunklib.data.Record` object with three keys:
    ``required``, ``optional``, and ``wildcard``.
)rg  r}   r   s    r%   r}   Entity.fields  r  r$   c                 .    U R                   R                  $ )zbReturns a dictionary of related resources.

:return: A ``dict`` with keys and corresponding URLs.
)rg  r{   r   s    r%   r{   Entity.links  s     zzr$   c                 .    U R                   R                  $ )zGReturns the entity name.

:return: The entity name.
:rtype: ``string``
)rg  rr   r   s    r%   rT   Entity.name  s     zzr$   c                 v    U R                  U5      n[        S US   R                  5        5       5      nX2S'   U$ )z7Reads the current state of the entity from the server. c              3   >   #    U  H  u  pU[        US S94v   M     g7f)TrV  Nr   rK   s      r%   rE   Entity.read.<locals>.<genexpr>  s&      E+C41  !*QD"AB+Cs   r{   )r  r  rN   )r   r]   resultsunquoted_linkss       r%   r[   Entity.read  sI    ""8,  E+27+;+A+A+CE E)r$   c                 (    U R                  S5        U $ )zReloads the entity._reloadr  r   s    r%   reloadEntity.reload  r  r$   c                     SU;  a  SU0nSUS   ;  a  [        S5      eSUS   ;  a  [        S5      eU R                  " S0 UD6  U R                  5         U $ )a  To update Access Control List (ACL) properties for an endpoint.

:param kwargs: Additional entity-specific arguments (required).

    - "owner" (``string``): The Splunk username, such as "admin". A value of "nobody" means no specific user (required).

    - "sharing" (``string``): A mode that indicates how the resource is shared. The sharing mode can be "user", "app", "global", or "system" (required).

:type kwargs: ``dict``

**Example**::

    import splunklib.client as client
    service = client.connect(...)
    saved_search = service.saved_searches["name"]
    saved_search.acl_update(sharing="app", owner="nobody", app="search", **{"perms.read": "admin, nobody"})
rZ   rU  z'Required argument 'sharing' is missing.r:  z%Required argument 'owner' is missing.)acl)r8   r   r   r   r   s     r%   
acl_updateEntity.acl_update  sc    $ f%FF6N*FGG&.(DEE		"6"r$   c                 T    U R                   c  U R                  5         U R                   $ )zgReturns the entity's state record.

:return: A ``dict`` containing fields and metadata for the entity.
)rh  r   r   s    r%   rg  Entity.state  s      ;;{{r$   c                 L    SU;   a  [        S5      eU R                  " S0 UD6  U $ )a  Updates the server with any changes you've made to the current entity
along with any additional arguments you specify.

    **Note**: You cannot update the ``name`` field of an entity.

Many of the fields in the REST API are not valid Python
identifiers, which means you cannot pass them as keyword
arguments. That is, Python will fail to parse the following::

    # This fails
    x.update(check-new=False, email.to='boris@utopia.net')

However, you can always explicitly use a dictionary to pass
such keys::

    # This works
    x.update(**{'check-new': False, 'email.to': 'boris@utopia.net'})

:param kwargs: Additional entity-specific arguments (optional).
:type kwargs: ``dict``

:return: The entity this method is called on.
:rtype: class:`Entity`
rT   z5Cannot update the name of an Entity via the REST API.r   )r   r   r  s     r%   updateEntity.update  s,    < V+,cdd		Fr$   rh  NNNrb  rB   )"r   r   r    r!   r"   ru  r   rn  rr  rx  r|  r  r  r  r  r  rd   r   r   rA  r|   r   r  r  r}   r{   rT   r[   r  r  rg  r  r#   rC  rD  s   @r%   rd  rd    s    r H4m.""(#,UYZ6 ! ! " "

 ! !        	
<  ! !r$   rd  c                   b    \ rS rSrSr\4S jrS rS rS r	S r
S rS	 rS
 rSS jrSS jrSrg)r   i  zQThis class represents a read-only collection of entities in the Splunk
instance.
c                 J    [         R                  XU5        X0l        SU l        g )Nr6   )rF  r   r   
null_count)r   rH  r   r   s       r%   r   ReadOnlyCollection.__init__  s    $.	r$   c                 D     X     g! [          a     g[         a     gf = f)zIs there at least one entry called *name* in this collection?

Makes a single roundtrip to the server, plus at most two more
if
the ``autologin`` field of :func:`connect` is set to ``True``.
TF)rl  r)   r   rT   s     r%   rn  ReadOnlyCollection.__contains__  s,    	J 	* 		s    
	c                     [        U[        5      (       aB  [        U5      S:X  a3  Uu  p[        USS9nU R	                  XR
                  UR                  S9nO[        USS9nU R	                  U5      nU R                  U5      n[        U5      S:  a  [        SU S35      e[        U5      S:X  a  [        U5      eUS   $ ! [         a!  nUR                  S	:X  a  [        U5      ee S
nAff = f)a
  Fetch an item named *key* from this collection.

A name is not a unique identifier in a collection. The unique
identifier is a name plus a namespace. For example, there can
be a saved search named ``'mysearch'`` with sharing ``'app'``
in application ``'search'``, and another with sharing
``'user'`` with owner ``'boris'`` and application
``'search'``. If the ``Collection`` is attached to a
``Service`` that has ``'-'`` (wildcard) as user and app in its
namespace, then both of these may be visible under the same
name.

Where there is no conflict, ``__getitem__`` will fetch the
entity given just the name. If there is a conflict, and you
pass just a name, it will raise a ``ValueError``. In that
case, add the namespace as a second argument.

This function makes a single roundtrip to the server, plus at
most two additional round trips if
the ``autologin`` field of :func:`connect` is set to ``True``.

:param key: The name to fetch, or a tuple (name, namespace).
:return: An :class:`Entity` object.
:raises KeyError: Raised if *key* does not exist.
:raises ValueError: Raised if no namespace is specified and *key*
                    does not refer to a unique name.

**Example**::

    s = client.connect(...)
    saved_searches = s.saved_searches
    x1 = saved_searches.create(
        'mysearch', 'search * | head 1',
        owner='admin', app='search', sharing='app')
    x2 = saved_searches.create(
        'mysearch', 'search * | head 1',
        owner='admin', app='search', sharing='user')
    # Raises ValueError:
    saved_searches['mysearch']
    # Fetches x1
    saved_searches[
        'mysearch',
        client.namespace(sharing='app', app='search')]
    # Fetches x2
    saved_searches[
        'mysearch',
        client.namespace(sharing='user', owner='boris', app='search')]
r/  Tencode_slash)r:  rT  ry   zFound multiple entities named 'z'; please specify a namespace.r     N)re   r"  r9   r   rd   r:  rT  
_load_listr)   rl  r   status)r   rw  nsr]   rh   hes         r%   r|  ReadOnlyCollection.__getitem__$  s    b	#u%%#c(a-  4888CxxRVV8D 4888C=ooh/G7|a15cU:XY[ [7|q sm#1: 	yyCsm#		s   B?C 
C-C((C-c              +   F   #    U R                   " S0 UD6 H  nUv   M	     g7f)a,  Iterate over the entities in the collection.

:param kwargs: Additional arguments.
:type kwargs: ``dict``
:rtype: iterator over entities.

Implemented to give Collection a listish interface. This
function always makes a roundtrip to the server, plus at most
two additional round trips if
the ``autologin`` field of :func:`connect` is set to ``True``.

**Example**::

    import splunklib.client as client
    c = client.connect(...)
    saved_searches = c.saved_searches
    for entity in saved_searches:
        print(f"Saved search named {entity.name}")
Nr   iterr   r   r   s      r%   __iter__ReadOnlyCollection.__iter__l  "     * II''DJ (   !c                 4    [        U R                  5       5      $ )a  Enable ``len(...)`` for ``Collection`` objects.

Implemented for consistency with a listish interface. No
further failure modes beyond those possible for any method on
an Endpoint.

This function always makes a round trip to the server, plus at
most two additional round trips if
the ``autologin`` field of :func:`connect` is set to ``True``.

**Example**::

    import splunklib.client as client
    c = client.connect(...)
    saved_searches = c.saved_searches
    n = len(saved_searches)
)r9   rf   r   s    r%   __len__ReadOnlyCollection.__len__  s    $ 499;r$   c                     [         R                  " UR                  R                  5      nSU;   a  [	        USSS5      $ SU;   a  [	        US5      $ U$ )a_  Calculate the path to an entity to be returned.

*state* should be the dictionary returned by
:func:`_parse_atom_entry`. :func:`_entity_path` extracts the
link to this entity from *state*, and strips all the namespace
prefixes from it to leave only the relative path of the entity
itself, sans namespace.

:rtype: ``string``
:return: an absolute path
zservicesNS/r   z	services/)r   unquoter{   	alternater?   )r   rg  raw_paths      r%   _entity_pathReadOnlyCollection._entity_path  sO     ==!6!67H$X}c3??("X{33r$   c                     [        U5      nUc  / $ / nU HI  n[        U5      nU R                  U R                  U R	                  U5      US9nUR                  U5        MK     U$ )a)  Converts *response* to a list of entities.

*response* is assumed to be a :class:`Record` containing an
HTTP response, of the form::

    {'status': 200,
     'headers': [('content-length', '232642'),
                 ('expires', 'Fri, 30 Oct 1998 00:00:00 GMT'),
                 ('server', 'Splunkd'),
                 ('connection', 'close'),
                 ('cache-control', 'no-store, max-age=0, must-revalidate, no-cache'),
                 ('date', 'Tue, 29 May 2012 15:27:08 GMT'),
                 ('content-type', 'text/xml; charset=utf-8')],
     'reason': 'OK',
     'body': ...a stream implementing .read()...}

The ``'body'`` key refers to a stream containing an Atom feed,
that is, an XML document with a toplevel element ``<feed>``,
and within that element one or more ``<entry>`` elements.
rg  )ri   r   r   rH  r  appendr   r]   rh   entitiesr   rg  entitys          r%   r  ReadOnlyCollection._load_list  sp    0 %X.?2IE%e,EYY!!%(  F OOF#  r$   c                 Z    U R                  S5      n[        U[        5      n[        U5      $ )aO  Returns metadata for members of the collection.

Makes a single roundtrip to the server, plus two more at most if
the ``autologin`` field of :func:`connect` is set to ``True``.

:return: A :class:`splunklib.data.Record` object containing the metadata.

**Example**::

    import splunklib.client as client
    import pprint
    s = client.connect(...)
    pprint.pprint(s.apps.itemmeta())
    {'access': {'app': 'search',
                            'can_change_perms': '1',
                            'can_list': '1',
                            'can_share_app': '1',
                            'can_share_global': '1',
                            'can_share_user': '1',
                            'can_write': '1',
                            'modifiable': '1',
                            'owner': 'admin',
                            'perms': {'read': ['*'], 'write': ['admin']},
                            'removable': '0',
                            'sharing': 'user'},
     'fields': {'optional': ['author',
                                'configured',
                                'description',
                                'label',
                                'manageable',
                                'template',
                                'visible'],
                                'required': ['name'], 'wildcard': []}}
_new)rd   r_   r   r~   )r   r]   r   s      r%   itemmetaReadOnlyCollection.itemmeta  s+    F 88F#X':;#G,,r$   Nc              +   ~  #    Ub  US:  d   eUc  U R                   nSnX R                   :X  d  XR:  a  U R                  " SU=(       d    UUS.UD6nU R                  U5      n[        U5      nXX-  nU H  n	U	v   M	     Ub  X:  a  gX-  n[        R                  SX5XU5        X R                   :X  a  M  XR:  a  M  gg7f)a]  Iterates over the collection.

This method is equivalent to the :meth:`list` method, but
it returns an iterator and can load a certain number of entities at a
time from the server.

:param offset: The index of the first entity to return (optional).
:type offset: ``integer``
:param count: The maximum number of entities to return (optional).
:type count: ``integer``
:param pagesize: The number of entities to load (optional).
:type pagesize: ``integer``
:param kwargs: Additional arguments (optional):

    - "search" (``string``): The search query to filter responses.

    - "sort_dir" (``string``): The direction to sort returned items:
      "asc" or "desc".

    - "sort_key" (``string``): The field to use for sorting (optional).

    - "sort_mode" (``string``): The collating sequence for sorting
      returned items: "auto", "alpha", "alpha_case", or "num".

:type kwargs: ``dict``

**Example**::

    import splunklib.client as client
    s = client.connect(...)
    for saved_search in s.saved_searches.iter(pagesize=10):
        # Loads 10 saved searches at a time from the
        # server.
        ...
Nr   )countoffsetz3pagesize=%d, fetched=%d, offset=%d, N=%d, kwargs=%sr   )r  rd   r  r9   loggerdebug)
r   r  r  pagesizer   fetchedr]   rN   Nr   s
             r%   r  ReadOnlyCollection.iter  s     H 8a<//=OOE&'/xxQh&7%Q&QHOOH-EE
ALG
 1<KFLLNPXcintu &'/s   B0B=4B=;B=c                 <    [        U R                  " SSU0UD65      $ )a  Retrieves a list of entities in this collection.

The entire collection is loaded at once and is returned as a list. This
function makes a single roundtrip to the server, plus at most two more if
the ``autologin`` field of :func:`connect` is set to ``True``.
There is no caching--every call makes at least one round trip.

:param count: The maximum number of entities to return (optional).
:type count: ``integer``
:param kwargs: Additional arguments (optional):

    - "offset" (``integer``): The offset of the first item to return.

    - "search" (``string``): The search query to filter responses.

    - "sort_dir" (``string``): The direction to sort returned items:
      "asc" or "desc".

    - "sort_key" (``string``): The field to use for sorting (optional).

    - "sort_mode" (``string``): The collating sequence for sorting
      returned items: "auto", "alpha", "alpha_case", or "num".

:type kwargs: ``dict``
:return: A ``list`` of entities.
r  r   )rf   r  )r   r  r   s      r%   rf   ReadOnlyCollection.list/  s     : DII4E4V455r$   )r   r  )r   NNrB   )r   r   r    r!   r"   rd  r   rn  r|  r  r  r  r  r  r  rf   r#   r   r$   r%   r   r     sD     ,2 
FP0 (,#J%-N2vj6r$   r   c                   <   ^  \ rS rSrSrS rS rSU 4S jjrSrU =r	$ )r   iO  a  A collection of entities.

Splunk provides a number of different collections of distinct
entity types: applications, saved searches, fired alerts, and a
number of others. Each particular type is available separately
from the Splunk instance, and the entities of that type are
returned in a :class:`Collection`.

The interface for :class:`Collection` does not quite match either
``list`` or ``dict`` in Python, because there are enough semantic
mismatches with either to make its behavior surprising. A unique
element in a :class:`Collection` is defined by a string giving its
name plus namespace (although the namespace is optional if the name is
unique).

**Example**::

    import splunklib.client as client
    service = client.connect(...)
    mycollection = service.saved_searches
    mysearch = mycollection['my_search', client.namespace(owner='boris', app='natasha', sharing='user')]
    # Or if there is only one search visible named 'my_search'
    mysearch = mycollection['my_search']

Similarly, ``name`` in ``mycollection`` works as you might expect (though
you cannot currently pass a namespace to the ``in`` operator), as does
``len(mycollection)``.

However, as an aggregate, :class:`Collection` behaves more like a
list. If you iterate over a :class:`Collection`, you get an
iterator over the entities, not the names and namespaces.

**Example**::

    for entity in mycollection:
        assert isinstance(entity, client.Entity)

Use the :meth:`create` and :meth:`delete` methods to create and delete
entities in this collection. To view the access control list and other
metadata of the collection, use the :meth:`ReadOnlyCollection.itemmeta` method.

:class:`Collection` does no caching. Each call makes at least one
round trip to the server to fetch data.
c                    [        U[        5      (       d  [        U S35      eSU;   a>  UR                  S5      nUR                  US'   UR
                  US'   UR                  US'   U R                  " SSU0UD6n[        U[        5      nUc  X   $ UR                  n[        U5      nU R                  U R                  U R                  U5      US9nU$ )	a  Creates a new entity in this collection.

This function makes either one or two roundtrips to the
server, depending on the type of entities in this
collection, plus at most two more if
the ``autologin`` field of :func:`connect` is set to ``True``.

:param name: The name of the entity to create.
:type name: ``string``
:param namespace: A namespace, as created by the :func:`splunklib.binding.namespace`
    function (optional).  You can also set ``owner``, ``app``, and
    ``sharing`` in ``params``.
:type namespace: A :class:`splunklib.data.Record` object with keys ``owner``, ``app``,
    and ``sharing``.
:param params: Additional entity-specific arguments (optional).
:type params: ``dict``
:return: The new entity.
:rtype: A subclass of :class:`Entity`, chosen by :meth:`Collection.self.item`.

**Example**::

    import splunklib.client as client
    s = client.connect(...)
    applications = s.apps
    new_app = applications.create("my_fake_app")
z# is not a valid name for an entity.r   r:  rT  rU  rT   r  r   )re   strr,   r   r:  rT  rU  r   r_   r  r   r   r   rH  r  )	r   rT   paramsr   r]   atomr   rg  r  s	            r%   r   Collection.create}  s    6 $$$&$/R'STT& 

;/I'ooF7O%MMF5M ) 1 1F9991$1&1(K0< :

!%(LLe$   r$   c                 h   [        USS9nSU;   a>  UR                  S5      nUR                  US'   UR                  US'   UR                  US'    U R
                  R                  " [        U R                  U5      40 UD6  U $ ! [         a$  nUR                  S:X  a  [        SU 35      ee S	nAff = f)
a  Deletes a specified entity from the collection.

:param name: The name of the entity to delete.
:type name: ``string``
:return: The collection.
:rtype: ``self``

This method is implemented for consistency with the REST API's DELETE
method.

If there is no *name* entity on the server, a ``KeyError`` is
thrown. This function always makes a roundtrip to the server.

**Example**::

    import splunklib.client as client
    c = client.connect(...)
    saved_searches = c.saved_searches
    saved_searches.create('my_saved_search',
                          'search * | head 1')
    assert 'my_saved_search' in saved_searches
    saved_searches.delete('my_saved_search')
    assert 'my_saved_search' not in saved_searches
Tr  r   r:  rT  rU  r  zNo such entity N)r   r   r:  rT  rU  rH  r  rU   r   r   r  rl  )r   rT   r   r   r  s        r%   r  Collection.delete  s    2 $T2& 

;/I'ooF7O%MMF5M ) 1 1F9		LLdii 6A&A   	 yyC788	s   1B 
B1B,,B1c                 <   > [        USS9n[        TU ]  " XX440 UD6$ )a+  Performs a GET request to the server on the collection.

If *owner*, *app*, and *sharing* are omitted, this method takes a
default namespace from the :class:`Service` object for this :class:`Endpoint`.
All other keyword arguments are included in the URL as query parameters.

:raises AuthenticationError: Raised when the ``Service`` is not logged in.
:raises HTTPError: Raised when an error in the request occurs.
:param path_segment: A path segment relative to this endpoint.
:type path_segment: ``string``
:param owner: The owner context of the namespace (optional).
:type owner: ``string``
:param app: The app context of the namespace (optional).
:type app: ``string``
:param sharing: The sharing mode for the namespace (optional).
:type sharing: "global", "system", "app", or "user"
:param query: All other keyword arguments, which are used as query
    parameters.
:type query: ``string``
:return: The response from the server.
:rtype: ``dict`` with keys ``body``, ``headers``, ``reason``,
        and ``status``

**Example**::

    import splunklib.client
    s = client.service(...)
    saved_searches = s.saved_searches
    saved_searches.get("my/saved/search") == \
        {'body': ...a response reader object...,
         'headers': [('content-length', '26208'),
                     ('expires', 'Fri, 30 Oct 1998 00:00:00 GMT'),
                     ('server', 'Splunkd'),
                     ('connection', 'close'),
                     ('cache-control', 'no-store, max-age=0, must-revalidate, no-cache'),
                     ('date', 'Fri, 11 May 2012 16:30:35 GMT'),
                     ('content-type', 'text/xml; charset=utf-8')],
         'reason': 'OK',
         'status': 200}
    saved_searches.get('nonexistant/search') # raises HTTPError
    s.logout()
    saved_searches.get() # raises AuthenticationError

Tr  )r   r   rd   )r   rT   r:  rT  rU  r   r   s         r%   rd   Collection.get  s(    Z $T2w{4>>>r$   r   rb  )
r   r   r    r!   r"   r   r  rd   r#   rC  rD  s   @r%   r   r   O  s    +Z.`)V.? .?r$   r   c                       \ rS rSrSrS rSrg)ConfigurationFilei	  zHThis class contains all of the stanzas from one configuration file.
    c                 P    [         R                  XU[        S9  US   S   U l        g )Nr   rg  rr   )r   r   StanzarT   ri  s       r%   r   ConfigurationFile.__init__  s'    D4f=7OG,	r$   rT   N)r   r   r    r!   r"   r   r#   r   r$   r%   r  r  	  s    -r$   r  c                   <    \ rS rSrSrS rS rS rS rS r	S r
S	rg
)r   i  aH  This class provides access to the configuration files from this Splunk
instance. Retrieve this collection using :meth:`Service.confs`.

Splunk's configuration is divided into files, and each file into
stanzas. This collection is unusual in that the values in it are
themselves collections of :class:`ConfigurationFile` objects.
c                     [         R                  X[        [        S9  U R                  R
                  R                  S:X  d$  U R                  R
                  R                  S:X  a  [        S5      eg )Nr   -z2Configurations cannot have wildcards in namespace.)	r   r   PATH_PROPERTIESr  rH  r   r:  rT  r8   r   rH  s     r%   r   Configurations.__init__  sZ    D?ARS<<!!''3.$,,2H2H2L2LPS2SQRR 3Tr$   c                      U R                  U5        [        U R                  [        U-  SU0S9$ ! [         a!  nUR
                  S:X  a  [        U5      ee S nAff = f)Nrr   r  r  )rd   r  rH  	PATH_CONFr   r  rl  r   rw  r  s      r%   r|  Configurations.__getitem__#  sW    	HHSM$T\\9s?7TW.YY 	yyCsm#		s   .1 
AAAc                 x     U R                  U5        g! [         a  nUR                  S:X  a   S nAge S nAff = f)NTr  F)rd   r   r  r  s      r%   rn  Configurations.__contains__4  s7    	HHSM 	yyC	s    
9449c                 8   [        U[        5      (       d  [        S[        U5       35      eU R	                  US9nUR
                  S:X  a  X   $ UR
                  S:X  a#  [        U R                  [        U-  [        SU0S9$ [        SUR
                   S35      e)	zCreates a configuration file named *name*.

If there is already a configuration file with that name,
the existing file is returned.

:param name: The name of the configuration file.
:type name: ``string``

:return: The :class:`ConfigurationFile` object.
Invalid name: )__confi/     rr   )r   rg  Unexpected status code   returned from creating a stanza)
re   r  r8   reprr   r  r  rH  r  r
  )r   rT   r]   s      r%   r   Configurations.create?  s     $$$~d4j\:;;99D9)??c!:??c!$T\\9t3C&Y`bfXghh28??2CCcdeer$   c                     [        S5      e)z#Raises `IllegalOperationException`.z4Cannot delete configuration files from the REST API.r   rv  s     r%   r  Configurations.deleteV  s    '(^__r$   c                     [         US   -  $ )Nrr   )r  r  s     r%   r  Configurations._entity_pathZ  s     5>))r$   r   N)r   r   r    r!   r"   r   r|  rn  r   r  r  r#   r   r$   r%   r   r     s(    S
"	f.`*r$   r   c                   $    \ rS rSrSrS rS rSrg)r
  ia  z2This class contains a single configuration stanza.c                 d    [        S0 UD6nU R                  R                  U R                  US9  U $ )zAdds keys to the current configuration stanza as a
dictionary of key-value pairs.

:param stanza: A dictionary of key-value pairs for the stanza.
:type stanza: ``dict``
:return: The :class:`Stanza` object.
)rZ   r   )r   rH  r   r   )r   stanzarZ   s      r%   submitStanza.submitd  s1       $))$/r$   c                     [        U R                  R                  R                  5        Vs/ s H%  nUR	                  S5      (       a  M  US:w  d  M#  UPM'     sn5      $ s  snf )Neaidisabled)r9   rh  r   keysrX  )r   r  s     r%   r  Stanza.__len__p  s`     t{{22779 D9!<<. 34
? 9 D E 	E Ds   A
AAr   N)r   r   r    r!   r"   r)  r  r#   r   r$   r%   r
  r
  a  s    <
Er$   r
  c                   l   ^  \ rS rSrSrU 4S jr\S 5       r\S 5       r\S 5       r	\S 5       r
SrU =r$ )	StoragePasswordix  z,This class contains a storage password.
    c                    > UR                  SS 5      nUR                  SUS L5      US'   [        TU ]  " X40 UD6  X@l        g )Nrg  rf  )rd   r   r   rh  )r   rH  r   r   rg  r   s        r%   r   StoragePassword.__init__|  sD    

7D)!'NE<M!N~1&1r$   c                 8    U R                   R                  S5      $ )Nclear_passwordr   rd   r   s    r%   r5  StoragePassword.clear_password  s    || 011r$   c                 8    U R                   R                  S5      $ )Nencr_passwordr6  r   s    r%   encrypted_password"StoragePassword.encrypted_password  s    ||00r$   c                 8    U R                   R                  S5      $ )Nrealmr6  r   s    r%   r=  StoragePassword.realm  s    ||((r$   c                 8    U R                   R                  S5      $ )Nr   r6  r   s    r%   r   StoragePassword.username  s    ||
++r$   r  )r   r   r    r!   r"   r   rA  r5  r:  r=  r   r#   rC  rD  s   @r%   r1  r1  x  s]     2 2 1 1 ) ) , ,r$   r1  c                   @   ^  \ rS rSrSrU 4S jrSS jrSS jrSrU =r	$ )r   i  zThis class provides access to the storage passwords from this Splunk
instance. Retrieve this collection using :meth:`Service.storage_passwords`.
c                    > UR                   R                  S:X  d  UR                   R                  S:X  a  [        S5      e[        TU ]  U[        [        S9  g )Nr  z4StoragePasswords cannot have wildcards in namespace.r   )r   r:  rT  r8   r   r   PATH_STORAGE_PASSWORDSr1  )r   rH  r   s     r%   r   StoragePasswords.__init__  sK    ""c)W->->-B-Bc-ISTT"8Or$   c                 r   [        U[        5      (       d  [        S[        U5       35      eUc  U R	                  XS9nOU R	                  XUS9nUR
                  S:w  a  [        SUR
                   S35      e[        U5      n[        US   5      n[        U R                  U R                  U5      USS	9nU$ )
a  Creates a storage password.

A `StoragePassword` can be identified by <username>, or by <realm>:<username> if the
optional realm parameter is also provided.

:param password: The password for the credentials - this is the only part of the credentials that will be stored securely.
:type name: ``string``
:param username: The username for the credentials.
:type name: ``string``
:param realm: The credential realm. (optional)
:type name: ``string``

:return: The :class:`StoragePassword` object created.
r  )passwordrT   )rF  r=  rT   r  r  r  r   T)rg  rf  )re   r  r8   r  r   r  ri   r   r1  rH  r  )r   rF  r   r=  r]   rh   rg  storage_passwords           r%   r   StoragePasswords.create  s     (C((~d8n-=>??=yy(yBHyy(hyOH??c!6x6GGghii$X.!'!*-*4<<9J9J59QY^mqrr$   c                     Uc  UnO[        USS9S-   [        USS9-   nUS   S:w  a  US-   n[        R                  X5      $ )a  Delete a storage password by username and/or realm.

The identifier can be passed in through the username parameter as
<username> or <realm>:<username>, but the preferred way is by
passing in the username and realm parameters.

:param username: The username for the credentials, or <realm>:<username> if the realm parameter is omitted.
:type name: ``string``
:param realm: The credential realm. (optional)
:type name: ``string``
:return: The `StoragePassword` collection.
:rtype: ``self``
Tr  :r6   )r   r   r  )r   r   r=  rT   s       r%   r  StoragePasswords.delete  sW     = D e$7#=
8bf@ggD 8s?#:D  ,,r$   r   rB   )
r   r   r    r!   r"   r   r   r  r#   rC  rD  s   @r%   r   r     s    P
 @- -r$   r   c                   D    \ rS rSrSrS rS r\S 5       r\S 5       r	Sr
g)	r   i  znThis class represents a group of fired alerts for a saved search. Access
it using the :meth:`alerts` property.c                 4    [         R                  " XU40 UD6  g rB   rd  r   ri  s       r%   r   AlertGroup.__init__      t6v6r$   c                     U R                   $ rB   )r  r   s    r%   r  AlertGroup.__len__  s    zzr$   c                 B    [        U R                  U R                  5      $ )z_Returns a collection of triggered alerts.

:return: A :class:`Collection` of triggered alerts.
)r   rH  r   r   s    r%   alertsAlertGroup.alerts  s     $,,		22r$   c                 L    [        U R                  R                  SS5      5      $ )z`Returns the count of triggered alerts.

:return: The triggered alert count.
:rtype: ``integer``
triggered_alert_countr   )r  r   rd   r   s    r%   r  AlertGroup.count  s!     4<<##$;Q?@@r$   r   N)r   r   r    r!   r"   r   r  rA  rT  r  r#   r   r$   r%   r   r     s;    -7 3 3 A Ar$   r   c                   $    \ rS rSrSrS rS rSrg)r   i  zThis class contains the collection of indexes in this Splunk instance.
Retrieve this collection using :meth:`Service.indexes`.
c                     U S   nUS   $ )zQReturns the name of the default index.

:return: The name of the default index.

_auditdefaultDatabaser   )r   indexs     r%   get_defaultIndexes.get_default  s     X&''r$   c                 x    U R                   R                  S:  a  [        R                  X5        g[	        S5      e)zDeletes a given index.

**Note**: This method is only supported in Splunk 5.0 and later.

:param name: The name of the index to delete.
:type name: ``string``
r   zKDeleting indexes via the REST API is not supported before Splunk version 5.N)rH  r   r   r  r   r  s     r%   r  Indexes.delete  s9     <<&&$.d)+ -U V Vr$   r   N)r   r   r    r!   r"   r^  r  r#   r   r$   r%   r   r     s    (Vr$   r   c                   l    \ rS rSrSrS rSS jr\R                  S 5       r	SS jr
S rSS	 jrS
 rSrg)r   i  zThis class represents an index and provides different operations, such as
cleaning the index, writing to the index, and so forth.c                 4    [         R                  " XU40 UD6  g rB   rN  ri  s       r%   r   Index.__init__  rP  r$   Nc                    SU R                   0nUb  XS'   Ub  X$S'   Ub  X4S'   [        [        S-   [        R                  " U5      -   SS9nU R
                  R                  [        L a  U R
                  R                  O%U R
                  R                  R                  SS	5      nS
U S3nU R
                  R                  5       (       a7  [        U R
                  R                  5       R                  5       5      nSU S3nU R
                  R                  5       nS[        U R
                  R                  U5      5       S3R!                  S5      SU R
                  R"                   S[%        U R
                  R&                  5       S3R!                  S5      SUR!                  S5      SS/n	U	 H  n
UR)                  U
5        M     U$ )a}  Opens a stream (a writable socket) for writing events to the index.

:param host: The host value for events written to the stream.
:type host: ``string``
:param source: The source value for events written to the stream.
:type source: ``string``
:param sourcetype: The sourcetype value for events written to the
    stream.
:type sourcetype: ``string``

:return: A writable socket.
r]  hostsource
sourcetype?TrV  zSplunk r'  zAuthorization: Splunk z
zCookie: zPOST z HTTP/1.1
rW   zHost: rJ  s   Accept-Encoding: identity
s    X-Splunk-Input-Mode: Streaming
s   
)rT   r   PATH_RECEIVERS_STREAMr   	urlencoderH  tokenr   rZ  has_cookiesr   get_cookiesrN   r   r  rY  encoderf  r  portwrite)r   rf  rg  rh  rO   r   cookie_headercookie_or_auth_headersockheadershs              r%   attachIndex.attach  s    #D&\H~!
#5/#58MM[_`.2ll.@.@DZ.Z**`d`l`l`r`r`z`z  |E  GI  aJ"8t L <<##%%/0H0H0J0P0P0RSM&.}oT$B!
 ||##%3t||44T:;<MJQQRYZDLL--.aDLL4E4E0F/GtLSST[\3(//88 AJJqM r$   c              /      #     U R                   " U0 UD6nUv   UR                  [        R                  5        UR	                  5         g! WR                  [        R                  5        UR	                  5         f = f7f)a  Opens a raw socket in a ``with`` block to write data to Splunk.

The arguments are identical to those for :meth:`attach`. The socket is
automatically closed at the end of the ``with`` block, even if an
exception is raised in the block.

:param host: The host value for events written to the stream.
:type host: ``string``
:param source: The source value for events written to the stream.
:type source: ``string``
:param sourcetype: The sourcetype value for events written to the
    stream.
:type sourcetype: ``string``

:returns: Nothing.

**Example**::

    import splunklib.client as client
    s = client.connect(...)
    index = s.indexes['some_index']
    with index.attached_socket(sourcetype='test') as sock:
        sock.send('Test event\r\n')

N)rw  shutdownsocket	SHUT_RDWRclose)r   rO   r   rt  s       r%   attached_socketIndex.attached_socketD  s[     6	;;//DJMM&**+JJL MM&**+JJLs   A>A
 0A>
1A;;A>c                    U R                  5         U S   nU S   nU R                  n U(       d*  U R                  R                  S:  a  U R	                  5         U R                  SSS9  U R                  5         [        R                  " 5       n[        US9nU R                  R                  S:w  am  [        R                  " 5       XV-   :  aR  [        S5        U R                  5         U R                  R                  S:w  a  [        R                  " 5       XV-   :  a  MR  U R                  R                  S:w  a  [        SU R                   S	U S
35      e U R                  X#S9  U(       d*  U R                  R                  S:  a  U R                  5         U $ ! U R                  X#S9  U(       d,  U R                  R                  S:  a  U R                  5         f f f = f)a&  Deletes the contents of the index.

This method blocks until the index is empty, because it needs to restore
values at the end of the operation.

:param timeout: The time-out period for the operation, in seconds (the
    default is 60).
:type timeout: ``integer``

:return: The :class:`Index`.
maxTotalDataSizeMBfrozenTimePeriodInSecsr   ry   )r  r  r   rc   zCleaning index z took longer than z seconds; timing out.)r   r-  rH  r   r  r  roll_hot_bucketsr   r   r   r   totalEventCountr   r   rT   r  )r   r   tdsftpwas_disabled_initiallyr   r   s          r%   cleanIndex.cleanf  s    	'(+,!%	)dll.I.ID.P KK1QKG!!# LLNEW-D,,..#5(,,.5<:Wa ,,..#5(,,.5<:W ||++s2$%dii[0B7)K`ac c 3
 KK3KK)dll.I.ID.P KK3KK)dll.I.ID.P /Q)s   C4F 6F AGc                 (    U R                  S5        U $ )zKPerforms rolling hot buckets for this index.

:return: The :class:`Index`.
zroll-hot-bucketsr  r   s    r%   r  Index.roll_hot_buckets  s    
 			$%r$   c                     SU R                   0nUb  X%S'   Ub  X5S'   Ub  XES'   U R                  R                  " [        4SU0UD6  U $ )at  Submits a single event to the index using ``HTTP POST``.

:param event: The event to submit.
:type event: ``string``
:param `host`: The host value of the event.
:type host: ``string``
:param `source`: The source value of the event.
:type source: ``string``
:param `sourcetype`: The sourcetype value of the event.
:type sourcetype: ``string``

:return: The :class:`Index`.
r]  rf  rg  rh  rZ   )rT   rH  r   PATH_RECEIVERS_SIMPLE)r   eventrf  rg  rh  rO   s         r%   r)  Index.submit  sY     #D&\H~!
#5/DeDtDr$   c                 f    U R                   US'   SnU R                  R                  " U4SU0UD6  U $ )a  Uploads a file for immediate indexing.

**Note**: The file must be locally accessible from the server.

:param filename: The name of the file to upload. The file can be a
    plain, compressed, or archived file.
:type filename: ``string``
:param kwargs: Additional arguments (optional). For more about the
    available parameters, see `Index parameters <http://dev.splunk.com/view/SP-CAAAEE6#indexparams>`_ on Splunk Developer Portal.
:type kwargs: ``dict``

:return: The :class:`Index`.
r]  zdata/inputs/oneshotrT   )rT   rH  r   )r   filenamer   r   s       r%   uploadIndex.upload  s7     ))w$$8X88r$   r   r  )<   )r   r   r    r!   r"   r   rw  
contextlibcontextmanagerr~  r  r  r)  r  r#   r   r$   r%   r   r     sB    ?7(T  B*X.r$   r   c                   6   ^  \ rS rSrSrSS jrU 4S jrSrU =r$ )r   i  zThis class represents a Splunk input. This class is the base for all
typed input classes and is also used when the client does not recognize an
input kind.
c                 <   [         R                  " XU40 UD6  UcL  UR                  S5      nUR                  S5      S-   nXV   S:X  a  XV   S-   XVS-      -   U l        OXV   U l        OX0l        U R                  S:X  a  SU l        U R                  S:X  a  SU l        g g )Nr   r   ry   tcptcp/raw	splunktcp
tcp/cooked)rd  r   r#  r]  r   )r   rH  r   r   r   path_segmentsis          r%   r   Input.__init__  s    
 	t6v6< JJsOM##H-1A5(),s2]q55II	),	I 99!DI99#$DI $r$   c                 2  > U R                   S;  a  [        TU ]  " S0 UD6$ UR                  5       nSU;   a  [	        S5      eSU R
                  R                  ;   a,  U R                   S:w  a  U R
                  R                  S   US'   [        TU ]  " S0 UD6$ )a  Updates the server with any changes you've made to the current input
along with any additional arguments you specify.

:param kwargs: Additional arguments (optional). For more about the
    available parameters, see `Input parameters <http://dev.splunk.com/view/SP-CAAAEE6#inputparams>`_ on Splunk Developer Portal.
:type kwargs: ``dict``

:return: The input this method was called on.
:rtype: class:`Input`
)r  r  r  r  udprestrictToHostz<Cannot set restrictToHost on an existing input with the SDK.r  r   )r   r   r  copyr   rh  r   )r   r   	to_updater   s      r%   r  Input.update  s     99PP7>+F++ I6)/0noo4;;#6#66499;M.2kk.A.ABR.S	*+ 7>.I..r$   r   rB   )	r   r   r    r!   r"   r   r  r#   rC  rD  s   @r%   r   r     s    
%,$/ $/r$   r   c                   |    \ rS rSrSrSS jrS rS rS rSS jr	S	 r
SS
 jr\S 5       rS rS rS rS rS rSrg)r   i	  zThis class represents a collection of inputs. The collection is
heterogeneous and each member of the collection contains a *kind* property
that indicates the specific type of input.
Retrieve this collection using :meth:`Service.inputs`.Nc                 >    [         R                  X[        [        S9  g Nr   )r   r   PATH_INPUTSr   )r   rH  kindmaps      r%   r   Inputs.__init__	  s    D;UCr$   c                 N   [        U[        5      (       a  [        U5      S:X  a  Uu  p[        USS9n U R	                  U R                  U5      S-   U-   5      nU R                  U5      n[        U5      S:  a  [        SU SU S35      e[        U5      S	:X  a  [        X45      eUS	   $ S nS n[        USS9nU R                   Hu  n U R	                  US-   U-   5      nU R                  U5      n[        U5      S:  a  [        SU SU S35      e[        U5      S	:X  a  M^  Ub  [        SU S35      eUS	   nMw     Uc  [        U5      eU$ ! [         a"  nUR                  S
:X  a  [        X45      ee S nAff = f! [         a  nUR                  S
:X  a   S nAM  e S nAff = f)Nr/  Tr  r   ry   zFound multiple inputs of kind z named r!  r   r  zFound multiple inputs named z, please specify a kind)re   r"  r9   r   rd   kindpathr  r)   rl  r   r  kinds)r   rw  r   r]   rh   r  	candidates          r%   r|  Inputs.__getitem__	  s    c5!!c#h!mICSt4C88DMM$$7#$=$CD//(3w<!#58VW[V\\cdgchhi6jkkw<1$"C;//qz! DISt4C

#xxs
S(89H"ooh7G7|a'9<Z[_Z``ghkgllm:noo7|q($0"=">seCZ [#] ]$+AJ	 #$  sm#=  99#"C;//	. ! yyC'	s=   A7E 
AE>$E>
E;E66E;>
F$FFF$c                    [        U[        5      (       a"  [        U5      S:X  a   U R                  U5        gU R
                   HL  n U R                  U R                  U5      S-   U-   5      nU R                  U5      n[        U5      S:  a    gMN     g! [         a     gf = f! [         a  nUR                  S:X  a   S nAM  e S nAff = f)Nr/  TFr   r   r  )re   r"  r9   r|  rl  r  rd   r  r  r   r  )r   rw  r   r]   rh   r  s         r%   rn  Inputs.__contains__D	  s    c5!!c#h!m  % 

	#xxd(;c(AC(GHH"ooh7G7|a'# (	 # #   ! yyC'	s0   B AB%
B"!B"%
C/CCCc                     U R                  U5      nU R                  " U4SU0UD6  [        USS9n[        U R                  U-   SU;   a
  US    SU 3OU5      n[        U R                  XR5      $ )a&  Creates an input of a specific kind in this collection, with any
arguments you specify.

:param `name`: The input name.
:type name: ``string``
:param `kind`: The kind of input:

    - "ad": Active Directory

    - "monitor": Files and directories

    - "registry": Windows Registry

    - "script": Scripts

    - "splunktcp": TCP, processed

    - "tcp": TCP, unprocessed

    - "udp": UDP

    - "win-event-log-collections": Windows event log

    - "win-perfmon": Performance monitoring

    - "win-wmi-collections": WMI

:type kind: ``string``
:param `kwargs`: Additional arguments (optional). For more about the
    available parameters, see `Input parameters <http://dev.splunk.com/view/SP-CAAAEE6#inputparams>`_ on Splunk Developer Portal.

:type kwargs: ``dict``

:return: The new :class:`Input`.
rT   Tr  r  rJ  )r  r   r   rU   r   r   rH  )r   rT   r   r   r  r   s         r%   r   Inputs.create]	  s    H ==&		(000 $T2II 4D4Nv&'($0TX
 T\\4..r$   c                     Uc)  U R                   R                  X   R                  5        U $ U R                   R                  XU4   R                  5        U $ )a,  Removes an input from the collection.

:param `kind`: The kind of input:

    - "ad": Active Directory

    - "monitor": Files and directories

    - "registry": Windows Registry

    - "script": Scripts

    - "splunktcp": TCP, processed

    - "tcp": TCP, unprocessed

    - "udp": UDP

    - "win-event-log-collections": Windows event log

    - "win-perfmon": Performance monitoring

    - "win-wmi-collections": WMI

:type kind: ``string``
:param name: The name of the input to remove.
:type name: ``string``

:return: The :class:`Inputs` collection.
)rH  r  r   )r   rT   r   s      r%   r  Inputs.delete	  sN    > <LL
0  LL4Z 0 5 56r$   c                 z    U R                  U R                  U    S35      n[        U[        5      n[	        U5      $ )a	  Returns metadata for the members of a given kind.

:param `kind`: The kind of input:

    - "ad": Active Directory

    - "monitor": Files and directories

    - "registry": Windows Registry

    - "script": Scripts

    - "splunktcp": TCP, processed

    - "tcp": TCP, unprocessed

    - "udp": UDP

    - "win-event-log-collections": Windows event log

    - "win-perfmon": Performance monitoring

    - "win-wmi-collections": WMI

:type kind: ``string``

:return: The metadata.
:rtype: class:``splunklib.data.Record``
z/_new)rd   _kindmapr_   r   r~   )r   r   r]   r   s       r%   r  Inputs.itemmeta	  s;    < 88t}}T2359:X':;#G,,r$   c                    Uc  / n/ nU R                  SR                  U5      5      n[        U5      nU H  nXR                  /-   nUR                  S:X  d  USS/:X  a  M,  SUR                   Vs/ s H  owR
                  PM     sn;   a1  SR                  XR                  /-   5      nUR                  U5        M  U R                  XR                  /-   5      n	UR                  U	5        M     U$ s  snf )Nr   allr  sslr   )	rd   joinri   rr   rs   ru   r  _get_kind_listextend)
r   subpathr  r]   r   r   this_subpathr  r   subkindss
             r%   r  Inputs._get_kind_list	  s    ?G88CHHW-.$X.E"kk]2L {{e#|u~'E5::6:aEE:66xx;;- 78T"..w++/FGX&   7s   0C1c                 "    U R                  5       $ )zeReturns the input kinds on this Splunk instance.

:return: The list of input kinds.
:rtype: ``list``
)r  r   s    r%   r  Inputs.kinds	  s     ""$$r$   c                 V    US:X  a
  [        SSS9$ US:X  a
  [        SSS9$ [        USS9$ )a  Returns a path to the resources for a given input kind.

:param `kind`: The kind of input:

    - "ad": Active Directory

    - "monitor": Files and directories

    - "registry": Windows Registry

    - "script": Scripts

    - "splunktcp": TCP, processed

    - "tcp": TCP, unprocessed

    - "udp": UDP

    - "win-event-log-collections": Windows event log

    - "win-perfmon": Performance monitoring

    - "win-wmi-collections": WMI

:type kind: ``string``

:return: The relative endpoint path.
:rtype: ``string``
r  r  TrV  r  r  r  )r   r   s     r%   r  Inputs.kindpath	  s:    < 5=iT::;l==$D11r$   c           	        ^ [        U5      S:X  a  U R                  n[        U5      S:X  a  US   n[        R                  S5        U R	                  U5      n[        R                  SU5         [        USS9nU R                  " U40 UD6n/ n[        W5      nUc  / $ U H^  n	[        U	5      n
[        R                  " U
R                  R                  5      n[        U R                   XCU
S	9nUR#                  U5        M`     U$ UR                  S
S5      n/ nU H  nSn [        USS9nU R                  U R	                  U5      US9n[        U5      nUc  M?  U H^  n	[        U	5      n
[        R                  " U
R                  R                  5      n[        U R                   XCU
S	9nUR#                  U5        M`     M     SU;   a  XrS   S nSU;   a  USUS    nUR                  SS5      S:X  a+  UR                  SS5      mTS:X  a  S nOU4S jn[%        X~S9nUR                  SS5      S:X  a+  UR                  SS5      mTS:X  a  S nOU4S jn[%        X~S9nUR                  SS5      S:X  a  ['        [)        U5      5      nU$ ! [         a"  nUR                  S:X  a  / s SnA$  SnAGN%SnAff = f! [         a  nUR                  S:X  a   SnAGM  e SnAff = f)aL  Returns a list of inputs that are in the :class:`Inputs` collection.
You can also filter by one or more input kinds.

This function iterates over all possible inputs, regardless of any arguments you
specify. Because the :class:`Inputs` collection is the union of all the inputs of each
kind, this method implements parameters such as "count", "search", and so
on at the Python level once all the data has been fetched. The exception
is when you specify a single input kind, and then this method makes a single request
with the usual semantics for parameters.

:param kinds: The input kinds to return (optional).

    - "ad": Active Directory

    - "monitor": Files and directories

    - "registry": Windows Registry

    - "script": Scripts

    - "splunktcp": TCP, processed

    - "tcp": TCP, unprocessed

    - "udp": UDP

    - "win-event-log-collections": Windows event log

    - "win-perfmon": Performance monitoring

    - "win-wmi-collections": WMI

:type kinds: ``string``
:param kwargs: Additional arguments (optional):

    - "count" (``integer``): The maximum number of items to return.

    - "offset" (``integer``): The offset of the first item to return.

    - "search" (``string``): The search query to filter responses.

    - "sort_dir" (``string``): The direction to sort returned items:
      "asc" or "desc".

    - "sort_key" (``string``): The field to use for sorting (optional).

    - "sort_mode" (``string``): The collating sequence for sorting
      returned items: "auto", "alpha", "alpha_case", or "num".

:type kwargs: ``dict``

:return: A list of input kinds.
:rtype: ``list``
r   ry   z8Inputs.list taking short circuit branch for single kind.zPath for inputs: %sTrV  r  Nr  r  *)r  r  r  	sort_modealpha
sort_fieldrT   c                 6    U R                   R                  5       $ rB   )rT   r0  r  s    r%   <lambda>Inputs.list.<locals>.<lambda>
  s    affllnr$   c                 *   > U T   R                  5       $ rB   )r0  r  r  s    r%   r  r  
  s    a
m113r$   )rw  
alpha_casec                     U R                   $ rB   r  r  s    r%   r  r  
  s    affr$   c                    > U T   $ rB   r   r  s    r%   r  r  
  s	    a
mr$   sort_dirascdesc)r9   r  r  r  r  r   rd   r   r  ri   r   r   r  r{   r  r   rH  r  sortedrf   reversed)r   r  r   r   r   r]   r  r  rh   r   rg  r  r  r   fr  s                  @r%   rf   Inputs.list
  s   n u:?JJEu:?8DLLST==&DLL.5!$D988D3F3 H(2G	 )%0 }}U[[%:%:;t||TuE' ! OHc*DH!$D988DMM$$78G )2G )%0 }}U[[%:%:;t||TuE' ! * vx 0 12Hf 01H::k4(G3L&9JV#,3h.H::k4(L8L&9JV#$+h.H::j%(F2HX./H{  99#I $2  88s?	s<   .J	 )J8	
J5J0$J50J58
KKKKc              +   F   #    U R                   " S0 UD6 H  nUv   M	     g 7fr   r  r  s      r%   r  Inputs.__iter__
  s      II''DJ (r  c              +   F   #    U R                   " S0 UD6 H  nUv   M	     g7f)aj  Iterates over the collection of inputs.

:param kwargs: Additional arguments (optional):

    - "count" (``integer``): The maximum number of items to return.

    - "offset" (``integer``): The offset of the first item to return.

    - "search" (``string``): The search query to filter responses.

    - "sort_dir" (``string``): The direction to sort returned items:
      "asc" or "desc".

    - "sort_key" (``string``): The field to use for sorting (optional).

    - "sort_mode" (``string``): The collating sequence for sorting
      returned items: "auto", "alpha", "alpha_case", or "num".

:type kwargs: ``dict``
Nr   )rf   r  s      r%   r  Inputs.iter
  r  r  c                 ,    U R                   " SSU0UD6  g)aq  Creates a oneshot data input, which is an upload of a single file
for one-time indexing.

:param path: The path and filename.
:type path: ``string``
:param kwargs: Additional arguments (optional). For more about the
    available parameters, see `Input parameters <http://dev.splunk.com/view/SP-CAAAEE6#inputparams>`_ on Splunk Developer Portal.
:type kwargs: ``dict``
rT   N)oneshotr  )r   r   r   s      r%   r  Inputs.oneshot
  s     			1$1&1r$   r   rB   )r   r   r    r!   r"   r   r|  rn  r   r  r  r  rA  r  r  rf   r  r  r  r#   r   r$   r%   r   r   	  s_    >
D.`21/f#J -D* % %"2H~@0
2r$   r   c                       \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS r\S 5       rS rS rS rS rS rS rS rS rS rS rSrg)r   i
  z#This class represents a search job.c                     SnUR                   (       a  UR                  [        US9nOUR                  [        US9n[        R
                  " XU4SS0UD6  X l        g )Nz{path}{sid})r   rl   rf  T)r   formatr\  r[  rd  r   rl   )r   rH  rl   r   r   s        r%   r   Job.__init__
  sQ    !!;;I3;7D;;Lc;:DtI$I&Ir$   c                 ,    [        U5      R                  $ rB   )r_   r   r   s     r%   r  Job._load_atom_entry
  s    (#)))r$   c                 z     U R                  SSS9  U $ ! [         a  nUR                  S:X  a   SnAU $ e SnAff = f)zTStops the current search and deletes the results cache.

:return: The :class:`Job`.
controlcancelactionr  N)r   r   r  )r   r  s     r%   r  
Job.cancel
  sM    
	IIiI1   	yyC   	s    
:55:c                 &    U R                  SSS9  U $ )z;Disables preview for this job.

:return: The :class:`Job`.
r  disablepreviewr  r  r   s    r%   disable_previewJob.disable_preview
  s    
 			)$4	5r$   c                 &    U R                  SSS9  U $ )zvEnables preview for this job.

**Note**: Enabling preview might slow search considerably.

:return: The :class:`Job`.
r  enablepreviewr  r  r   s    r%   enable_previewJob.enable_preview
  s     			)O	4r$   c                     UR                  SS5      US'   U R                  R                  (       a  U R                   " S0 UD6R                  $ U R                  " S0 UD6R                  $ )a  Returns a streaming handle to this job's events.

:param kwargs: Additional parameters (optional). For a list of valid
    parameters, see `GET search/jobs/{search_id}/events
    <http://docs.splunk.com/Documentation/Splunk/latest/RESTAPI/RESTsearch#GET_search.2Fjobs.2F.7Bsearch_id.7D.2Fevents>`_
    in the REST API documentation.
:type kwargs: ``dict``

:return: The ``InputStream`` IO handle to this job's events.
segmentationnone)eventsrd   rH  r   rZ   r   r  s     r%   r  
Job.events
  sX     "(NF!C~ <<&&88//444yy,V,111r$   c                 &    U R                  SSS9  U $ )z[Stops the job and provides intermediate results for retrieval.

:return: The :class:`Job`.
r  finalizer  r  r   s    r%   r  Job.finalize	  s    
 			)J	/r$   c                 j    U R                  5       (       d  gU R                  R                  S   S:H  nU$ )zzIndicates whether this job finished running.

:return: ``True`` if the job is done, ``False`` if not.
:rtype: ``boolean``
FisDone1)is_readyrh  r   )r   dones     r%   is_doneJob.is_done  s0     }}##H-4r$   c                     U R                  5       nUR                  S:X  a  gU R                  U5      U l        U R                  R                  S   S;  nU$ )zIndicates whether this job is ready for querying.

:return: ``True`` if the job is ready, ``False`` if not.
:rtype: ``boolean``

   FdispatchState)QUEUEDPARSING)rd   r  r[   rh  r   )r   r]   readys      r%   r  Job.is_ready  sM     88:??c!ii)##O4<QQr$   c                     U R                   $ )znReturns the name of the search job, which is the search ID (SID).

:return: The search ID.
:rtype: ``string``
)rl   r   s    r%   rT   Job.name*  s     xxr$   c                 &    U R                  SSS9  U $ )z9Suspends the current search.

:return: The :class:`Job`.
r  pauser  r  r   s    r%   r  	Job.pause3  s    
 			)G	,r$   c                     UR                  SS5      US'   U R                  R                  (       a  U R                   " S0 UD6R                  $ U R                  " S0 UD6R                  $ )a  Returns a streaming handle to this job's search results. To get a nice, Pythonic iterator, pass the handle
to :class:`splunklib.results.JSONResultsReader` along with the query param "output_mode='json'", as in::

    import splunklib.client as client
    import splunklib.results as results
    from time import sleep
    service = client.connect(...)
    job = service.jobs.create("search * | head 5")
    while not job.is_done():
        sleep(.2)
    rr = results.JSONResultsReader(job.results(output_mode='json'))
    for result in rr:
        if isinstance(result, results.Message):
            # Diagnostic messages may be returned in the results
            print(f'{result.type}: {result.message}')
        elif isinstance(result, dict):
            # Normal events are returned as dicts
            print(result)
    assert rr.is_preview == False

Results are not available until the job has finished. If called on
an unfinished job, the result is an empty event set.

This method makes a single roundtrip
to the server, plus at most two additional round trips if
the ``autologin`` field of :func:`connect` is set to ``True``.

:param query_params: Additional parameters (optional). For a list of valid
    parameters, see `GET search/jobs/{search_id}/results
    <http://docs.splunk.com/Documentation/Splunk/latest/RESTAPI/RESTsearch#GET_search.2Fjobs.2F.7Bsearch_id.7D.2Fresults>`_.
:type query_params: ``dict``

:return: The ``InputStream`` IO handle to this job's results.
r  r  )r  r  r   query_paramss     r%   r  Job.results;  s[    F (4'7'7'O^$ <<&&8866;;;yy3l3888r$   c                     UR                  SS5      US'   U R                  R                  (       a  U R                   " S0 UD6R                  $ U R                  " S0 UD6R                  $ )a  Returns a streaming handle to this job's preview search results.

Unlike :class:`splunklib.results.JSONResultsReader`along with the query param "output_mode='json'",
which requires a job to be finished to return any results, the ``preview`` method returns any results that
have been generated so far, whether the job is running or not. The returned search results are the raw data
from the server. Pass the handle returned to :class:`splunklib.results.JSONResultsReader` to get a nice,
Pythonic iterator over objects, as in::

    import splunklib.client as client
    import splunklib.results as results
    service = client.connect(...)
    job = service.jobs.create("search * | head 5")
    rr = results.JSONResultsReader(job.preview(output_mode='json'))
    for result in rr:
        if isinstance(result, results.Message):
            # Diagnostic messages may be returned in the results
            print(f'{result.type}: {result.message}')
        elif isinstance(result, dict):
            # Normal events are returned as dicts
            print(result)
    if rr.is_preview:
        print("Preview of a running search job.")
    else:
        print("Job is finished. Results are final.")

This method makes one roundtrip to the server, plus at most
two more if
the ``autologin`` field of :func:`connect` is set to ``True``.

:param query_params: Additional parameters (optional). For a list of valid
    parameters, see `GET search/jobs/{search_id}/results_preview
    <http://docs.splunk.com/Documentation/Splunk/latest/RESTAPI/RESTsearch#GET_search.2Fjobs.2F.7Bsearch_id.7D.2Fresults_preview>`_
    in the REST API documentation.
:type query_params: ``dict``

:return: The ``InputStream`` IO handle to this job's preview results.
r  r  )results_previewr  r  s     r%   previewJob.previewe  s[    L (4'7'7'O^$ <<&&88>>CCCyy;l;@@@r$   c                 :    U R                   " S0 UD6R                  $ )a  Returns a streaming handle to this job's search log.

:param `kwargs`: Additional parameters (optional). For a list of valid
    parameters, see `GET search/jobs/{search_id}/search.log
    <http://docs.splunk.com/Documentation/Splunk/latest/RESTAPI/RESTsearch#GET_search.2Fjobs.2F.7Bsearch_id.7D.2Fsearch.log>`_
    in the REST API documentation.
:type kwargs: ``dict``

:return: The ``InputStream`` IO handle to this job's search log.
)z
search.logrd   rZ   r  s     r%   	searchlogJob.searchlog  s     xx//444r$   c                 (    U R                  SSUS9  U $ )a  Sets this job's search priority in the range of 0-10.

Higher numbers indicate higher priority. Unless splunkd is
running as *root*, you can only decrease the priority of a running job.

:param `value`: The search priority.
:type value: ``integer``

:return: The :class:`Job`.
r  setpriority)r  priorityr  r8  s     r%   set_priorityJob.set_priority  s     			)ME	Br$   c                 :    U R                   " S0 UD6R                  $ )a  Returns a streaming handle to this job's summary.

:param `kwargs`: Additional parameters (optional). For a list of valid
    parameters, see `GET search/jobs/{search_id}/summary
    <http://docs.splunk.com/Documentation/Splunk/latest/RESTAPI/RESTsearch#GET_search.2Fjobs.2F.7Bsearch_id.7D.2Fsummary>`_
    in the REST API documentation.
:type kwargs: ``dict``

:return: The ``InputStream`` IO handle to this job's summary.
)summaryr  r  s     r%   r&  Job.summary  s     xx,V,111r$   c                 :    U R                   " S0 UD6R                  $ )a  Returns a streaming handle to this job's timeline results.

:param `kwargs`: Additional timeline arguments (optional). For a list of valid
    parameters, see `GET search/jobs/{search_id}/timeline
    <http://docs.splunk.com/Documentation/Splunk/latest/RESTAPI/RESTsearch#GET_search.2Fjobs.2F.7Bsearch_id.7D.2Ftimeline>`_
    in the REST API documentation.
:type kwargs: ``dict``

:return: The ``InputStream`` IO handle to this job's timeline.
)timeliner  r  s     r%   r)  Job.timeline  s     xx-f-222r$   c                 &    U R                  SSS9  U $ )zExtends the expiration time of the search to the current time (now) plus
the time-to-live (ttl) value.

:return: The :class:`Job`.
r  touchr  r  r   s    r%   r,  	Job.touch  s     			)G	,r$   c                 (    U R                  SSUS9  U $ )zSet the job's time-to-live (ttl) value, which is the time before the
search job expires and is still available.

:param `value`: The ttl value, in seconds.
:type value: ``integer``

:return: The :class:`Job`.
r  setttl)r  ttlr  r8  s     r%   set_ttlJob.set_ttl  s     			)H%	8r$   c                 &    U R                  SSS9  U $ )zCResumes the current search, if paused.

:return: The :class:`Job`.
r  unpauser  r  r   s    r%   r4  Job.unpause  s    
 			)I	.r$   )rh  rl   N)r   r   r    r!   r"   r   r  r  r  r  r  r  r  r  rA  rT   r  r  r  r  r#  r&  r)  r,  r1  r4  r#   r   r$   r%   r   r   
  s{    -
* 2$	  (9T+AZ523
r$   r   c                   <    \ rS rSrSrS rS rS rS rS r	S r
S	rg
)r   i  zgThis class represents a collection of search jobs. Retrieve this
collection using :meth:`Service.jobs`.c                     UR                   (       d  [        nO[        n[        R	                  XU[
        S9  SU l        g )Nr   r   )r   r[  r\  r   r   r   r  rI  s      r%   r   Jobs.__init__  s3    %%DDD4c: r$   c                     [        U5      nUc  / $ / nU H@  n[        U5      nU R                  U R                  US   S   US9nUR	                  U5        MB     U$ )Nr   rl   r  )ri   r   r   rH  r  r  s          r%   r  Jobs._load_list  sm    $X.?2IE%e,EYYi '  F OOF#  r$   c                     UR                  SS5      S:X  a  [        S5      eU R                  " SSU0UD6n[        X2R                  SS5      5      n[	        U R
                  U5      $ )a  Creates a search using a search query and any additional parameters
you provide.

:param query: The search query.
:type query: ``string``
:param kwargs: Additiona parameters (optional). For a list of available
    parameters, see `Search job parameters
    <http://dev.splunk.com/view/SP-CAAAEE5#searchjobparams>`_
    on Splunk Developer Portal.
:type kwargs: ``dict``

:return: The :class:`Job`.
	exec_modeNr  zACannot specify exec_mode=oneshot; use the oneshot method instead.r  rn   r   )rd   	TypeErrorr   rp   r   rH  )r   r   r   r]   rl   s        r%   r   Jobs.create  s_     ::k4(I5_``994E4V4**]D"AB4<<%%r$   c                     SU;   a  [        S5      eUR                  SS5      US'   U R                  " SSUS.UD6R                  $ )a  Runs a search and immediately starts streaming preview events. This method returns a streaming handle to
this job's events as an XML document from the server. To parse this stream into usable Python objects,
pass the handle to :class:`splunklib.results.JSONResultsReader` along with the query param
"output_mode='json'"::

    import splunklib.client as client
    import splunklib.results as results
    service = client.connect(...)
    rr = results.JSONResultsReader(service.jobs.export("search * | head 5",output_mode='json'))
    for result in rr:
        if isinstance(result, results.Message):
            # Diagnostic messages may be returned in the results
            print(f'{result.type}: {result.message}')
        elif isinstance(result, dict):
            # Normal events are returned as dicts
            print(result)
    assert rr.is_preview == False

Running an export search is more efficient as it streams the results
directly to you, rather than having to write them out to disk and make
them available later. As soon as results are ready, you will receive
them.

The ``export`` method makes a single roundtrip to the server (as opposed
to two for :meth:`create` followed by :meth:`preview`), plus at most two
more if the ``autologin`` field of :func:`connect` is set to ``True``.

:raises `ValueError`: Raised for invalid queries.
:param query: The search query.
:type query: ``string``
:param params: Additional arguments (optional). For a list of valid
    parameters, see `GET search/jobs/export
    <http://docs/Documentation/Splunk/latest/RESTAPI/RESTsearch#search.2Fjobs.2Fexport>`_
    in the REST API documentation.
:type params: ``dict``

:return: The ``InputStream`` IO handle to raw XML returned from the server.
r<  z&Cannot specify an exec_mode to export.r  r  export)r^  r  r   r=  rd   r   rZ   r   r   r   s      r%   r@  Jobs.export  sV    N & DEE!'NF!C~yy #h %#!##'4	(r$   c                     [        5       e)zThere is no metadata available for class:``Jobs``.

Any call to this method raises a class:``NotSupportedError``.

:raises: class:``NotSupportedError``
r   r   s    r%   r  Jobs.itemmetaD        !!r$   c                     SU;   a  [        S5      eUR                  SS5      US'   U R                  " SUSS.UD6R                  $ )aq  Run a oneshot search and returns a streaming handle to the results.

The ``InputStream`` object streams fragments from the server. To parse this stream into usable Python
objects, pass the handle to :class:`splunklib.results.JSONResultsReader` along with the query param
"output_mode='json'" ::

    import splunklib.client as client
    import splunklib.results as results
    service = client.connect(...)
    rr = results.JSONResultsReader(service.jobs.oneshot("search * | head 5",output_mode='json'))
    for result in rr:
        if isinstance(result, results.Message):
            # Diagnostic messages may be returned in the results
            print(f'{result.type}: {result.message}')
        elif isinstance(result, dict):
            # Normal events are returned as dicts
            print(result)
    assert rr.is_preview == False

The ``oneshot`` method makes a single roundtrip to the server (as opposed
to two for :meth:`create` followed by :meth:`results`), plus at most two more
if the ``autologin`` field of :func:`connect` is set to ``True``.

:raises ValueError: Raised for invalid queries.

:param query: The search query.
:type query: ``string``
:param params: Additional arguments (optional):

    - "output_mode": Specifies the output format of the results (XML,
      JSON, or CSV).

    - "earliest_time": Specifies the earliest time in the time range to
      search. The time string can be a UTC time (with fractional seconds),
      a relative time specifier (to now), or a formatted time string.

    - "latest_time": Specifies the latest time in the time range to
      search. The time string can be a UTC time (with fractional seconds),
      a relative time specifier (to now), or a formatted time string.

    - "rf": Specifies one or more fields to add to the search.

:type params: ``dict``

:return: The ``InputStream`` IO handle to raw XML returned from the server.
r<  z'Cannot specify an exec_mode to oneshot.r  r  r  )r  r<  r   rA  rB  s      r%   r  Jobs.oneshotM  sV    ^ & EFF!'NF!C~yy ##,#!##'4	(r$   )r  N)r   r   r    r!   r"   r   r  r   r@  r  r  r#   r   r$   r%   r   r     s&    .	&(,(\"4(r$   r   c                   $    \ rS rSrSrS rS rSrg)r   i  zyThis class represents a collection of service logging categories.
Retrieve this collection using :meth:`Service.loggers`.c                 8    [         R                  X[        5        g rB   )r   r   PATH_LOGGERr  s     r%   r   Loggers.__init__  s    D;7r$   c                     [        5       e)zThere is no metadata available for class:``Loggers``.

Any call to this method raises a class:``NotSupportedError``.

:raises: class:``NotSupportedError``
rE  r   s    r%   r  Loggers.itemmeta  rG  r$   r   N)r   r   r    r!   r"   r   r  r#   r   r$   r%   r   r     s    ?8"r$   r   c                   *    \ rS rSrS r\S 5       rSrg)r   i  c                 4    [         R                  " XU40 UD6  g rB   rN  ri  s       r%   r   Message.__init__  rP  r$   c                     X R                      $ )zKReturns the message value.

:return: The message value.
:rtype: ``string``
r  r   s    r%   r   Message.value  s     IIr$   r   N)r   r   r    r!   r   rA  r   r#   r   r$   r%   r   r     s    7  r$   r   c                   :    \ rS rSrSrS rS r\S 5       rS r	Sr
g)	r   i  zThis class contains the different types of modular inputs. Retrieve this
collection using :meth:`Service.modular_input_kinds`.
c                 p    U R                   R                  S   S   nX;   a  g[        R                  X5      $ )N	endpointsrO   T)rg  r   rd  rn  r   rT   rO   s      r%   rn  ModularInputKind.__contains__  s4    zz!!+.v6<""4..r$   c                 x    U R                   R                  S   S   nX;   a  US   $ [        R                  X5      $ )NendpointrO   r   )rg  r   rd  r|  rX  s      r%   r|  ModularInputKind.__getitem__  s;    zz!!*-f5<<!!$--r$   c                 :    U R                   R                  S   S   $ )a  A dictionary of all the arguments supported by this modular input kind.

The keys in the dictionary are the names of the arguments. The values are
another dictionary giving the metadata about that argument. The possible
keys in that dictionary are ``"title"``, ``"description"``, ``"required_on_create``",
``"required_on_edit"``, ``"data_type"``. Each value is a string. It should be one
of ``"true"`` or ``"false"`` for ``"required_on_create"`` and ``"required_on_edit"``,
and one of ``"boolean"``, ``"string"``, or ``"number``" for ``"data_type"``.

:return: A dictionary describing the arguments this modular input kind takes.
:rtype: ``dict``
r[  rO   r  r   s    r%   	argumentsModularInputKind.arguments  s     zz!!*-f55r$   c                     [        S5      e)z3Raises an error. Modular input kinds are read only.z7Modular input kinds cannot be updated via the REST API.r"  r  s     r%   r  ModularInputKind.update  s    '(abbr$   r   N)r   r   r    r!   r"   rn  r|  rA  r^  r  r#   r   r$   r%   r   r     s+    /. 6 6cr$   r   c                       \ rS rSrSrS rS r\S 5       rS r	\S 5       r
S rSS
 jrSS jrS r\S 5       rS rSrg	)SavedSearchi  z%This class represents a saved search.c                 4    [         R                  " XU40 UD6  g rB   rN  ri  s       r%   r   SavedSearch.__init__  rP  r$   c                 (    U R                  S5        U $ )zxAcknowledges the suppression of alerts from this saved search and
resumes alerting.

:return: The :class:`SavedSearch`.
acknowledger  r   s    r%   rg  SavedSearch.acknowledge  s     			- r$   c                 `    [        U R                  R                  R                  SS5      5      $ )zReturns the number of alerts fired by this saved search.

:return: The number of alerts fired by this saved search.
:rtype: ``integer``
rW  r   )r  rh  r   rd   r   s    r%   alert_countSavedSearch.alert_count  s'     4;;&&**+BAFGGr$   c                     U R                   " S0 UD6n[        X!R                  SS5      5      n[        U R                  U5      $ )a  Runs the saved search and returns the resulting search job.

:param `kwargs`: Additional dispatch arguments (optional). For details,
                 see the `POST saved/searches/{name}/dispatch
                 <http://docs.splunk.com/Documentation/Splunk/latest/RESTAPI/RESTsearch#POST_saved.2Fsearches.2F.7Bname.7D.2Fdispatch>`_
                 endpoint in the REST API documentation.
:type kwargs: ``dict``
:return: The :class:`Job`.
rn   N)dispatch)r   rp   rd   r   rH  )r   r   r]   rl   s       r%   rm  SavedSearch.dispatch  s;     99262**]D"AB4<<%%r$   c           
      j   U S   S:X  a  [        S5      e[        U R                  U R                  R                  [        U R
                  -   U R                  R                  R                  U R                  R                  R                  U R                  R                  R                  S9[        S9nU$ )zReturns the collection of fired alerts (a fired alert group)
corresponding to this saved search's alerts.

:raises IllegalOperationException: Raised when the search is not scheduled.

:return: A collection of fired alerts.
:rtype: :class:`AlertGroup`
is_scheduledrc   z*Unscheduled saved searches have no alerts.rS  r   )r   r   rH  rY  r   rT   rh  r|   r:  rT  rU  r   )r   cs     r%   r   SavedSearch.fired_alerts  s     3&+,XYYLLLL!!"3dii"?(,(:(:(@(@&*kk&8&8&<&<*.++*<*<*D*D " F  r$   c                     U R                   " S0 UD6n[        U5      nUc  / $ / nU H4  n[        U R                  UR                  5      nUR                  U5        M6     U$ )zReturns a list of search jobs corresponding to this saved search.

:param `kwargs`: Additional arguments (optional).
:type kwargs: ``dict``

:return: A list of :class:`Job` objects.
)history)rd   ri   r   rH  rr   r  )r   r   r]   rh   r   r   r   s          r%   rt  SavedSearch.history  s^     8800$X.?2IEdllEKK0CKK  r$   Nc                 j    Uc  U R                   R                  n[        R                  " U 4SU0UD6  U $ )a  Updates the server with any changes you've made to the current saved
search along with any additional arguments you specify.

:param `search`: The search query (optional).
:type search: ``string``
:param `kwargs`: Additional arguments (optional). For a list of available
    parameters, see `Saved search parameters
    <http://dev.splunk.com/view/SP-CAAAEE5#savedsearchparams>`_
    on Splunk Developer Portal.
:type kwargs: ``dict``

:return: The :class:`SavedSearch`.
r  )r   r  rd  r  )r   r  r   s      r%   r  SavedSearch.update  s2    " >DLL$7$76d464V4r$   c                     U R                  SUUS9nU R                  U5      n[        U5      nUR                  R                   Vs/ s H"  n[
        R                  " [        U5      5      PM$     nnU$ s  snf )a  Returns the times when this search is scheduled to run.

By default this method returns the times in the next hour. For different
time ranges, set *earliest_time* and *latest_time*. For example,
for all times in the last day use "earliest_time=-1d" and
"latest_time=now".

:param earliest_time: The earliest time.
:type earliest_time: ``string``
:param latest_time: The latest time.
:type latest_time: ``string``

:return: The list of search times.
scheduled_times)earliest_timelatest_time)rd   r  r   r   ry  r   fromtimestampr  )r   rz  r{  r]   r   r  r=   timess           r%   ry  SavedSearch.scheduled_times*  s     88-*7(3  5 $$X.%++5575Q ''A/5 	 77s   )A3c                 &    U R                  SUS9  U $ )zSkips any scheduled runs of this search in the next *expiration*
number of seconds.

:param expiration: The expiration period, in seconds.
:type expiration: ``integer``

:return: The :class:`SavedSearch`.
suppress
expirationr  )r   r  s     r%   r  SavedSearch.suppressB  s     			*	4r$   c                 p    U R                  S5      nUR                  S:X  a  [        UR                  5      $ g)zReturns the number of seconds that this search is blocked from running
(possibly 0).

:return: The number of seconds.
:rtype: ``integer``
r  r  r   )r  
suppressedr  r  )r   rg   s     r%   r  SavedSearch.suppressedN  s2     Z(<<3q||$$r$   c                 &    U R                  SSS9  U $ )z`Cancels suppression and makes this search run as scheduled.

:return: The :class:`SavedSearch`.
r  rc   r  r  r   s    r%   
unsuppressSavedSearch.unsuppress[  s    
 			*	-r$   r   rB   )r   z+1h)r   r   r    r!   r"   r   rg  rA  rj  rm  r   rt  r  ry  r  r  r  r#   r   r$   r%   rc  rc    sk    /7 H H&  ("*0
 
 
r$   rc  c                   $    \ rS rSrSrS rS rSrg)r  id  ztThis class represents a collection of saved searches. Retrieve this
collection using :meth:`Service.saved_searches`.c                 >    [         R                  X[        [        S9  g r  )r   r   PATH_SAVED_SEARCHESrc  r  s     r%   r   SavedSearches.__init__h  s    .[ 	 	Br$   c                 4    [         R                  " X4SU0UD6$ )a  Creates a saved search.

:param name: The name for the saved search.
:type name: ``string``
:param search: The search query.
:type search: ``string``
:param kwargs: Additional arguments (optional). For a list of available
    parameters, see `Saved search parameters
    <http://dev.splunk.com/view/SP-CAAAEE5#savedsearchparams>`_
    on Splunk Developer Portal.
:type kwargs: ``dict``
:return: The :class:`SavedSearches` collection.
r  r   r   )r   rT   r  r   s       r%   r   SavedSearches.createl  s       EFEfEEr$   r   Nr   r   r    r!   r"   r   r   r#   r   r$   r%   r  r  d  s    8BFr$   r  c                   x    \ rS rSrSrS r\S 5       r\S 5       r\S 5       r	\S 5       r
SS	 jr\S
 5       rSrg)Macroi}  z%This class represents a search macro.c                 4    [         R                  " XU40 UD6  g rB   rN  ri  s       r%   r   Macro.__init__  rP  r$   c                 N    U R                   R                  R                  SS5      $ )zNReturns the macro arguments.
:return: The macro arguments.
:rtype: ``string``
rO   r'  rh  r   rd   r   s    r%   rO   
Macro.args  s!     {{""&&vr22r$   c                 N    U R                   R                  R                  SS5      $ )zPReturns the macro definition.
:return: The macro definition.
:rtype: ``string``

definitionr'  r  r   s    r%   r  Macro.definition  !     {{""&&|R88r$   c                 N    U R                   R                  R                  SS5      $ )z|Returns the validation error message for the macro.
:return: The validation error message for the macro.
:rtype: ``string``
errormsgr'  r  r   s    r%   r  Macro.errormsg  s!     {{""&&z266r$   c                 N    U R                   R                  R                  SS5      $ )zsReturns the eval-based definition status of the macro.
:return: The iseval value for the macro.
:rtype: ``string``
isevalrc   r  r   s    r%   r  Macro.iseval  s!     {{""&&x55r$   Nc                 j    Uc  U R                   R                  n[        R                  " U 4SU0UD6  U $ )a  Updates the server with any changes you've made to the current macro
along with any additional arguments you specify.
:param `definition`: The macro definition (optional).
:type definition: ``string``
:param `kwargs`: Additional arguments (optional). Available parameters are:
    'disabled', 'iseval', 'validation', and 'errormsg'.
:type kwargs: ``dict``
:return: The :class:`Macro`.
r  )r   r  rd  r  )r   r  r   s      r%   r  Macro.update  s3     DLL,C,Czd<z<V<r$   c                 N    U R                   R                  R                  SS5      $ )zvReturns the validation expression for the macro.
:return: The validation expression for the macro.
:rtype: ``string``

validationr'  r  r   s    r%   r  Macro.validation  r  r$   r   rB   )r   r   r    r!   r"   r   rA  rO   r  r  r  r  r  r#   r   r$   r%   r  r  }  ss    /7 3 3 9 9 7 7 6 6" 9 9r$   r  c                   $    \ rS rSrSrS rS rSrg)r  i  zdThis class represents a collection of macros. Retrieve this
collection using :meth:`Service.macros`.c                 >    [         R                  X[        [        S9  g r  )r   r   PATH_MACROSr  r  s     r%   r   Macros.__init__  s    ;U 	 	4r$   c                 4    [         R                  " X4SU0UD6$ )aU  Creates a macro.
:param name: The name for the macro.
:type name: ``string``
:param definition: The macro definition.
:type definition: ``string``
:param kwargs: Additional arguments (optional). Available parameters are:
    'disabled', 'iseval', 'validation', and 'errormsg'.
:type kwargs: ``dict``
:return: The :class:`Macros` collection.
r  r  )r   rT   r  r   s       r%   r   Macros.create  s       M
MfMMr$   r   Nr  r   r$   r%   r  r    s    04Nr$   r  c                   $    \ rS rSrSrS rS rSrg)r  i  z{This class represents configuration settings for a Splunk service.
Retrieve this collection using :meth:`Service.settings`.c                 4    [         R                  " XS40 UD6  g )Nz/services/server/settingsrN  )r   rH  r   s      r%   r   Settings.__init__  s    'BMfMr$   c                 >    U R                   R                  " S0 UD6  U $ )a  Updates the settings on the server using the arguments you provide.

:param kwargs: Additional arguments. For a list of valid arguments, see
    `POST server/settings/{name}
    <http://docs.splunk.com/Documentation/Splunk/latest/RESTAPI/RESTsystem#POST_server.2Fsettings.2F.7Bname.7D>`_
    in the REST API documentation.
:type kwargs: ``dict``
:return: The :class:`Settings` collection.
)z"/services/server/settings/settings)rH  r   r  s     r%   r  Settings.update  s     	I&Ir$   r   N)r   r   r    r!   r"   r   r  r#   r   r$   r%   r  r    s    @Nr$   r  c                   (    \ rS rSrSr\S 5       rSrg)Useri  z)This class represents a Splunk user.
    c                    U R                   R                  R                  5        Vs/ s H  oR                  PM     nnU R                  R                   Vs/ s H#  o3U;   d  M
  U R                   R                  U   PM%     sn$ s  snf s  snf )z]Returns a list of roles assigned to this user.

:return: The list of roles.
:rtype: ``list``
)rH  r	  rf   rT   r   )r   rg   all_role_namesrT   s       r%   role_entitiesUser.role_entities  sq     +/,,*<*<*A*A*CD*CQ&&*CD59\\5G5Gb5GTSaKa(""4(5Gbb Ebs   B	B#Br   N)r   r   r    r!   r"   rA  r  r#   r   r$   r%   r  r    s     c cr$   r  c                   6    \ rS rSrSrS rS rS rS rS r	Sr
g	)
r>  i  zThis class represents the collection of Splunk users for this instance of
Splunk. Retrieve this collection using :meth:`Service.users`.
c                 >    [         R                  X[        [        S9  g r  )r   r   
PATH_USERSr  r  s     r%   r   Users.__init__      D:DAr$   c                 H    [         R                  XR                  5       5      $ rB   r   r|  r0  rv  s     r%   r|  Users.__getitem__       %%dIIK88r$   c                 H    [         R                  XR                  5       5      $ rB   r   rn  r0  r  s     r%   rn  Users.__contains__      &&tZZ\::r$   c                    [        U[        5      (       d  [        S[        U5       35      eUR                  5       nU R                  " SXUS.UD6  U R                  U5      n[        U[        5      R                  n[        U5      nU R                  U R                  [        R                  " UR                  R                  5      US9nU$ )a  Creates a new user.

This function makes two roundtrips to the server, plus at most
two more if
the ``autologin`` field of :func:`connect` is set to ``True``.

:param username: The username.
:type username: ``string``
:param password: The password.
:type password: ``string``
:param roles: A single role or list of roles for the user.
:type roles: ``string`` or  ``list``
:param params: Additional arguments (optional). For a list of available
    parameters, see `User authentication parameters
    <http://dev.splunk.com/view/SP-CAAAEJ6#userauthparams>`_
    on Splunk Developer Portal.
:type params: ``dict``

:return: The new user.
:rtype: :class:`User`

**Example**::

    import splunklib.client as client
    c = client.connect(...)
    users = c.users
    boris = users.create("boris", "securepassword", roles="user")
    hilda = users.create("hilda", "anotherpassword", roles=["user","power"])
zInvalid username: )rT   rF  r	  r  r   re   r  r8   r0  r   rd   r_   r  r   r   r   rH  r   r  r{   r  )	r   r   rF  r	  r   r]   r   rg  r  s	            r%   r   Users.create  s    < (C((1#h-ABB>>#		Jx%J6J 88H%8[177!%(LLMM%++//0   r$   c                 H    [         R                  XR                  5       5      $ )zDeletes the user and returns the resulting collection of users.

:param name: The name of the user to delete.
:type name: ``string``

:return:
:rtype: :class:`Users`
r   r  r0  r  s     r%   r  Users.delete3  s       zz|44r$   r   Nr   r   r    r!   r"   r   r|  rn  r   r  r#   r   r$   r%   r>  r>    s"    B9;+Z	5r$   r>  c                   $    \ rS rSrSrS rS rSrg)Rolei?  z'This class represents a user role.
    c                     U R                   R                  nU H  nX2;  d  M
  [        U5      e   U S   [        U5      -   nU R	                  US9  U $ )a  Grants additional capabilities to this role.

:param capabilities_to_grant: Zero or more capabilities to grant this
    role. For a list of capabilities, see
    `Capabilities <http://dev.splunk.com/view/SP-CAAAEJ6#capabilities>`_
    on Splunk Developer Portal.
:type capabilities_to_grant: ``string`` or ``list``
:return: The :class:`Role`.

**Example**::

    service = client.connect(...)
    role = service.roles['somerole']
    role.grant('change_own_password', 'search')
r   r   )rH  r   r/   rf   r   )r   capabilities_to_grantpossible_capabilities
capabilitynew_capabilitiess        r%   grant
Role.grantC  s[      !% 9 9/J6&z22 0  /$7L2MM		/	0r$   c                     U R                   R                  nU H  nX2;  d  M
  [        U5      e   U S   n/ nU H  nXa;  d  M
  UR                  U5        M     U(       d  SnU R	                  US9  U $ )a  Revokes zero or more capabilities from this role.

:param capabilities_to_revoke: Zero or more capabilities to grant this
    role. For a list of capabilities, see
    `Capabilities <http://dev.splunk.com/view/SP-CAAAEJ6#capabilities>`_
    on Splunk Developer Portal.
:type capabilities_to_revoke: ``string`` or ``list``

:return: The :class:`Role`.

**Example**::

    service = client.connect(...)
    role = service.roles['somerole']
    role.revoke('change_own_password', 'search')
r   r'  r  )rH  r   r/   r  r   )r   capabilities_to_revoker  r  old_capabilitiesr  rq  s          r%   revokeRole.revoke[  s    " !% 9 90J6&z22 1  /!A. ''* "  !		/	0r$   r   N)r   r   r    r!   r"   r  r  r#   r   r$   r%   r  r  ?  s    0r$   r  c                   6    \ rS rSrSrS rS rS rS rS r	Sr
g	)
r  i{  z{This class represents the collection of roles in the Splunk instance.
Retrieve this collection using :meth:`Service.roles`.c                 >    [         R                  X[        [        S9  g r  )r   r   
PATH_ROLESr  r  s     r%   r   Roles.__init__  r  r$   c                 H    [         R                  XR                  5       5      $ rB   r  rv  s     r%   r|  Roles.__getitem__  r  r$   c                 H    [         R                  XR                  5       5      $ rB   r  r  s     r%   rn  Roles.__contains__  r  r$   c                    [        U[        5      (       d  [        S[        U5       35      eUR                  5       nU R                  " SSU0UD6  U R                  U5      n[        U[        5      R                  n[        U5      nU R                  U R                  [        R                  " UR                  R                  5      US9nU$ )a  Creates a new role.

This function makes two roundtrips to the server, plus at most
two more if
the ``autologin`` field of :func:`connect` is set to ``True``.

:param name: Name for the role.
:type name: ``string``
:param params: Additional arguments (optional). For a list of available
    parameters, see `Roles parameters
    <http://dev.splunk.com/view/SP-CAAAEJ6#rolesparams>`_
    on Splunk Developer Portal.
:type params: ``dict``

:return: The new role.
:rtype: :class:`Role`

**Example**::

    import splunklib.client as client
    c = client.connect(...)
    roles = c.roles
    paltry = roles.create("paltry", imported_roles="user", defaultApp="search")
zInvalid role name: rT   r  r   r  )r   rT   r   r]   r   rg  r  s          r%   r   Roles.create  s    2 $$$23t9+>??zz|		&t&v& 88D>8[177!%(LLMM%++//0   r$   c                 H    [         R                  XR                  5       5      $ )zDeletes the role and returns the resulting collection of roles.

:param name: The name of the role to delete.
:type name: ``string``

:rtype: The :class:`Roles`
r  r  s     r%   r  Roles.delete  s       zz|44r$   r   Nr  r   r$   r%   r  r  {  s"    =B9;&P5r$   r  c                   4    \ rS rSrSr\S 5       rS rS rSr	g)r   i  z*Represents a locally-installed Splunk app.c                 :    U R                   R                  SS5      $ )zLReturns the setup information for the app.

:return: The setup information.
z	eai:setupNr6  r   s    r%   	setupInfoApplication.setupInfo  s     ||T22r$   c                 $    U R                  S5      $ )z6Creates a compressed package of the app for archiving.packager  r   s    r%   r  Application.package  s    	**r$   c                 $    U R                  S5      $ )z=Returns any update information that is available for the app.r  r  r   s    r%   
updateInfoApplication.updateInfo  s    ))r$   r   N)
r   r   r    r!   r"   rA  r  r  r  r#   r   r$   r%   r   r     s!    43 3+*r$   r   c                   .    \ rS rSrS rS r0 0 4S jrSrg)r;  i  c                 6    [         R                  XS[        S9  g )Nzstorage/collections/configr   )r   r   KVStoreCollectionr  s     r%   r   KVStoreCollections.__init__  s    D+GN_`r$   c                     [         R                  X5      nUR                  R                  5        H0  u  p4SU;   d  M  [        R
                  " U5      UR                  U'   M2     U$ )Naccelerated_fields)r   r|  r   rN   rk   rm   )r   r   resrD   rL   s        r%   r|  KVStoreCollections.__getitem__  sO    $$T0KK%%'DA#q(!%AA ( 
r$   c                     UR                  5        H7  u  pV[        U[        5      (       a  [        R                  " U5      nXdSU-   '   M9     UR                  5        H  u  pVXdSU-   '   M     U R
                  " SSU0UD6$ )a  Creates a KV Store Collection.

:param name: name of collection to create
:type name: ``string``
:param accelerated_fields: dictionary of accelerated_fields definitions
:type accelerated_fields: ``dict``
:param fields: dictionary of field definitions
:type fields: ``dict``
:param kwargs: a dictionary of additional parameters specifying indexes and field definitions
:type kwargs: ``dict``

:return: Result of POST request
accelerated_fields.field.rT   r   )rN   re   r  rk   dumpsr   )r   rT   r  r}   r   rD   rL   s          r%   r   KVStoreCollections.create  sx     ',,.DA!T""JJqM01(1,- / LLNDA#$8a<  #yy-d-f--r$   r   N)r   r   r    r!   r   r|  r   r#   r   r$   r%   r;  r;    s    a /1 .r$   r;  c                   0    \ rS rSr\S 5       rS rS rSrg)r  i  c                     [        U 5      $ )zQReturns data object for this Collection.

:rtype: :class:`KVStoreCollectionData`
)KVStoreCollectionDatar   s    r%   r   KVStoreCollection.data  s     %T**r$   c                     0 n[        U[        5      (       a  [        R                  " U5      OUUSU-   '   U R                  " S0 UD6$ )zChanges the definition of a KV Store accelerated_field.

:param name: name of accelerated_fields to change
:type name: ``string``
:param value: new accelerated_fields definition
:type value: ``dict``

:return: Result of POST request
r  r   )re   r  rk   r  r   r   rT   r   r   s       r%   update_accelerated_field*KVStoreCollection.update_accelerated_field  sD     DNuVZD[D[tzz%/@af$t+,yy"6""r$   c                 8    0 nX#SU-   '   U R                   " S0 UD6$ )zChanges the definition of a KV Store field.

:param name: name of field to change
:type name: ``string``
:param value: new field definition
:type value: ``string``

:return: Result of POST request
r  r   r  r  s       r%   update_fieldKVStoreCollection.update_field  s'     "'x$yy"6""r$   r   N)	r   r   r    r!   rA  r   r  r	  r#   r   r$   r%   r  r    s    + +##r$   r  c                   j    \ rS rSrSrS/rS rS rS rS r	S r
S	 rS
 rSS jrS rS rS rS rSrg)r  i  zpThis class represents the data endpoint for a KVStoreCollection.

Retrieve using :meth:`KVStoreCollection.data`
)zContent-Typezapplication/jsonc                     UR                   U l         Xl        UR                  5       u  U l        U l        U l        S[        U R                  R                  SS9-   S-   U l        g )Nzstorage/collections/data/Tr  r   )	rH  
collectionr  r:  rT  rU  r   rT   r   )r   r  s     r%   r   KVStoreCollectionData.__init__  sS    !))$-7-I-I-K*
DHdl/*T__=Q=Q`d2eehkk	r$   c                     U R                   R                  " U R                  U-   4U R                  U R                  U R
                  S.UD6$ r  )rH  rd   r   r:  rT  rU  r   urlr   s      r%   _getKVStoreCollectionData._get$  s=    ||		CptzztxxY]YeYepioppr$   c                     U R                   R                  " U R                  U-   4U R                  U R                  U R
                  S.UD6$ r  )rH  r   r   r:  rT  rU  r  s      r%   _postKVStoreCollectionData._post'  s=    ||  Sq

Z^ZfZfqjpqqr$   c                     U R                   R                  " U R                  U-   4U R                  U R                  U R
                  S.UD6$ r  )rH  r  r   r:  rT  rU  r  s      r%   _deleteKVStoreCollectionData._delete*  s=    ||""499s?s$**$((\`\h\hslrssr$   c                 0   UR                  5        H6  u  p#[        X   [        5      (       d  M  [        R                  " U5      X'   M8     [        R
                  " U R                  " S0 UD6R                  R                  5       R                  S5      5      $ )a  
Gets the results of query, with optional parameters sort, limit, skip, and fields.

:param query: Optional parameters. Valid options are sort, limit, skip, and fields
:type query: ``dict``

:return: Array of documents retrieved by query.
:rtype: ``array``
rW   r'  )
rN   re   r  rk   r  rm   r  rZ   r[   r\   )r   r   rw  r   s       r%   r   KVStoreCollectionData.query-  sl      ++-JC%*d++!ZZ.
 ( zz$))0%055::<CCGLMMr$   c           	          [         R                  " U R                  [        [	        U5      SS95      R
                  R                  5       R                  S5      5      $ )z
Returns object with _id = id.

:param id: Value for ID. If not a string will be coerced to string.
:type id: ``string``

:return: Document with id
:rtype: ``dict``
Tr  rW   )rk   rm   r  r   r  rZ   r[   r\   r   ids     r%   query_by_id!KVStoreCollectionData.query_by_id>  sB     zz$))Js2wT$JKPPUUW^^_fghhr$   c                    [        U[        5      (       a  [        R                  " U5      n[        R                  " U R                  S[        R                  US9R                  R                  5       R                  S5      5      $ )z
Inserts item into this collection. An _id field will be generated if not assigned in the data.

:param data: Document to insert
:type data: ``string``

:return: _id of inserted object
:rtype: ``dict``
r'  ru  rZ   rW   )re   r  rk   r  rm   r  r  JSON_HEADERrZ   r[   r\   )r   r   s     r%   insertKVStoreCollectionData.insertJ  sf     dD!!::d#DzzJJr#8#D#D4JPUUZZ\ccdkln 	nr$   Nc                 @    U R                   " S0 U(       a  SU0D6$ 0 D6$ )z
Deletes all data in collection if query is absent. Otherwise, deletes all data matched by query.

:param query: Query to select documents to delete
:type query: ``string``

:return: Result of DELETE request
r   r  )r  )r   r   s     r%   r  KVStoreCollectionData.deleteY  s%     ||FGU#3FF2FFr$   c                 F    U R                  [        [        U5      SS95      $ )z
Deletes document that has _id = id.

:param id: id of document to delete
:type id: ``string``

:return: Result of DELETE request
Tr  )r  r   r  r  s     r%   delete_by_id"KVStoreCollectionData.delete_by_idd  s     ||Js2wTBCCr$   c           	      .   [        U[        5      (       a  [        R                  " U5      n[        R                  " U R                  [        [        U5      SS9[        R                  US9R                  R                  5       R                  S5      5      $ )z
Replaces document with _id = id with data.

:param id: _id of document to update
:type id: ``string``
:param data: the new document to insert
:type data: ``string``

:return: id of replaced document
:rtype: ``dict``
Tr  r#  rW   )re   r  rk   r  rm   r  r   r  r  r$  rZ   r[   r\   )r   r  r   s      r%   r  KVStoreCollectionData.updateo  sn     dD!!::d#Dzz$**ZBd%KUjUvUv*. % 004TTVFF7OM 	Mr$   c                    [        U5      S:  a  [        S5      e[        R                  " U5      n[        R                  " U R                  S[        R                  US9R                  R                  5       R                  S5      5      $ )z
Returns array of results from queries dbqueries.

:param dbqueries: Array of individual queries as dictionaries
:type dbqueries: ``array`` of ``dict``

:return: Results of each query
:rtype: ``array`` of ``array``
ry   zMust have at least one query.
batch_findr#  rW   r9   r   rk   r  rm   r  r  r$  rZ   r[   r\   )r   	dbqueriesr   s      r%   r/   KVStoreCollectionData.batch_find  sr     y>A;<<zz)$zzJJ|-B-N-NUYJZ__ddfmmnuvx 	xr$   c                    [        U5      S:  a  [        S5      e[        R                  " U5      n[        R                  " U R                  S[        R                  US9R                  R                  5       R                  S5      5      $ )z
Inserts or updates every document specified in documents.

:param documents: Array of documents to save as dictionaries
:type documents: ``array`` of ``dict``

:return: Results of update operation as overall stats
:rtype: ``dict``
ry   z Must have at least one document.
batch_saver#  rW   r0  )r   	documentsr   s      r%   r4   KVStoreCollectionData.batch_save  sr     y>A>??zz)$zzJJ|-B-N-NUYJZ__ddfmmnuvx 	xr$   )rT  r  r:  r   rH  rU  rB   )r   r   r    r!   r"   r$  r   r  r  r  r   r   r%  r  r*  r  r/  r4  r#   r   r$   r%   r  r    sY     88KlqrtN"
in	G	DM"x$xr$   r  rB   )nr"   r  r   rk   loggingrL  r{  r   timer   urllibr   	splunklibr   splunklib.datar   splunklib.bindingr	   r
   r   r   r   r   r   r   	getLoggerr   r  __all__r   r   r  r  PATH_DEPLOYMENT_CLIENTSPATH_DEPLOYMENT_TENANTSPATH_DEPLOYMENT_SERVERSPATH_DEPLOYMENT_SERVERCLASSESr   r   r   r  r\  r[  rL  r  r   r   r  r  PATH_STANZAr  rj  r  rC  XNAMEF_ATOMr  XNAME_CONTENTr   r   r   r   r8   r)   r,   r/   r   r   r?   rP   rU   r_   ri   rp   r   r~   r   r   r   rF  rd  r   r   r  r   r
  r1  r   r   r   r   r   r   r   r   r   r   r   rc  r  r  r  r  r  r>  r  r  r   r;  r  r  r   r$   r%   <module>rF     sq  8B     	  (    !* * * 
		8	$ 	1 	. / .  9 & * 	 ($+ #
' "$
4 4 , /G#i'$Q}oR8 0	 0
1I 1
U* U9 
Ny N<Y <J	 J<EC?&-$P85|	7 	Ql QhxW xWxWX Wt
A6 A6H
w?# w?t	-
 	-I*Z I*XEV E.,f ,6D-z D-NA A8Vj V:oF od@/F @/Lt2Z t2n`& `F	\(: \(~"j ""f #cv #cLX& XvFJ F2<9F <9~NZ N*v ,c6 c"D5J D5N96 9x=5J =5@*& *(. .D## ##LKx Kxr$   