
    Ii                        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  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  SS	KJr  SS
KJr  SSKJrJr  SSKJr  SSKJr  \R8                  " \5      r/ SQr/ SQr Sr!Sr"Sr#S r$S r%S r&S r' " S S5      r( " S S\)5      r*\
S 5       r+S r,\#\!\"4S jr-S-S jr. " S S 5      r/S! r0 " S" S#\15      r2 " S$ S%\25      r3S& r4S' r5 " S( S)5      r6 " S* S+\Rn                  5      r8S.S, jr9g)/a  The **splunklib.binding** module provides a low-level binding interface to the
`Splunk REST API <http://docs.splunk.com/Documentation/Splunk/latest/RESTAPI/RESTcontents>`_.

This module handles the wire details of calling the REST API, such as
authentication tokens, prefix paths, URL encoding, and so on. Actual path
segments, ``GET`` and ``POST`` arguments, and the parsing of responses is left
to the user.

If you want a friendlier interface to the Splunk REST API, use the
:mod:`splunklib.client` module.
    N)	b64encode)contextmanager)datetimewraps)BytesIO)parse)client)SimpleCookie)XML
ParseError)record)__version__)
AuthenticationErrorconnectContexthandler	HTTPError
UrlEncoded_encode_make_cookie_header_NoAuthenticationToken	namespace)AuthorizationCookiezaction.email.auth_passwordauthauth_passwordclear_passwordclientIdzcrc-saltencr_passwordoldpasswordpassAuthpasswordsessionsuppressionKeytoken	localhost8089httpsc                 0   ^  [        T 5      U 4S j5       nU$ )Nc                     > [         R                  " 5       nT" U 0 UD6n[         R                  " 5       n[        R                  SXB-
  5        U$ )NzOperation took %s)r   nowloggerdebug)argskwargs
start_timevalend_timefs        7/venv/lib/python3.13/site-packages/splunklib/binding.pynew_f_log_duration.<locals>.new_fI   s?    \\^
  <<>((*?@
    r   )r4   r6   s   ` r5   _log_durationr9   H   s     
1X  Lr8   c                 .   [        U [        5      (       d   [        R                  " U 5      n [        U [        5      (       d  U $ 0 nU R                  5        H"  u  p4U[        ;   a  SX#'   M  [        U5      X#'   M$     U$ ! [         a  nU s SnA$ SnAff = f)z2
Masked sensitive fields data for logging purpose
Nz******)
isinstancedictjsonloads	ExceptionitemsSENSITIVE_KEYSmask_sensitive_data)dataexmdatakvs        r5   rB   rB   T   s     dD!!	::d#D
 dD!!E

EH*1-EH	 
 L  	K	s   A> >
BB	BBc                 x    [        U 5      nUR                  5        H  nUR                  XR                  '   M     g)a  Tries to parse any key-value pairs of cookies in a string,
then updates the the dictionary with any key-value pairs found.

**Example**::

    dictionary = {}
    _parse_cookies('my=value', dictionary)
    # Now the following is True
    dictionary['my'] == 'value'

:param cookie_str: A string containing "key=value" pairs from an HTTP "Set-Cookie" header.
:type cookie_str: ``str``
:param dictionary: A dictionary to update with any found key-value pairs.
:type dictionary: ``dict``
N)r   valuescoded_valuekey)
cookie_str
dictionaryparsed_cookiecookies       r5   _parse_cookiesrP   j   s3      !,M&&(!'!3!3
:: )r8   c                 2    SR                  S U  5       5      $ )a  
Takes a list of 2-tuples of key-value pairs of
cookies, and returns a valid HTTP ``Cookie``
header.

**Example**::

    header = _make_cookie_header([("key", "value"), ("key_2", "value_2")])
    # Now the following is True
    header == "key=value; key_2=value_2"

:param cookies: A list of 2-tuples of cookie key-value pairs.
:type cookies: ``list`` of 2-tuples
:return: ``str` An HTTP header cookie string.
:rtype: ``str``
z; c              3   4   #    U  H  u  pU S U 3v   M     g7f)=N ).0rK   values      r5   	<genexpr>&_make_cookie_header.<locals>.<genexpr>   s     @*#uAeW%s   )join)cookiess    r5   r   r      s    " 99@@@@r8   c                       \ rS rSrSrSrg)r      a  The value stored in a :class:`Context` or :class:`splunklib.client.Service`
class that is not logged in.

If a ``Context`` or ``Service`` object is created without an authentication
token, and there has not yet been a call to the ``login`` method, the token
field of the ``Context`` or ``Service`` object is set to
``_NoAuthenticationToken``.

Likewise, after a ``Context`` or ``Service`` object has been logged out, the
token is set to this value again.
rT   N)__name__
__module____qualname____firstlineno____doc____static_attributes__rT   r8   r5   r   r      s    
r8   r   c                   :    \ rS rSrSrS
S jrS rS rS rS r	Sr
g	)r      a  This class marks URL-encoded strings.
It should be considered an SDK-private implementation detail.

Manually tracking whether strings are URL encoded can be difficult. Avoid
calling ``urllib.quote`` to replace special characters with escapes. When
you receive a URL-encoded string, *do* use ``urllib.unquote`` to replace
escapes with single characters. Then, wrap any string you want to use as a
URL in ``UrlEncoded``. Note that because the ``UrlEncoded`` class is
idempotent, making multiple calls to it is OK.

``UrlEncoded`` objects are identical to ``str`` objects (including being
equal if their contents are equal) except when passed to ``UrlEncoded``
again.

``UrlEncoded`` removes the ``str`` type support for interpolating values
with ``%`` (doing that raises a ``TypeError``). There is no reliable way to
encode values this way, so instead, interpolate into a string, quoting by
hand, and call ``UrlEncode`` with ``skip_encode=True``.

**Example**::

    import urllib
    UrlEncoded(f'{scheme}://{urllib.quote(host)}', skip_encode=True)

If you append ``str`` strings and ``UrlEncoded`` strings, the result is also
URL encoded.

**Example**::

    UrlEncoded('ab c') + 'de f' == UrlEncoded('ab cde f')
    'ab c' + UrlEncoded('de f') == UrlEncoded('ab cde f')
