Skip to content

Commit

Permalink
Upgrade external libs
Browse files Browse the repository at this point in the history
- jmespath-0.9.4     from (0.9.3)
- splunk-sdk-1.6.6   from (1.6.5)
  • Loading branch information
lowell80 committed Mar 20, 2019
1 parent 692ee42 commit f649fb0
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 40 deletions.
2 changes: 1 addition & 1 deletion bin/jmespath/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from jmespath import parser
from jmespath.visitor import Options

__version__ = '0.9.3'
__version__ = '0.9.4'


def compile(expression):
Expand Down
14 changes: 10 additions & 4 deletions bin/jmespath/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
'boolean': ('bool',),
'array': ('list', '_Projection'),
'object': ('dict', 'OrderedDict',),
'null': ('None',),
'null': ('NoneType',),
'string': ('unicode', 'str'),
'number': ('float', 'int', 'long'),
'expref': ('_Expression',),
Expand Down Expand Up @@ -331,14 +331,20 @@ def _func_min_by(self, array, expref):
keyfunc = self._create_key_func(expref,
['number', 'string'],
'min_by')
return min(array, key=keyfunc)
if array:
return min(array, key=keyfunc)
else:
return None

@signature({'types': ['array']}, {'types': ['expref']})
def _func_max_by(self, array, expref):
keyfunc = self._create_key_func(expref,
['number', 'string'],
'min_by')
return max(array, key=keyfunc)
'max_by')
if array:
return max(array, key=keyfunc)
else:
return None

def _create_key_func(self, expref, allowed_types, function_name):
def keyfunc(x):
Expand Down
4 changes: 2 additions & 2 deletions bin/jmespath/visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ class Options(object):
"""Options to control how a JMESPath function is evaluated."""
def __init__(self, dict_cls=None, custom_functions=None):
#: The class to use when creating a dict. The interpreter
# may create dictionaries during the evalution of a JMESPath
# may create dictionaries during the evaluation of a JMESPath
# expression. For example, a multi-select hash will
# create a dictionary. By default we use a dict() type.
# You can set this value to change what dict type is used.
# The most common reason you would change this is if you
# want to set a collections.OrderedDict so that you can
# have predictible key ordering.
# have predictable key ordering.
self.dict_cls = dict_cls
self.custom_functions = custom_functions

Expand Down
2 changes: 1 addition & 1 deletion bin/splunklib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@

from __future__ import absolute_import
from splunklib.six.moves import map
__version_info__ = (1, 6, 5)
__version_info__ = (1, 6, 6)
__version__ = ".".join(map(str, __version_info__))
58 changes: 37 additions & 21 deletions bin/splunklib/binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,30 @@
"""

from __future__ import absolute_import

import io
import logging
import socket
import ssl
from io import BytesIO

from splunklib.six.moves import urllib
import io
import sys

from base64 import b64encode
from contextlib import contextmanager
from datetime import datetime
from functools import wraps
from io import BytesIO
from xml.etree.ElementTree import XML

from splunklib import six
from splunklib.six import StringIO
from splunklib.six.moves import urllib

from contextlib import contextmanager
from .data import record

from xml.etree.ElementTree import XML
from splunklib import six
try:
from xml.etree.ElementTree import ParseError
except ImportError as e:
from xml.parsers.expat import ExpatError as ParseError

from .data import record

__all__ = [
"AuthenticationError",
Expand Down Expand Up @@ -449,6 +449,8 @@ class Context(object):
: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 handler: The HTTP request handler (optional).
:returns: A ``Context`` instance.
Expand All @@ -465,7 +467,8 @@ class Context(object):
c = binding.Context(cookie="splunkd_8089=...")
"""
def __init__(self, handler=None, **kwargs):
self.http = HttpLib(handler, kwargs.get("verify", True))
self.http = HttpLib(handler, kwargs.get("verify", False), key_file=kwargs.get("key_file"),
cert_file=kwargs.get("cert_file")) # Default to False for backward compat
self.token = kwargs.get("token", _NoAuthenticationToken)
if self.token is None: # In case someone explicitly passes token=None
self.token = _NoAuthenticationToken
Expand All @@ -478,6 +481,7 @@ def __init__(self, handler=None, **kwargs):
self.password = kwargs.get("password", "")
self.basic = kwargs.get("basic", False)
self.autologin = kwargs.get("autologin", False)
self.additional_headers = kwargs.get("headers", [])

