5858 my_app.package() # Creates a compressed package of this application
5959"""
6060
61+ import contextlib
6162import datetime
6263import json
63- from splunklib .six .moves import urllib
6464import logging
65- from time import sleep
66- from datetime import datetime , timedelta
6765import socket
68- import contextlib
66+ from datetime import datetime , timedelta
67+ from time import sleep
6968
7069from splunklib import six
71- from . binding import Context , HTTPError , AuthenticationError , namespace , UrlEncoded , _encode , _make_cookie_header , _NoAuthenticationToken
72- from . data import record
70+ from splunklib . six . moves import urllib
71+
7372from . import data
73+ from .binding import (AuthenticationError , Context , HTTPError , UrlEncoded ,
74+ _encode , _make_cookie_header , _NoAuthenticationToken ,
75+ namespace )
76+ from .data import record
7477
7578__all__ = [
7679 "connect" ,
@@ -193,8 +196,11 @@ def _path(base, name):
193196
194197
195198# Load an atom record from the body of the given response
199+ # this will ultimately be sent to an xml ElementTree so we
200+ # should use the xmlcharrefreplace option
196201def _load_atom (response , match = None ):
197- return data .load (response .body .read ().decode ('utf-8' ), match )
202+ return data .load (response .body .read ()
203+ .decode ('utf-8' , 'xmlcharrefreplace' ), match )
198204
199205
200206# Load an array of atom entries from the body of the given response
@@ -557,7 +563,7 @@ def restart(self, timeout=None):
557563 # This message will be deleted once the server actually restarts.
558564 self .messages .create (name = "restart_required" , ** msg )
559565 result = self .post ("/services/server/control/restart" )
560- if timeout is None :
566+ if timeout is None :
561567 return result
562568 start = datetime .now ()
563569 diff = timedelta (seconds = timeout )
@@ -1631,7 +1637,7 @@ def get(self, name="", owner=None, app=None, sharing=None, **query):
16311637 and ``status``
16321638
16331639 Example:
1634-
1640+
16351641 import splunklib.client
16361642 s = client.service(...)
16371643 saved_searches = s.saved_searches
@@ -1685,7 +1691,7 @@ def __getitem__(self, key):
16851691 # The superclass implementation is designed for collections that contain
16861692 # entities. This collection (Configurations) contains collections
16871693 # (ConfigurationFile).
1688- #
1694+ #
16891695 # The configurations endpoint returns multiple entities when we ask for a single file.
16901696 # This screws up the default implementation of __getitem__ from Collection, which thinks
16911697 # that multiple entities means a name collision, so we have to override it here.
@@ -1749,9 +1755,9 @@ class Stanza(Entity):
17491755 """This class contains a single configuration stanza."""
17501756
17511757 def submit (self , stanza ):
1752- """Adds keys to the current configuration stanza as a
1758+ """Adds keys to the current configuration stanza as a
17531759 dictionary of key-value pairs.
1754-
1760+
17551761 :param stanza: A dictionary of key-value pairs for the stanza.
17561762 :type stanza: ``dict``
17571763 :return: The :class:`Stanza` object.
@@ -1962,7 +1968,7 @@ def attach(self, host=None, source=None, sourcetype=None):
19621968 cookie_or_auth_header .encode ('utf-8' ),
19631969 b"X-Splunk-Input-Mode: Streaming\r \n " ,
19641970 b"\r \n " ]
1965-
1971+
19661972 for h in headers :
19671973 sock .write (h )
19681974 return sock
@@ -3695,13 +3701,13 @@ def batch_find(self, *dbqueries):
36953701
36963702 :param dbqueries: Array of individual queries as dictionaries
36973703 :type dbqueries: ``array`` of ``dict``
3698-
3704+
36993705 :return: Results of each query
37003706 :rtype: ``array`` of ``array``
37013707 """
3702- if len (dbqueries ) < 1 :
3708+ if len (dbqueries ) < 1 :
37033709 raise Exception ('Must have at least one query.' )
3704-
3710+
37053711 data = json .dumps (dbqueries )
37063712
37073713 return json .loads (self ._post ('batch_find' , headers = KVStoreCollectionData .JSON_HEADER , body = data ).body .read ().decode ('utf-8' ))
@@ -3712,13 +3718,13 @@ def batch_save(self, *documents):
37123718
37133719 :param documents: Array of documents to save as dictionaries
37143720 :type documents: ``array`` of ``dict``
3715-
3721+
37163722 :return: Results of update operation as overall stats
37173723 :rtype: ``dict``
37183724 """
3719- if len (documents ) < 1 :
3725+ if len (documents ) < 1 :
37203726 raise Exception ('Must have at least one document.' )
3721-
3727+
37223728 data = json .dumps (documents )
37233729
37243730 return json .loads (self ._post ('batch_save' , headers = KVStoreCollectionData .JSON_HEADER , body = data ).body .read ().decode ('utf-8' ))
0 commit comments