c                    [        U[        5      (       a  U$ U(       a  [        R                  X5      $ U(       a*  [        R                  U [        R
                  " U5      5      $ [        R                  U [        R                  " U5      5      $ N)r;   r   str__new__r	   
quote_plusquote)selfr2   skip_encodeencode_slashs       r5   rh   UrlEncoded.__new__   sa    c:&&J;;t));;tU%5%5c%:;; {{4S!122r8   c                     [        U[        5      (       a  [        [        R                  X5      SS9$ [        [        R                  U [        R
                  " U5      5      SS9$ )zRself + other

If *other* is not a ``UrlEncoded``, URL encode it before
adding it.
Trl   )r;   r   rg   __add__r	   rj   rk   others     r5   rq   UrlEncoded.__add__   sH     eZ((ckk$6DII#++dEKK,>?TRRr8   c                     [        U[        5      (       a  [        [        R                  X5      SS9$ [        [        R	                  [
        R                  " U5      U 5      SS9$ )zSother + self

If *other* is not a ``UrlEncoded``, URL _encode it before
adding it.
Trp   )r;   r   rg   __radd__rq   r	   rj   rr   s     r5   rv   UrlEncoded.__radd__   sH     eZ((cll47TJJ#++ekk%&8$?TRRr8   c                     [        S5      e)z{Interpolation into ``UrlEncoded``s is disabled.

If you try to write ``UrlEncoded("%s") % "abc", will get a
``TypeError``.
z,Cannot interpolate into a UrlEncoded object.)	TypeError)rk   fieldss     r5   __mod__UrlEncoded.__mod__   s     FGGr8   c                 Z    S[        [        R                  " [        U 5      5      5       S3$ )NzUrlEncoded())reprr	   unquoterg   rk   s    r5   __repr__UrlEncoded.__repr__   s$    T%--D	":;<A>>r8   rT   N) FF)r]   r^   r_   r`   ra   rh   rq   rv   r{   r   rb   rT   r8   r5   r   r      s$    B3	S	SH?r8   r   c              #   r   #     Sv   g! [          a!  nUR                  S:X  a  [        X5      ee SnAff = f7f)a  Handle re-raising HTTP authentication errors as something clearer.

If an ``HTTPError`` is raised with status 401 (access denied) in
the body of this context manager, re-raise it as an
``AuthenticationError`` instead, with *msg* as its message.

This function adds no round trips to the server.

:param msg: The message to be raised in ``AuthenticationError``.
:type msg: ``str``

**Example**::

    with _handle_auth_error("Your login failed."):
         ... # make an HTTP request
N  )r   statusr   )msghes     r5   _handle_auth_errorr      s6     $ 99%c..	s   7	 7
4/47c                 0   ^  [        T 5      U 4S j5       nU$ )a  Decorator to handle autologin and authentication errors.

*request_fun* is a function taking no arguments that needs to
be run with this ``Context`` logged into Splunk.

``_authentication``'s behavior depends on whether the
``autologin`` field of ``Context`` is set to ``True`` or
``False``. If it's ``False``, then ``_authentication``
aborts if the ``Context`` is not logged in, and raises an
``AuthenticationError`` if an ``HTTPError`` of status 401 is
raised in *request_fun*. If it's ``True``, then
``_authentication`` will try at all sensible places to
log in before issuing the request.

If ``autologin`` is ``False``, ``_authentication`` makes
one roundtrip to the server if the ``Context`` is logged in,
or zero if it is not. If ``autologin`` is ``True``, it's less
deterministic, and may make at most three roundtrips (though
that would be a truly pathological case).

:param request_fun: A function of no arguments encapsulating
                    the request to make to the server.

**Example**::

    import splunklib.binding as binding
    c = binding.connect(..., autologin=True)
    c.logout()
    def f():
        c.get("/services")
        return 42
    print(_authentication(f))
c                   > U R                   [        L az  U R                  5       (       de  U R                  (       a3  U R                  (       a"  U R
                  (       a  U R                  5         O![        S5         T" U /UQ70 UD6sS S S 5        $  T" U /UQ70 UD6$ ! , (       d  f       N= f! [         a  nUR                  S:X  a  U R                  (       aq  [        S5         U R                  5         S S S 5        O! , (       d  f       O= f[        S5         T" U /UQ70 UD6sS S S 5        s S nA$ ! , (       d  f        S nAg = fUR                  S:X  a  U R                  (       d  [        SU5      ee S nAff = f)NzRequest aborted: not logged in.r   zAutologin failed.zOAuthentication Failed! If session token is used, it seems to have been expired.z)Request failed: Session is not logged in.)r&   r   has_cookies	autologinusernamer#   loginr   r   r   r   )rk   r/   r0   r   request_funs       r5   wrapper _authentication.<locals>.wrapper1  s"   :://8H8H8J8J~~$--DMM 


 ((IJ&t=d=f= KJ	t5d5f55	 KJ
  	yyCDNN ((;<JJL =<<'(yz&t=d=f= {zzzzc!$..)?E E 	s`   9BB- 
B*-
E<7,E7#C=4	E7=
D	E7D4%	E7.E<4
E	>E71E77E<r   )r   r   s   ` r5   _authenticationr     s$    F ; > Nr8   c                     SU;   a4  UR                  S5      (       a  UR                  S5      (       d  SU-   S-   n[        U  SU SU 3SS9$ )a8  Construct a URL authority from the given *scheme*, *host*, and *port*.

Named in accordance with RFC2396_, which defines URLs as::

    <scheme>://<authority><path>?<query>

.. _RFC2396: http://www.ietf.org/rfc/rfc2396.txt

So ``https://localhost:8000/a/b/b?boris=hilda`` would be parsed as::

    scheme := https
    authority := localhost:8000
    path := /a/b/c
    query := boris=hilda

:param scheme: URL scheme (the default is "https")
:type scheme: "http" or "https"
:param host: The host name (the default is "localhost")
:type host: string
:param port: The port number (the default is 8089)
:type port: integer
:return: The URL authority.
:rtype: UrlEncoded (subclass of ``str``)

**Example**::

    _authority() == "https://localhost:8089"

    _authority(host="splunk.utopia.net") == "https://splunk.utopia.net:8089"

    _authority(host="2001:0db8:85a3:0000:0000:8a2e:0370:7334") ==             "https://[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:8089"

    _authority(scheme="http", host="splunk.utopia.net", port="471") ==             "http://splunk.utopia.net:471"

:[]z://Trp   )
startswithendswithr   )schemehostports      r5   
_authorityr   T  sV    N d{DOOC00T]]35G5G TzCD64&1tDDr8   c                     U S;   a  [        U SSS.5      $ U S;   a  [        U SUS.5      $ U S;   a  [        XUS.5      $ [        S5      e)a  This function constructs a Splunk namespace.

Every Splunk resource belongs to a namespace. The namespace is specified by
the pair of values ``owner`` and ``app`` and is governed by a ``sharing`` mode.
The possible values for ``sharing`` are: "user", "app", "global" and "system",
which map to the following combinations of ``owner`` and ``app`` values:

    "user"   => {owner}, {app}

    "app"    => nobody, {app}

    "global" => nobody, {app}

    "system" => nobody, system

"nobody" is a special user name that basically means no user, and "system"
is the name reserved for system resources.

"-" is a wildcard that can be used for both ``owner`` and ``app`` values and
refers to all users and all apps, respectively.

In general, when you specify a namespace you can specify any combination of
these three values and the library will reconcile the triple, overriding the
provided values as appropriate.

Finally, if no namespacing is specified the library will make use of the
``/services`` branch of the REST API, which provides a namespaced view of
Splunk resources equivelent to using ``owner={currentUser}`` and
``app={defaultApp}``.

The ``namespace`` function returns a representation of the namespace from
reconciling the values you provide. It ignores any keyword arguments other
than ``owner``, ``app``, and ``sharing``, so you can provide ``dicts`` of
configuration information without first having to extract individual keys.

:param sharing: The sharing mode (the default is "user").
:type sharing: "system", "global", "app", or "user"
:param owner: The owner context (the default is "None").
:type owner: ``string``
:param app: The app context (the default is "None").
:type app: ``string``
:returns: A :class:`splunklib.data.Record` containing the reconciled
    namespace.

**Example**::

    import splunklib.binding as binding
    n = binding.namespace(sharing="user", owner="boris", app="search")
    n = binding.namespace(sharing="global", app="search")
)systemnobodyr   )sharingownerapp)globalr   )userNz%Invalid value for argument: 'sharing')r   
ValueError)r   r   r   r0   s       r5   r   r     s^    f *'HXNOO##'HSIJJ. '#FGG
<
==r8   c                       \ rS rSrSrSS jrS rS r\S 5       r	S r
\\SS	 j5       5       r\\SS
 j5       5       r\\SS j5       5       r\\SS0 SSS4S j5       5       rS rS r SS jrSrg)r   i  a  This class represents a context that encapsulates a splunkd connection.

The ``Context`` class encapsulates the details of HTTP requests,
authentication, a default namespace, and URL prefixes to simplify access to
the REST API.

After creating a ``Context`` object, you must call its :meth:`login`
method before you can issue requests to splunkd. Or, use the :func:`connect`
function to create an already-authenticated ``Context`` object. You can
provide a session token explicitly (the same token can be shared by multiple
``Context`` objects) to provide authentication.

: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.
:type verify: ``Boolean``
:param self_signed_certificate: Specifies if self signed certificate is used
:type self_signed_certificate: ``Boolean``
:param sharing: The sharing mode for the namespace (the default is "user").
:type sharing: "global", "system", "app", or "user"
:param owner: The owner context of the namespace (optional, the default is "None").
:type owner: ``string``
:param app: The app context of the namespace (optional, the default is "None").
:type app: ``string``
:param token: A session token. When provided, you don't need to call :meth:`login`.
: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 for the Splunk account.
:type password: ``string``
:param splunkToken: Splunk authentication token
:type splunkToken: ``string``
:param headers: List of extra HTTP headers to send (optional).
:type headers: ``list`` of 2-tuples.
: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 AND BLOCK THE
                CURRENT THREAD WHILE RETRYING.
: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 handler: The HTTP request handler (optional).
:returns: A ``Context`` instance.

**Example**::

    import splunklib.binding as binding
    c = binding.Context(username="boris", password="natasha", ...)
    c.login()
    # Or equivalently
    c = binding.connect(username="boris", password="natasha")
    # Or if you already have a session token
    c = binding.Context(token="atg232342aa34324a")
    # Or if you already have a valid cookie
    c = binding.Context(cookie="splunkd_8089=...")
Nc                 4   [        XR                  SS5      UR                  S5      UR                  S5      UR                  S5      UR                  SS5      UR                  SS	5      S
9U l        UR                  S[        5      U l        U R                  c  [        U l        UR                  S[
        5      U l        UR                  S[        5      U l        [        UR                  S[        5      5      U l        [        U R                  U R                  U R                  5      U l        [        S0 UD6U l        UR                  SS5      U l        UR                  SS5      U l        UR                  SS5      U l        UR                  SS5      U l        UR                  SS5      U l        UR                  S/ 5      U l        UR                  SS5      U l        SU;   a4  US   S [        4;  a$  [-        US   U R                  R.                  5        g g g )NverifyFkey_file	cert_filecontextretriesr   
retryDelay
   )r   r   r   r   r   r&   r   r   r   r   r   r#   basicsplunkTokenr   headersself_signed_certificateTrO   rT   )HttpLibgethttpr   r&   DEFAULT_SCHEMEr   DEFAULT_HOSTr   intDEFAULT_PORTr   r   	authorityr   r   r#   r   bearerTokenr   additional_headers_self_signed_certificaterP   _cookies)rk   r   r0   s      r5   __init__Context.__init__   s   GZZ%%@6::V`Ka&,jj&=vzzR[G\$*JJy!$<T`bdIeg	 ZZ)?@
::/DJjj>:JJv|4	

6<89	#DKKDIIF",V,

:r2

:r2ZZ/
!::mR8K7"(**Y";(.

3Ld(S% v&"24AW:X"X6(+TYY-?-?@ #Yr8   c                 .    U R                   R                  $ )zGets the dictionary of cookies from the ``HttpLib`` member of this instance.

:return: Dictionary of cookies stored on the ``self.http``.
:rtype: ``dict``
)r   r   r   s    r5   get_cookiesContext.get_cookies  s     yy!!!r8   c                 j   ^ Sm[        U4S jU R                  5       R                  5        5       5      $ )zReturns true if the ``HttpLib`` member of this instance has auth token stored.

:return: ``True`` if there is auth token present, else ``False``
:rtype: ``bool``
splunkd_c              3   .   >#    U  H
  nTU;   v   M     g 7frf   rT   )rU   rK   auth_token_keys     r5   rW   &Context.has_cookies.<locals>.<genexpr>(  s     N4MS>S(4Ms   )anyr   keys)rk   r   s    @r5   r   Context.has_cookies!  s-     $ND4D4D4F4K4K4MNNNr8   c           	      V   / nU R                  5       (       a3  S[        [        U R                  5       R	                  5       5      5      4/$ U R
                  (       aj  U R                  (       aY  U R                  (       aH  S[        U R                  < SU R                  < 3R                  S5      5      R                  S5       3nOsU R                  (       a  SU R                   3nORU R                  [        L a  / nO<U R                  R                  S5      (       a  U R                  nOSU R                   3nU(       a  UR                  SU45        U R                  5       (       aA  UR                  S[        [        U R                  5       R	                  5       5      5      45        U$ )	zHeaders required to authenticate a request.

Assumes your ``Context`` already has a authentication token or
cookie, either provided explicitly or obtained by logging
into the Splunk instance.

:returns: A list of 2-tuples containing key and value
r   zBasic r   utf-8asciizBearer Splunk r   )r   r   listr   r@   r   r   r#   r   encodedecoder   r&   r   r   append)rk   headerr&   s      r5   _auth_headersContext._auth_headers+  sA    248H8H8J8P8P8R3STUVVZZT]]t}}Y4==$--(P'X'XY`'abiijqrstEd../0EZZ11E zz$$Y//

!$**.MM?E23MM8%8d>N>N>P>V>V>X9Y%Z[\r8   c                 ^   [         R                   " [         R                  [         R                  5      nU R                  S:X  a  [        R
                  " 5       nU=R                  [        R                  [        R                  -  -  sl        U R                  (       + Ul
        U R                  (       a  [        R                  O[        R                  Ul        UR                  XR                  S9nUR!                  [         R"                  " U R                  5      U R$                  45        U$ )a  Returns an open connection (socket) to the Splunk instance.

This method is used for writing bulk events to an index or similar tasks
where the overhead of opening a connection multiple times would be
prohibitive.

:returns: A socket.

**Example**::

    import splunklib.binding as binding
    c = binding.connect(...)
    socket = c.connect()
    socket.write("POST %s HTTP/1.1\r\n" % "some/path/to/post/to")
    socket.write("Host: %s:%s\r\n" % (c.host, c.port))
    socket.write("Accept-Encoding: identity\r\n")
    socket.write("Authorization: %s\r\n" % c.token)
    socket.write("X-Splunk-Input-Mode: Streaming\r\n")
    socket.write("\r\n")
r)   )server_hostname)socketAF_INETSOCK_STREAMr   sslcreate_default_contextoptionsOP_NO_TLSv1OP_NO_TLSv1_1r   check_hostname	CERT_NONECERT_REQUIREDverify_modewrap_socketr   r   gethostbynamer   )rk   sockr   s      r5   r   Context.connectK  s    * }}V^^V-?-?@;;'!002GOOs1B1BBBO)-)F)F%FG"373P3P#--VYVgVgG&&tYY&GDf**4995tyyABr8   c                     U R                   U R                  XX4S9-   n[        R                  SU[	        U5      5        U R
                  R                  " X`R                  40 UD6nU$ )a  Performs a DELETE operation at the REST path segment with the given
namespace and query.

This method is named to match the HTTP method. ``delete`` makes at least
one round trip to the server, one additional round trip for each 303
status returned, and 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 uses the
default :class:`Context` namespace. All other keyword arguments are
included in the URL as query parameters.

:raises AuthenticationError: Raised when the ``Context`` object is not
     logged in.
:raises HTTPError: Raised when an error occurred in a GET operation from
     *path_segment*.
:param path_segment: A REST path segment.
: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**::

    c = binding.connect(...)
    c.delete('saved/searches/boris') == \
        {'body': ...a response reader object...,
         'headers': [('content-length', '1786'),
                     ('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:53:06 GMT'),
                     ('content-type', 'text/xml; charset=utf-8')],
         'reason': 'OK',
         'status': 200}
    c.delete('nonexistant/path') # raises HTTPError
    c.logout()
    c.delete('apps/local') # raises AuthenticationError
r   r   r   zDELETE request to %s (body: %s))r   _abspathr-   r.   rB   r   deleter   )rk   path_segmentr   r   r   querypathresponses           r5   r   Context.deletej  sf    h ~~l25 !. !H H6>QRW>XY99##D*<*<FFr8   c                     Uc  / nU R                   U R                  XX5S9-   n[        R                  SU[	        U5      5        X@R
                  -   U R                  -   nU R                  R                  " Xx40 UD6n	U	$ )a"  Performs a GET operation from the REST path segment with the given
namespace and query.

This method is named to match the HTTP method. ``get`` makes at least
one round trip to the server, one additional round trip for each 303
status returned, and 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 uses the
default :class:`Context` namespace. All other keyword arguments are
included in the URL as query parameters.

:raises AuthenticationError: Raised when the ``Context`` object is not
     logged in.
:raises HTTPError: Raised when an error occurred in a GET operation from
     *path_segment*.
:param path_segment: A REST path segment.
: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 headers: List of extra HTTP headers to send (optional).
:type headers: ``list`` of 2-tuples.
: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**::

    c = binding.connect(...)
    c.get('apps/local') == \
        {'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}
    c.get('nonexistant/path') # raises HTTPError
    c.logout()
    c.get('apps/local') # raises AuthenticationError
r   zGET request to %s (body: %s))	r   r   r-   r.   rB   r   r   r   r   )
rk   r   r   r   r   r   r   r   all_headersr   s
             r5   r   Context.get  s    l ?G~~l25 !. !H H3T;Nu;UV 7 77$:L:LL99==<e<r8   c                     Uc  / nU R                   U R                  XX4S9-   n[        R                  SU[	        U5      5        XPR
                  -   U R                  -   nU R                  R                  " Xx40 UD6n	U	$ )aK  Performs a POST operation from the REST path segment with the given
namespace and query.

This method is named to match the HTTP method. ``post`` makes at least
one round trip to the server, one additional round trip for each 303
status returned, and 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 uses the
default :class:`Context` namespace. All other keyword arguments are
included in the URL as query parameters.

Some of Splunk's endpoints, such as ``receivers/simple`` and
``receivers/stream``, require unstructured data in the POST body
and all metadata passed as GET-style arguments. If you provide
a ``body`` argument to ``post``, it will be used as the POST
body, and all other keyword arguments will be passed as
GET-style arguments in the URL.

:raises AuthenticationError: Raised when the ``Context`` object is not
     logged in.
:raises HTTPError: Raised when an error occurred in a GET operation from
     *path_segment*.
:param path_segment: A REST path segment.
: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 headers: List of extra HTTP headers to send (optional).
:type headers: ``list`` of 2-tuples.
:param query: All other keyword arguments, which are used as query
    parameters.
:param body: Parameters to be used in the post body. If specified,
    any parameters in the query will be applied to the URL instead of
    the body. If a dict is supplied, the key-value pairs will be form
    encoded. If a string is supplied, the body will be passed through
    in the request unchanged.
:type body: ``dict`` or ``str``
:return: The response from the server.
:rtype: ``dict`` with keys ``body``, ``headers``, ``reason``,
        and ``status``

**Example**::

    c = binding.connect(...)
    c.post('saved/searches', name='boris',
           search='search * earliest=-1m | head 1') == \
        {'body': ...a response reader object...,
         'headers': [('content-length', '10455'),
                     ('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:46:06 GMT'),
                     ('content-type', 'text/xml; charset=utf-8')],
         'reason': 'Created',
         'status': 201}
    c.post('nonexistant/path') # raises HTTPError
    c.logout()
    # raises AuthenticationError:
    c.post('saved/searches', name='boris',
           search='search * earliest=-1m | head 1')
r   zPOST request to %s (body: %s))	r   r   r-   r.   rB   r   r   r   post)
rk   r   r   r   r   r   r   r   r   r   s
             r5   r   Context.post  sw    J ?G~~lS bb4d<OPU<VW 7 77$:L:LL99>>$=u=r8   GETc                    Uc  / nU R                   U R                  XXgS9-   nX0R                  -   U R                  -   n	[        R                  SX([        [        [        U	5      5      5      [        U5      5        U(       a.  [        S	0 UD6nUS:X  a  U[        SU-   SS9-   nUU	S.n
OUU	US.n
OUU	S.n
U R                  R                  X5      nU$ )
a  Issues an arbitrary HTTP request to the REST path segment.

This method is named to match ``httplib.request``. This function
makes a single round trip to the server.

If *owner*, *app*, and *sharing* are omitted, this method uses the
default :class:`Context` namespace. All other keyword arguments are
included in the URL as query parameters.

:raises AuthenticationError: Raised when the ``Context`` object is not
     logged in.
:raises HTTPError: Raised when an error occurred in a GET operation from
     *path_segment*.
:param path_segment: A REST path segment.
:type path_segment: ``string``
:param method: The HTTP method to use (optional).
:type method: ``string``
:param headers: List of extra HTTP headers to send (optional).
:type headers: ``list`` of 2-tuples.
:param body: Content of the HTTP request (optional).
:type body: ``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``
:return: The response from the server.
:rtype: ``dict`` with keys ``body``, ``headers``, ``reason``,
        and ``status``

**Example**::

    c = binding.connect(...)
    c.request('saved/searches', method='GET') == \
        {'body': ...a response reader object...,
         'headers': [('content-length', '46722'),
                     ('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 17:24:19 GMT'),
                     ('content-type', 'text/xml; charset=utf-8')],
         'reason': 'OK',
         'status': 200}
    c.request('nonexistant/path', method='GET') # raises HTTPError
    c.logout()
    c.get('apps/local') # raises AuthenticationError
r   z(%s request to %s (headers: %s, body: %s)r   ?Trp   methodr   r   r   bodyrT   )r   r   r   r   r-   r.   rg   rB   r<   r   r   r   request)rk   r   r   r   r   r   r   r   r   r   messager   s               r5   r  Context.request3  s    j ?G~~|#&  99  7 77$:L:LL?3':4;L'M#NPcdhPi	k?T?DjtFF%+&13 &,&1#') "("-/G 99$$T3r8   c                    U R                  5       (       a#  U R                  (       d  U R                  (       d  gU R                  [        La#  U R                  (       d  U R                  (       d  gU R
                  (       a#  U R                  (       a  U R                  (       a  gU R                  (       a  g U R                  R                  U R                  U R                  S5      -   U R                  U R                  U R                  SS9nUR                  R                  5       n[        U5      R                  S5      nSU 3U l        U $ ! [          a"  nUR"                  S:X  a  [%        SU5      ee SnAff = f)	ak  Logs into the Splunk instance referred to by the :class:`Context`
object.

Unless a ``Context`` is created with an explicit authentication token
(probably obtained by logging in from a different ``Context`` object)
you must call :meth:`login` before you can issue requests.
The authentication token obtained from the server is stored in the
``token`` field of the ``Context`` object.

:raises AuthenticationError: Raised when login fails.
:returns: The ``Context`` object, so you can chain calls.

**Example**::

    import splunklib.binding as binding
    c = binding.Context(...).login()
    # Then issue requests...
Nz/services/auth/login1)r   r#   r   rO   z./sessionKeyr   r   zLogin failed.)r   r   r#   r&   r   r   r   r   r   r   r   r   r   readr   findtextr   r   r   )rk   r   r   r$   r   s        r5   r   Context.login  s   ( t}} ::33t}} ::4==T]]  	yy~~/E!FF// & H ==%%'D$i((8G"7),DJK 	yyC)/2>>		s   6BE 
E9E44E9c                 >    [         U l        0 U R                  l        U $ )z/Forgets the current session token, and cookies.)r   r&   r   r   r   s    r5   logoutContext.logout  s    +
		r8   c                    [        U[        5      nUR                  S5      (       a	  [        XS9$ U(       d  U(       d  U(       a  [        X#US9nOU R                  nUR                  c  UR
                  c  [        SU 3US9$ UR
                  c  SOUR
                  nUR                  c  SOUR                  n[        SU SU SU 3US9n	U	$ )a  Qualifies *path_segment* into an absolute path for a URL.

If *path_segment* is already absolute, returns it unchanged.
If *path_segment* is relative, then qualifies it with either
the provided namespace arguments or the ``Context``'s default
namespace. Any forbidden characters in *path_segment* are URL
encoded. This function has no network activity.

Named to be consistent with RFC2396_.

.. _RFC2396: http://www.ietf.org/rfc/rfc2396.txt

:param path_segment: A relative or absolute URL path segment.
:type path_segment: ``string``
:param owner, app, sharing: Components of a namespace (defaults
                            to the ``Context``'s namespace if all
                            three are omitted)
:type owner, app, sharing: ``string``
:return: A ``UrlEncoded`` (a subclass of ``str``).
:rtype: ``string``

**Example**::

    import splunklib.binding as binding
    c = binding.connect(owner='boris', app='search', sharing='user')
    c._abspath('/a/b/c') == '/a/b/c'
    c._abspath('/a/b c/d') == '/a/b%20c/d'
    c._abspath('apps/local/search') ==                 '/servicesNS/boris/search/apps/local/search'
    c._abspath('apps/local/search', sharing='system') ==                 '/servicesNS/nobody/system/apps/local/search'
    url = c.authority + c._abspath('apps/local/sharing')
/rp   r   z
/services/r   r   z/servicesNS/)r;   r   r   r   r   r   )
rk   r   r   r   r   rl   nsonameanamer   s
             r5   r   Context._abspath  s    F !z: ""3''lDD C7ABB 66>bhh.
<.9{SSHH,"((FFNLqqGU`ar8   )r   r   r   r   r   r   r   r   r   r#   r   r   r&   r   rf   NNN)NNNN)r]   r^   r_   r`   ra   r   r   r   propertyr   r   r   r9   r   r   r   r  r   r
  r   rb   rT   r8   r5   r   r     s    >@A2"O  >> 6  6p <  <| K  KZ +0$RdN  N`<| 04:r8   r   c                  <    [        S0 U D6nUR                  5         U$ )a  This function returns an authenticated :class:`Context` object.

This function is a shorthand for calling :meth:`Context.login`.

This function makes one round trip to the server.

: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 owner: The owner context of the namespace (the default is "None").
:type owner: ``string``
:param app: The app context of the namespace (the default is "None").
: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 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 headers: List of extra HTTP headers to send (optional).
:type headers: ``list`` of 2-tuples.
:param autologin: When ``True``, automatically tries to log in again if the
    session terminates.
:type autologin: ``Boolean``
:return: An initialized :class:`Context` instance.

**Example**::

    import splunklib.binding as binding
    c = binding.connect(...)
    response = c.get("apps/local")
rT   )r   r   )r0   cs     r5   r   r     s     V 	&AGGIHr8   c                   "    \ rS rSrSrSS jrSrg)r   i9  zAThis exception is raised for HTTP responses that return an error.Nc                 x   UR                   nUR                  nUR                  R                  5       n [	        U5      R                  S5      nUc  SOSU 3nSU SU U 3n[        R                  X=(       d    U5        X0l         X@l        UR                  U l	        XPl        Xl
        g ! [         a    Un Njf = f)Nz./messages/msgr   z -- zHTTP  )r   reasonr   r  r   r  r   r?   r   r   	_response)	rk   r   _messager   r  r   detaildetail_formattedr  s	            r5   r   HTTPError.__init__<  s    }}!!#	Y''(89F "(2tF8_&6(+;*<=4!4W5''	!  	F	s   B* *B98B9)r  r   r   r  r   rf   r]   r^   r_   r`   ra   r   rb   rT   r8   r5   r   r   9  s
    K"r8   r   c                       \ rS rSrSrS rSrg)r   iN  zRaised when a login request to Splunk fails.

If your username was unknown or you provided an incorrect password
in a call to :meth:`Context.login` or :meth:`splunklib.client.Service.login`,
this exception is raised.
c                     [        UR                  5      UR                  l        [        R	                  XR                  U5        g rf   )r   r   r  r   r   )rk   r  causes      r5   r   AuthenticationError.__init__V  s-      'uzz24':r8   rT   Nr  rT   r8   r5   r   r   N  s    ;r8   r   c                     / nU R                  5        HQ  u  p#[        U[        5      (       a%  UR                  U Vs/ s H  oBU4PM     sn5        M?  UR	                  X#45        MS     [
        R                  " U5      $ s  snf rf   )r@   r;   r   extendr   r	   	urlencode)r0   r@   rK   rV   items        r5   r   r   w  sg    Elln
eT""LL%8%$+%89LL#&	 %
 ??5!! 9s   A>
c                 x   [         R                  " U 5      nUR                  nUR                  nUR                  (       a'  SR                  UR                  UR                  45      OUR                  nUR                  S5      (       a  UR                  S5      (       a  USS nUc  [        nUR                  X#U4$ )Nr   r   r      )r	   urlparsehostnamer   r   rY   r   r   r   r   r   )url
parsed_urlr   r   r   s        r5   	_spliturlr/    s    $JD??D<F<L<L388Z__j&6&678R\RaRaDsc 2 24":D|LTd$..r8   c                   J    \ rS rSrSr  S
S jrSS jrSS jrSS jrS r	S	r
g)r   i  aZ  A set of convenient methods for making HTTP calls.

``HttpLib`` provides a general :meth:`request` method, and :meth:`delete`,
:meth:`post`, and :meth:`get` methods for the three HTTP methods that Splunk
uses.

By default, ``HttpLib`` uses Python's built-in ``httplib`` library,
but you can replace it by passing your own handling function to the
constructor for ``HttpLib``.

The handling function should have the type:

    ``handler(`url`, `request_dict`) -> response_dict``

where `url` is the URL to make the request to (including any query and
fragment sections) as a dictionary with the following keys:

    - method: The method for the request, typically ``GET``, ``POST``, or ``DELETE``.

    - headers: A list of pairs specifying the HTTP headers (for example: ``[('key': value), ...]``).

    - body: A string containing the body to send with the request (this string
      should default to '').

and ``response_dict`` is a dictionary with the following keys:

    - status: An integer containing the HTTP status code (such as 200 or 404).

    - reason: The reason phrase, if any, returned by the server.

    - headers: A list of pairs containing the response headers (for example, ``[('key': value), ...]``).

    - body: A stream-like object supporting ``read(size=None)`` and ``close()``
      methods to get the body of the response.

The response dictionary is returned directly by ``HttpLib``'s methods with
no further processing. By default, ``HttpLib`` calls the :func:`handler` function
to get a handler function.

If using the default handler, SSL verification can be disabled by passing verify=False.
Nc                 \    Uc  [        X#XES9U l         OXl         0 U l        X`l        Xpl        g )N)r   r   r   r   )r   r   r   r   )rk   custom_handlerr   r   r   r   r   r   s           r5   r   HttpLib.__init__  s,    !"&yjDL)L$r8   c           	      x    Uc  / nU(       a  U[        S[        S0 UD6-   SS9-   nSUS.nU R                  X5      $ )a  Sends a DELETE request to a URL.

:param url: The URL.
:type url: ``string``
:param headers: A list of pairs specifying the headers for the HTTP
    response (for example, ``[('Content-Type': 'text/cthulhu'), ('Token': 'boris')]``).
:type headers: ``list``
:param kwargs: Additional keyword arguments (optional). These arguments
    are interpreted as the query part of the URL. The order of keyword
    arguments is not preserved in the request, but the keywords and
    their arguments will be URL encoded.
:type kwargs: ``dict``
:returns: A dictionary describing the response (see :class:`HttpLib` for
    its structure).
:rtype: ``dict``
r   Trp   DELETEr   rT   r   r   r  )rk   r-  r   r0   r  s        r5   r   HttpLib.delete  sN    " ?bG 
3):6):#:MMC
 ||C))r8   c           	      v    Uc  / nU(       a  U[        S[        S0 UD6-   SS9-   nU R                  USUS.5      $ )a  Sends a GET request to a URL.

:param url: The URL.
:type url: ``string``
:param headers: A list of pairs specifying the headers for the HTTP
    response (for example, ``[('Content-Type': 'text/cthulhu'), ('Token': 'boris')]``).
:type headers: ``list``
:param kwargs: Additional keyword arguments (optional). These arguments
    are interpreted as the query part of the URL. The order of keyword
    arguments is not preserved in the request, but the keywords and
    their arguments will be URL encoded.
:type kwargs: ``dict``
:returns: A dictionary describing the response (see :class:`HttpLib` for
    its structure).
:rtype: ``dict``
r   Trp   r   r   rT   r6  )rk   r-  r   r0   s       r5   r   HttpLib.get  sF    " ?bG 
3):6):#:MMC||CEg!FGGr8   c           	         Uc  / nSU;   a  [        U Vs/ s H  oDS   R                  5       S:X  d  M  UPM     sn5      S:X  a  UR                  S5        UR                  S5      n[	        U[
        5      (       a  [        S0 UD6R                  S5      n[        U5      S:  a  U[        S[        S0 UD6-   SS9-   nO[        S0 UD6R                  S5      nS	UUS
.nU R                  X5      $ s  snf )a  Sends a POST request to a URL.

:param url: The URL.
:type url: ``string``
:param headers: A list of pairs specifying the headers for the HTTP
    response (for example, ``[('Content-Type': 'text/cthulhu'), ('Token': 'boris')]``).
:type headers: ``list``
:param kwargs: Additional keyword arguments (optional). If the argument
    is ``body``, the value is used as the body for the request, and the
    keywords and their arguments will be URL encoded. If there is no
    ``body`` keyword argument, all the keyword arguments are encoded
    into the body of the request in the format ``x-www-form-urlencoded``.
:type kwargs: ``dict``
:returns: A dictionary describing the response (see :class:`HttpLib` for
    its structure).
:rtype: ``dict``
r   r   zcontent-type)zContent-Typez!application/x-www-form-urlencodedr   r   Trp   POSTr   rT   )
lenlowerr   popr;   r<   r   r   r   r  )rk   r-  r   r0   xr   r  s          r5   r   HttpLib.post  s    $ ?bG V wIw!A$**,.*HAwIJaOTU::f%D$%%--g66{QJsW->v->'>DQQ$V$++G4D

 ||C)) Js
   C/C/c                 8     U R                   " X40 UD6n [        U5      nSUR                  ::  a  [        U5      eUR                  n[        UR                  [        5      (       a#  [        UR                  R                  5       5      nU H0  u  pgUR                  5       S:X  d  M  [        XpR                   5        M2     U$ ! [         aI    U R                  S::  a  e [        R                  " U R
                  5        U =R                  S-  sl         Of = fGM  )a  Issues an HTTP request to a URL.

:param url: The URL.
:type url: ``string``
:param message: A dictionary with the format as described in
    :class:`HttpLib`.
:type message: ``dict``
:param kwargs: Additional keyword arguments (optional). These arguments
    are passed unchanged to the handler.
:type kwargs: ``dict``
:returns: A dictionary describing the response (see :class:`HttpLib` for
    its structure).
:rtype: ``dict``
r   r)  i  z
set-cookie)r   r?   r   timesleepr   r   r   r   r   r;   r<   r   r@   r=  rP   r   )rk   r-  r  r0   r   key_value_tuplesrK   rV   s           r5   r  HttpLib.request%  s     &<<?? (#(//!H%% $++ h&&--#H$4$4$:$:$<=*JCyy{l*umm4 + +  &<<1$JJt/LLA%L&	 s   C ADD)r   r   r   r   )NFNNNr   r   rf   )r]   r^   r_   r`   ra   r   r   r   r   r  rb   rT   r8   r5   r   r     s-    (T pq%*:H2)*V(r8   r   c                   Z    \ rS rSrSrSS jrS r\S 5       rS r	S r
SS	 jrS
 rS rSrg)ResponseReaderiQ  a  This class provides a file-like interface for :class:`httplib` responses.

The ``ResponseReader`` class is intended to be a layer to unify the different
types of HTTP libraries used with this SDK. This class also provides a
preview of the stream and a few useful predicates.
Nc                 *    Xl         X l        SU l        g )Nr8   )r  _connection_buffer)rk   r   
connections      r5   r   ResponseReader.__init__\  s    !%r8   c                 6    [        U R                  5       S5      $ )NzUTF-8)rg   r  r   s    r5   __str__ResponseReader.__str__a  s    499;((r8   c                 *    U R                  S5      S:H  $ )z9Indicates whether there is any more data in the response.r)  r8   )peekr   s    r5   emptyResponseReader.emptyd  s     yy|s""r8   c                 P    U R                  U5      nU R                  U-   U l        U$ )zNondestructively retrieves a given number of characters.

The next :meth:`read` operation behaves as though this method was never
called.

:param size: The number of characters to retrieve.
:type size: ``integer``
)r  rJ  )rk   sizer  s      r5   rQ  ResponseReader.peeki  s&     IIdO||a'r8   c                     U R                   (       a  U R                   R                  5         U R                  R                  5         g)zCloses this response.N)rI  closer  r   s    r5   rX  ResponseReader.closev  s-    ""$r8   c                     U R                   nSU l         Ub  U[        U5      -  nX R                  R                  U5      -   nU$ )zReads a given number of characters from the response.

:param size: The number of characters to read, or "None" to read the
    entire response.
:type size: ``integer`` or "None"

r8   )rJ  r<  r  r  )rk   rU  rs      r5   r  ResponseReader.read|  sC     LLCFND##D))r8   c                     g)z/Indicates that the response reader is readable.TrT   r   s    r5   readableResponseReader.readable  s    r8   c                 \    [        U5      nU R                  U5      n[        U5      nX1SU& U$ )zRead data into a byte array, upto the size of the byte array.

