Skip to content

Commit d02c4b8

Browse files
committed
Merge branch 'apruneda/docs' of https://github.com/splunk/splunk-sdk-python into apruneda/docs
2 parents db7fa06 + 4a4e681 commit d02c4b8

File tree

2 files changed

+94
-13
lines changed

2 files changed

+94
-13
lines changed

splunklib/binding.py

Lines changed: 91 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,25 @@ def new_f(*args, **kwargs):
6666

6767
# Custom exceptions
6868
class AuthenticationError(Exception):
69-
""" This exception is raised when login fails. ### FRED: DOC ME ### """
69+
"""Raised when a login request to Splunk fails.
70+
71+
If your username was unknown or you provided an incorrect password
72+
in a call to Context.login() or Service.login(), this exception is
73+
raised.
74+
"""
7075
pass
7176

7277
# Singleton values to eschew None
7378
class NoAuthenticationToken(object):
74-
""" This exception is raised when there is no valid authentication token.
75-
### FRED: DOC ME ### """
79+
"""The value stored in a Context or Service that is not logged in.
80+
81+
If a Context or Service is created without an authentication token,
82+
and there has not yet been a call to the login method, the token
83+
field of the Context or Service is set to ``NoAuthenticationToken``.
84+
85+
Likewise, after a Context or Service has been logged out, the token
86+
is set to this value again.
87+
"""
7688
pass
7789

7890
class UrlEncoded(str):
@@ -921,13 +933,54 @@ def _spliturl(url):
921933

922934
# Given an HTTP request handler, this wrapper objects provides a related
923935
# family of convenience methods built using that handler.
924-
class HttpLib(object):
925-
""" This class ### FRED: DOC ME ### """
936+
class HttpLib(object):
937+
"""A set of convenient methods for making HTTP calls.
938+
939+
HttpLib provides a general ``request`` method, and ``delete``, ``post``,
940+
and ``get`` methods for the three HTTP methods that Splunk uses.
941+
942+
By default, ``HttpLib`` will use Python's built-in ``httplib`` library,
943+
but you can replace it by passing your own handling function to
944+
``HttpLib``'s constructor.
945+
946+
The handling function should have the type::
947+
948+
handler(url, request_dict) -> response_dict
949+
950+
where ``url`` is the URL to make the request to (including any query and
951+
fragment sections), ``request_dict`` is a dictionary with the following keys:
952+
953+
- method: the method for the request, typically ``'GET'``, ``'POST'``, or ``'DELETE'``.
954+
- headers: A list of pairs specifying the HTTP headers (e.g., ``[('key': value), ...]``)
955+
- body: A string giving the body to send with the request (should default to ``''``).
956+
957+
and ``response_dict`` is a dictionary with the following keys:
958+
959+
- status: An integer giving the HTTP status code (e.g., 200, 404).
960+
- reason: The reason phrase, if any, returned by the server
961+
- headers: A list of pairs giving the response headers (e.g., ``[('key': value), ...]``)
962+
- body: A stream-like object supporting ``read(size=None)`` and ``close()``
963+
methods to get the body of the response.
964+
965+
The response dictionary will be returned directly by ``HttpLib``'s methods with
966+
no further processing. By default, ``HttpLib`` calls the function ``handler``
967+
to get a handler function. See it for an example.
968+
"""
926969
def __init__(self, custom_handler=None):
927970
self.handler = handler() if custom_handler is None else custom_handler
928971