# Store any cookies in the self.http._cookies dict
if "cookie" in kwargs and kwargs['cookie'] not in [None, _NoAuthenticationToken]:
Expand Down Expand Up @@ -613,7 +617,7 @@ def delete(self, path_segment, owner=None, app=None, sharing=None, **query):

@_authentication
@_log_duration
def get(self, path_segment, owner=None, app=None, sharing=None, **query):
def get(self, path_segment, owner=None, app=None, headers=None, sharing=None, **query):
"""Performs a GET operation from the REST path segment with the given
namespace and query.
Expand All @@ -636,6 +640,8 @@ def get(self, path_segment, owner=None, app=None, sharing=None, **query):
: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
Expand Down Expand Up @@ -663,10 +669,14 @@ def get(self, path_segment, owner=None, app=None, sharing=None, **query):
c.logout()
c.get('apps/local') # raises AuthenticationError
"""
if headers is None:
headers = []

path = self.authority + self._abspath(path_segment, owner=owner,
app=app, sharing=sharing)
logging.debug("GET request to %s (body: %s)", path, repr(query))
response = self.http.get(path, self._auth_headers, **query)
all_headers = headers + self.additional_headers + self._auth_headers
response = self.http.get(path, all_headers, **query)
return response

@_authentication
Expand Down Expand Up @@ -738,7 +748,7 @@ def post(self, path_segment, owner=None, app=None, sharing=None, headers=None, *

path = self.authority + self._abspath(path_segment, owner=owner, app=app, sharing=sharing)
logging.debug("POST request to %s (body: %s)", path, repr(query))
all_headers = headers + self._auth_headers
all_headers = headers + self.additional_headers + self._auth_headers
response = self.http.post(path, all_headers, **query)
return response

Expand Down Expand Up @@ -804,7 +814,7 @@ def request(self, path_segment, method="GET", headers=None, body="",
path = self.authority \
+ self._abspath(path_segment, owner=owner,
app=app, sharing=sharing)
all_headers = headers + self._auth_headers
all_headers = headers + self.additional_headers + self._auth_headers
logging.debug("%s request to %s (headers: %s, body: %s)",
method, path, str(all_headers), repr(body))
response = self.http.request(path,
Expand Down Expand Up @@ -858,6 +868,7 @@ def login(self):
self.authority + self._abspath("/services/auth/login"),
username=self.username,
password=self.password,
headers=self.additional_headers,
cookie="1") # In Splunk 6.2+, passing "cookie=1" will return the "set-cookie" header

body = response.body.read()
Expand Down Expand Up @@ -968,6 +979,8 @@ def connect(**kwargs):
: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``
Expand Down Expand Up @@ -1108,8 +1121,11 @@ class HttpLib(object):
If using the default handler, SSL verification can be disabled by passing verify=False.
"""
def __init__(self, custom_handler=None, verify=True):
self.handler = handler(verify=verify) if custom_handler is None else custom_handler
def __init__(self, custom_handler=None, verify=False, key_file=None, cert_file=None):
if custom_handler is None:
self.handler = handler(verify=verify, key_file=key_file, cert_file=cert_file)
else:
self.handler = custom_handler
self._cookies = {}

def delete(self, url, headers=None, **kwargs):
Expand Down Expand Up @@ -1280,8 +1296,8 @@ def peek(self, size):

def close(self):
"""Closes this response."""
if _connection:
_connection.close()
if self._connection:
self._connection.close()
self._response.close()

def read(self, size = None):
Expand Down Expand Up @@ -1317,7 +1333,7 @@ def readinto(self, byte_array):
return bytes_read


def handler(key_file=None, cert_file=None, timeout=None, verify=True):
def handler(key_file=None, cert_file=None, timeout=None, verify=False):
"""This class returns an instance of the default HTTP request handler using
the values you provide.
Expand All @@ -1341,7 +1357,7 @@ def connect(scheme, host, port):
if cert_file is not None: kwargs['cert_file'] = cert_file

# If running Python 2.7.9+, disable SSL certificate validation
if (sys.version_info >= (2,7,9) and key_file is None and cert_file is None) or not verify:
if (sys.version_info >= (2,7,9) and key_file is None and cert_file is None) and not verify:
kwargs['context'] = ssl._create_unverified_context()
return six.moves.http_client.HTTPSConnection(host, port, **kwargs)
raise ValueError("unsupported scheme: %s" % scheme)
Expand All @@ -1352,7 +1368,7 @@ def request(url, message, **kwargs):
head = {
"Content-Length": str(len(body)),
"Host": host,
"User-Agent": "splunk-sdk-python/1.6.5",
"User-Agent": "splunk-sdk-python/1.6.6",
"Accept": "*/*",
"Connection": "Close",
} # defaults
Expand Down
20 changes: 13 additions & 7 deletions bin/splunklib/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,22 @@
my_app.package() # Creates a compressed package of this application
"""

import contextlib
import datetime
import json
from splunklib.six.moves import urllib
import logging
from time import sleep
from datetime import datetime, timedelta
import socket
import contextlib
from datetime import datetime, timedelta
from time import sleep

from splunklib import six
from .binding import Context, HTTPError, AuthenticationError, namespace, UrlEncoded, _encode, _make_cookie_header, _NoAuthenticationToken
from .data import record
from splunklib.six.moves import urllib

from . import data
from .binding import (AuthenticationError, Context, HTTPError, UrlEncoded,
_encode, _make_cookie_header, _NoAuthenticationToken,
namespace)
from .data import record

__all__ = [
"connect",
Expand Down Expand Up @@ -193,8 +196,11 @@ def _path(base, name):


# Load an atom record from the body of the given response
# this will ultimately be sent to an xml ElementTree so we
# should use the xmlcharrefreplace option
def _load_atom(response, match=None):
return data.load(response.body.read().decode('utf-8'), match)
return data.load(response.body.read()
.decode('utf-8', 'xmlcharrefreplace'), match)


# Load an array of atom entries from the body of the given response
Expand Down
1 change: 1 addition & 0 deletions bin/splunklib/modularinput/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def run_script(self, args, event_writer, input_stream):
err_string = "ERROR Invalid arguments to modular input script:" + ' '.join(
args)
event_writer._err.write(err_string)
return 1

except Exception as e:
err_string = EventWriter.ERROR + str(e)
Expand Down
2 changes: 1 addition & 1 deletion bin/splunklib/searchcommands/internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from collections import OrderedDict # must be python 2.7
except ImportError:
from ..ordereddict import OrderedDict
from splunklib.six.moves import cStringIO as StringIO
from splunklib.six.moves import StringIO
from itertools import chain
from splunklib.six.moves import map as imap
from json import JSONDecoder, JSONEncoder
Expand Down
3 changes: 1 addition & 2 deletions bin/splunklib/searchcommands/search_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
except ImportError:
from ..ordereddict import OrderedDict
from copy import deepcopy
from splunklib.six.moves import cStringIO as StringIO
from splunklib.six.moves import StringIO
from itertools import chain, islice
from splunklib.six.moves import filter as ifilter, map as imap, zip as izip
from splunklib import six
Expand Down Expand Up @@ -850,7 +850,6 @@ def _execute(self, ifile, process):

@staticmethod
def _read_chunk(ifile):

# noinspection PyBroadException
try:
header = ifile.readline()
Expand Down
2 changes: 1 addition & 1 deletion bin/splunklib/searchcommands/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from json.encoder import encode_basestring_ascii as json_encode_string
from collections import namedtuple
from splunklib.six.moves import cStringIO as StringIO
from splunklib.six.moves import StringIO
from io import open
import csv
import os
Expand Down

0 comments on commit f649fb0

Please sign in to comment.