Skip to content

Commit c651780

Browse files
author
Frederick Ross
committed
Merge branch 'apruneda/docs' into develop
Conflicts: splunklib/client.py
2 parents b4ba2bf + 4c94136 commit c651780

File tree

2 files changed

+98
-72
lines changed

2 files changed

+98
-72
lines changed

splunklib/binding.py

Lines changed: 96 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,23 @@ class AuthenticationError(Exception):
6969
"""Raised when a login request to Splunk fails.
7070
7171
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.
72+
in a call to :meth:`Context.login` or :meth:`splunklib.client.Service.login`,
73+
this exception is raised.
7474
"""
7575
pass
7676

7777
# Singleton values to eschew None
7878
class NoAuthenticationToken(object):
79-
"""The value stored in a Context or Service that is not logged in.
79+
"""The value stored in a :class:`Context` or :class:`splunklib.client.Service`
80+
class that is not logged in.
8081
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``.
82+
If a ``Context`` or ``Service`` object is created without an authentication
83+
token, and there has not yet been a call to the ``login`` method, the token
84+
field of the ``Context`` or ``Service`` object is set to
85+
``NoAuthenticationToken``.
8486
85-
Likewise, after a Context or Service has been logged out, the token
86-
is set to this value again.
87+
Likewise, after a ``Context`` or ``Service`` object has been logged out, the
88+
token is set to this value again.
8789
"""
8890
pass
8991

@@ -936,51 +938,62 @@ def _spliturl(url):
936938
class HttpLib(object):
937939
"""A set of convenient methods for making HTTP calls.
938940
939-
HttpLib provides a general ``request`` method, and ``delete``, ``post``,
940-
and ``get`` methods for the three HTTP methods that Splunk uses.
941+
``HttpLib`` provides a general :meth:`request` method, and :meth:`delete`,
942+
:meth:`post`, and :meth:`get` methods for the three HTTP methods that Splunk
943+
uses.
941944
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+
By default, ``HttpLib`` uses Python's built-in ``httplib`` library,
946+
but you can replace it by passing your own handling function to the
947+
constructor for ``HttpLib``.
945948
946-
The handling function should have the type::
949+
The handling function should have the type:
947950
948-
handler(url, request_dict) -> response_dict
951+
``handler(`url`, `request_dict`) -> response_dict``
949952
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:
953+
where `url` is the URL to make the request to (including any query and
954+
fragment sections) as a dictionary with the following keys:
952955
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+
- method: The method for the request, typically ``GET``, ``POST``, or ``DELETE``.
957+
958+
- headers: A list of pairs specifying the HTTP headers (for example: ``[('key': value), ...]``).
959+
960+
- body: A string containing the body to send with the request (this string
961+
should default to '').
956962
957963
and ``response_dict`` is a dictionary with the following keys:
958964
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.
965+
- status: An integer containing the HTTP status code (such as 200 or 404).
966+
967+
- reason: The reason phrase, if any, returned by the server.
968+
969+
- headers: A list of pairs containing the response headers (for example, ``[('key': value), ...]``).
964970
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.
971+
- body: A stream-like object supporting ``read(size=None)`` and ``close()``
972+
methods to get the body of the response.
973+
974+
The response dictionary is returned directly by ``HttpLib``'s methods with
975+
no further processing. By default, ``HttpLib`` calls the :func:`handler` function
976+
to get a handler function.
968977
"""
969978
def __init__(self, custom_handler=None):
970979
self.handler = handler() if custom_handler is None else custom_handler
971980

972981
def delete(self, url, headers=None, **kwargs):
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).
982+
"""Sends a DELETE request to a URL.
983+
984+
:param url: The URL.
985+
:type url: ``string``
986+
:param headers: A list of pairs specifying the headers for the HTTP
987+
response (for example, ``[('Content-Type': 'text/cthulhu'), ('Token': 'boris')]``).
988+
:type headers: ``list``
989+
:param kwargs: Additional keyword arguments (optional). These arguments
990+
are interpreted as the query part of the URL. The order of keyword
991+
arguments is not preserved in the request, but the keywords and
992+
their arguments will be URL encoded.
993+
:type kwargs: ``dict``
994+
:returns: A dictionary describing the response (see :class:`HttpLib` for
995+
its structure).
996+
:rtype: ``dict``
984997
"""
985998
if headers is None: headers = []
986999
if kwargs:
@@ -995,17 +1008,21 @@ def delete(self, url, headers=None, **kwargs):
9951008
return self.request(url, message)
9961009

9971010
def get(self, url, headers=None, **kwargs):
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).
1011+
"""Sends a GET request to a URL.
1012+
1013+
:param url: The URL.
1014+
:type url: ``string``
1015+
:param headers: A list of pairs specifying the headers for the HTTP
1016+
response (for example, ``[('Content-Type': 'text/cthulhu'), ('Token': 'boris')]``).
1017+
:type headers: ``list``
1018+
:param kwargs: Additional keyword arguments (optional). These arguments
1019+
are interpreted as the query part of the URL. The order of keyword
1020+
arguments is not preserved in the request, but the keywords and
1021+
their arguments will be URL encoded.
1022+
:type kwargs: ``dict``
1023+
:returns: A dictionary describing the response (see :class:`HttpLib` for
1024+
its structure).
1025+
:rtype: ``dict``
10091026
"""
10101027
if headers is None: headers = []
10111028
if kwargs:
@@ -1016,19 +1033,22 @@ def get(self, url, headers=None, **kwargs):
10161033
return self.request(url, { 'method': "GET", 'headers': headers })
10171034

10181035
def post(self, url, headers=None, **kwargs):
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).
1036+
"""Sends a POST request to a URL.
1037+
1038+
:param url: The URL.
1039+
:type url: ``string``
1040+
:param headers: A list of pairs specifying the headers for the HTTP
1041+
response (for example, ``[('Content-Type': 'text/cthulhu'), ('Token': 'boris')]``).
1042+
:type headers: ``list``
1043+
:param kwargs: Additional keyword arguments (optional). If the argument
1044+
is ``body``, the value is used as the body for the request, and the
1045+
keywords and their arguments will be URL encoded. If there is no
1046+
``body`` keyword argument, all the keyword arguments are encoded
1047+
into the body of the request in the format ``x-www-form-urlencoded``.
1048+
:type kwargs: ``dict``
1049+
:returns: A dictionary describing the response (see :class:`HttpLib` for
1050+
its structure).
1051+
:rtype: ``dict``
10321052
"""
10331053
if headers is None: headers = []
10341054
headers.append(("Content-Type", "application/x-www-form-urlencoded")),
@@ -1048,12 +1068,19 @@ def post(self, url, headers=None, **kwargs):
10481068
return self.request(url, message)
10491069

10501070
def request(self, url, message, **kwargs):
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.
1071+
"""Issues an HTTP request to a URL.
1072+
1073+
:param url: The URL.
1074+
:type url: ``string``
1075+
:param message: A dictionary with the format as described in
1076+
:class:`HttpLib`.
1077+
:type message: ``dict``
1078+
:param kwargs: Additional keyword arguments (optional). These arguments
1079+
are passed unchanged to the handler.
1080+
:type kwargs: ``dict``
1081+
:returns: A dictionary describing the response (see :class:`HttpLib` for
1082+
its structure).
1083+
:rtype: ``dict``
10571084
"""
10581085
response = self.handler(url, message, **kwargs)
10591086
response = record(response)

splunklib/client.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1690,7 +1690,7 @@ class Stanza(Entity):
16901690
"""This class contains a single configuration stanza."""
16911691

16921692
def submit(self, stanza):
1693-
"""Sets the keys in *stanza* this Stanza.
1693+
"""Sets the keys in *stanza* on this Stanza.
16941694
16951695
*stanza* will usually be a dictionary of key/value pairs, but can also
16961696
by a raw string to send as the POST body of the request (e.g.,
@@ -2359,7 +2359,6 @@ def list(self, *kinds, **kwargs):
23592359
23602360
:type kwargs: ``dict``
23612361
2362-
23632362
:return: A list of input kinds.
23642363
:rtype: ``list``
23652364
"""
@@ -2969,7 +2968,7 @@ def __init__(self, service):
29692968
Collection.__init__(self, service, PATH_LOGGER)
29702969

29712970
def itemmeta(self):
2972-
"""There is no metadata available for class:``Jobs``.
2971+
"""There is no metadata available for class:``Loggers``.
29732972
29742973
Any call to this method raises a class:``NotSupportedError``.
29752974

0 commit comments

Comments
 (0)