Skip to content

Commit 9f92cf2

Browse files
committed
Edits to new stuff, more cleanup
I looked over Fred's additions and edited, fixed the interdoc linking. Found more nitpicks.
1 parent 39bb7bf commit 9f92cf2

File tree

2 files changed

+107
-91
lines changed

2 files changed

+107
-91
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: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def _trailing(template, *targets):
171171
:type template: ``string``
172172
:param targets: Strings to successively match in *template*.
173173
:type targets: list of ``string``s
174-
:return: Trailing string after all targets are matched.
174+
:return: The trailing string after all targets are matched.
175175
:rtype: ``string``
176176
:raises ValueError: Raised when one of the targets does not match.
177177
"""
@@ -417,8 +417,7 @@ def indexes(self):
417417
def info(self):
418418
"""Returns the information about this instance of Splunk.
419419
420-
:return: The system information, as key-value pairs.
421-
:rtype: ``dict``
420+
:return: The system information, as a ``dict`` of key-value pairs.
422421
"""
423422
response = self.get("server/info")
424423
return _filter_content(_load_atom(response, MATCH_ENTRY_CONTENT))
@@ -915,10 +914,6 @@ def _proper_namespace(self, owner=None, app=None, sharing=None):
915914
showing up due to wildcards in the service's namespace. We replace the wildcards with the
916915
namespace of the entity we want.
917916
918-
:param owner:
919-
:param app:
920-
:param sharing:
921-
:return:
922917
"""
923918
if owner is None and app is None and sharing is None and\
924919
(self.service.namespace.owner == '-' or self.service.namespace.app == '-'):
@@ -1023,8 +1018,7 @@ def links(self):
10231018
def name(self):
10241019
"""Returns the entity name.
10251020
1026-
:return: The entity name.
1027-
:rtype: ``string``
1021+
:return: A ``string`` containing the entity name.
10281022
"""
10291023
return self.state.title
10301024

@@ -1081,8 +1075,7 @@ def update(self, **kwargs):
10811075
:param kwargs: Additional entity-specific arguments (optional).
10821076
:type kwargs: ``dict``
10831077
1084-
:return: The entity this method is called on.
1085-
:rtype: class:`Entity`
1078+
:return: The :class:`Entity`.
10861079
"""
10871080
# The peculiarity in question: the REST API creates a new
10881081
# Entity if we pass name in the dictionary, instead of the
@@ -1689,11 +1682,11 @@ def _entity_path(self, state):
16891682
class Stanza(Entity):
16901683
"""This class contains a single configuration stanza."""
16911684
def submit(self, stanza):
1692-
"""Sets the keys in *stanza* this Stanza.
1685+
"""Sets the keys in this stanza.
16931686
1694-
:param stanza: A dictionary of key/value pairs to set in this stanza.
1687+
:param stanza: A dictionary of key-value pairs to set in this stanza.
16951688
:type stanza: ``dict``
1696-
:return: The :class:`Stanza` object this method is called on.
1689+
:return: The :class:`Stanza` object.
16971690
"""
16981691
body = _encode(**stanza)
16991692
self.service.post(self.path, body=body)
@@ -1748,7 +1741,7 @@ def default(self):
17481741
def delete(self, name):
17491742
""" Deletes a given index.
17501743
1751-
**Note**: This method is only supported in Splunk 5.0 and later.
1744+
**Note**: This method is only supported in Splunk 5.0 and later.
17521745
17531746
:param name: The name of the index to delete.
17541747
:type name: ``string``
@@ -1814,8 +1807,6 @@ def attached_socket(self, *args, **kwargs):
18141807
stream.
18151808
:type sourcetype: ``string``
18161809
1817-
:returns: Nothing.
1818-
18191810
**Example**::
18201811
18211812
import splunklib.client as client
@@ -1933,7 +1924,7 @@ def submit(self, event, host=None, source=None, sourcetype=None):
19331924
def upload(self, filename, **kwargs):
19341925
"""Uploads a file for immediate indexing.
19351926
1936-
**Note**: The file must be locally accessible from the server.
1927+
**Note**: The file must be locally accessible from the server.
19371928
19381929
:param filename: The name of the file to upload. The file can be a
19391930
plain, compressed, or archived file.
@@ -1984,8 +1975,7 @@ def update(self, **kwargs):
19841975
available parameters, see `Input parameters <http://dev.splunk.com/view/SP-CAAAEE6#inputparams>`_ on Splunk Developer Portal.
19851976
:type kwargs: ``dict``
19861977
1987-
:return: The input this method was called on.
1988-
:rtype: class:`Input`
1978+
:return: The :class:`Input`.
19891979
"""
19901980
if self.kind not in ['tcp', 'splunktcp', 'tcp/raw', 'tcp/cooked']:
19911981
result = super(Input, self).update(**kwargs)
@@ -2221,8 +2211,7 @@ def itemmeta(self, kind):
22212211
22222212
:type kind: ``string``
22232213
2224-
:return: The metadata.
2225-
:rtype: class:``splunklib.data.Record``
2214+
:return: A :class:`splunklib.data.Record` containing the metadata.
22262215
"""
22272216
response = self.get("%s/_new" % self._kindmap[kind])
22282217
content = _load_atom(response, MATCH_ENTRY_CONTENT)

0 commit comments

Comments
 (0)