:param byte_array: A byte array/memory view to pour bytes into.
:type byte_array: ``bytearray`` or ``memoryview``

N)r<  r  )rk   
byte_arraymax_sizerC   
bytes_reads        r5   readintoResponseReader.readinto  s4     z?yy"Y
"&;Jr8   )rJ  rI  r  rf   )r]   r^   r_   r`   ra   r   rN  r  rR  rQ  rX  r  r^  rd  rb   rT   r8   r5   rG  rG  Q  s>    
) # #r8   rG  c                 4   ^ ^^^^^ UUU UU4S jmUU4S jnU$ )a  This class returns an instance of the default HTTP request handler using
the values you provide.

:param `key_file`: A path to a PEM (Privacy Enhanced Mail) formatted file containing your private key (optional).
:type key_file: ``string``
:param `cert_file`: A path to a PEM (Privacy Enhanced Mail) formatted file containing a certificate chain file (optional).
:type cert_file: ``string``
:param `timeout`: The request time-out period, in seconds (optional).
:type timeout: ``integer`` or "None"
:param `verify`: Set to False to disable SSL verification on https connections.
:type verify: ``Boolean``
:param `context`: The SSLContext that can is used with the HTTPSConnection when verify=True is enabled and context is specified
:type context: ``SSLContext`
c                    > 0 nTb  TUS'   U S:X  a  [         R                  " X40 UD6$ U S:X  aS  Tb  TUS'   Tb  TUS'   T(       d  [        R                  " 5       US'   OT(       a  TUS'   [         R                  " X40 UD6$ [        SU  35      e)Ntimeoutr   r)   r   r   r   zunsupported scheme: )r
   HTTPConnectionr   _create_unverified_contextHTTPSConnectionr   )	r   r   r   r0   r   r   r   rh  r   s	       r5   r   handler.<locals>.connect  s    Gy 1V((>v>>W#(VJ%7$If[&9$'$B$B$Dy!$+y!))$???/x899r8   c                   > [        U 5      u  p4pVUR                  SS5      n[        [        U5      5      US[        -  SSS.nUS    H	  u  pXU	'   M     UR                  SS	5      nT" X4U5      nS
n UR                  XXx5        Tb  UR                  R                  T5        UR                  5       nSUR                  SSS9R                  5       ;   nU(       d  UR                  5         UR                  UR                  UR                  5       [        X(       a  U5      S.$ S 5      S.$ ! U(       d  UR                  5         f f = f)Nr   r   zsplunk-sdk-python/%sz*/*Close)zContent-LengthHostz
User-AgentAccept
Connectionr   r   r   Fz
keep-aliverK  rX  )default)r   r  r   r   )r/  r   rg   r<  r   r  r   
settimeoutgetresponse	getheaderr=  rX  r   r  
getheadersrG  )r-  r  r0   r   r   r   r   r   headrK   rV   r   rK  is_keepaliver   r   rh  s                  r5   r  handler.<locals>.request  sK   #,S> d{{62&!#d)n0;>!
 "),JCI -Xu-V40
	#vT8"**73!--/H'8+=+=lT[+=+\+b+b+ddL  " oooo**,"8<ZR	
 	
 NRR	
 	
    "  s   3A!D, ,ErT   )r   r   rh  r   r   r  r   s   ````` @r5   r   r     s     : :$
B Nr8   r  )NNNFN):ra   ior=   loggingr   r   rB  base64r   
contextlibr   r   	functoolsr   r   urllibr	   r   r
   http.cookiesr   xml.etree.ElementTreer   r   splunklib.datar   	splunklibr   	getLoggerr]   r-   __all__rA   r   r   r   r9   rB   rP   r   r   rg   r   r   r   r   r   r   r   r?   r   r   r   r/  r   	RawIOBaserG  r   rT   r8   r5   <module>r     s+  
 
    
   %      % 1 ! ! 
		8	$ 	,4*A* N? N?b  4CL %<l +E^9>xD	 D	N-f"	 "*;) ;R"/~ ~DIR\\ IXCr8   