929972
def delete(self, url, headers=None, **kwargs):
930-
"""### FRED: DOC ME ###
973+
"""Send a DELETE request to *url*.
974+
975+
*headers* should be a list of pairs specifying the headers for
976+
the HTTP response (e.g., [('Content-Type': 'text/cthulhu'), ('Token': 'boris')]).
977+
978+
Any additional keyword arguments are interpreted as the query
979+
part of the URL. The order of keyword arguments is not preserved
980+
in the request, but the keywords and their arguments will be URL
981+
encoded.
982+
983+
:returns: A dictionary describing the response (see ``HttpLib`` for its structure).
931984
"""
932985
if headers is None: headers = []
933986
if kwargs:
@@ -942,7 +995,17 @@ def delete(self, url, headers=None, **kwargs):
942995
return self.request(url, message)
943996

944997
def get(self, url, headers=None, **kwargs):
945-
"""### FRED: DOC ME ###
998+
"""Issue a GET request to *url*
999+
1000+
*headers* should be a list of pairs specifying the headers for
1001+
the HTTP response (e.g., [('Content-Type': 'text/cthulhu'), ('Token': 'boris')]).
1002+
1003+
Any additional keyword arguments are interpreted as the query
1004+
part of the URL. The order of keyword arguments is not preserved
1005+
in the request, but the keywords and their arguments will be URL
1006+
encoded.
1007+
1008+
:returns: A dictionary describing the response (see ``HttpLib`` for its structure).
9461009
"""
9471010
if headers is None: headers = []
9481011
if kwargs:
@@ -953,7 +1016,19 @@ def get(self, url, headers=None, **kwargs):
9531016
return self.request(url, { 'method': "GET", 'headers': headers })
9541017

9551018
def post(self, url, headers=None, **kwargs):
956-
"""### FRED: DOC ME ###
1019+
"""Issue a POST request to *url*.
1020+
1021+
*headers* should be a list of pairs specifying the headers for
1022+
the HTTP response (e.g., [('Content-Type': 'text/cthulhu'), ('Token': 'boris')]).
1023+
1024+
If ``post`` receives a keyword argument ``body``, it will use
1025+
its value as the body for the request, and encode the rest of the
1026+
keyword arguments into the URL's query as ``get`` or ``delete``
1027+
does. If there is no ``body`` keyword argument, then all the keyword
1028+
arguments are encoded into the body of the request in the
1029+
``x-www-form-urlencoded`` format.
1030+
1031+
:returns: A dictionary describing the response (see ``HttpLib`` for its structure).
9571032
"""
9581033
if headers is None: headers = []
9591034
headers.append(("Content-Type", "application/x-www-form-urlencoded")),
@@ -973,7 +1048,12 @@ def post(self, url, headers=None, **kwargs):
9731048
return self.request(url, message)
9741049

9751050
def request(self, url, message, **kwargs):
976-
"""### FRED: DOC ME ###
1051+
"""Issue an HTTP request to *url*.
1052+
1053+
*message* should be a dictionary of the format understood
1054+
by the HTTP handler (see ``HttpLib`` for a description of
1055+
the format). Any additional keyword arguments are passed
1056+
unchanged to the handler.
9771057
"""
9781058
response = self.handler(url, message, **kwargs)
9791059
response = record(response)
@@ -1040,9 +1120,9 @@ def handler(key_file=None, cert_file=None, timeout=None):
10401120
"""This class returns an instance of the default HTTP request handler using
10411121
the values you provide.
10421122
1043-
:param `key_file`: A path to the key file (optional). ### FRED VERIFY ###
1123+
:param `key_file`: A path to a PEM (Privacy Enhanced Mail) formatted file containing your private key (optional).
10441124
:type key_file: ``string``
1045-
:param `cert_file`: A path to the cert file (optional).
1125+
:param `cert_file`: A path to a PEM (Privacy Enhanced Mail) formatted file containing a certificate chain file (optional).
10461126
:type cert_file: ``string``
10471127
:param `timeout`: The request time-out period, in seconds (optional).
10481128
:type timeout: ``integer`` or "None"

splunklib/results.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,10 @@
5353
]
5454

5555
class Message(object):
56-
"""This class represents Splunk messages that are returned in the XML stream.
56+
"""This class represents informational messages that Splunk interleaves in the results stream.
5757
58-
:param `object`: The object. ### FRED: DOC ME ###
58+
``Message`` takes two arguments: a string giving the message type (e.g., "DEBUG"), and
59+
a string giving the message itself.
5960
6061
**Example**::
6162

0 commit comments

Comments
 (0)