Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions splunklib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

"""Python library for Splunk."""

from __future__ import absolute_import
from splunklib.six.moves import map
import logging

DEFAULT_LOG_FORMAT = '%(asctime)s, Level=%(levelname)s, Pid=%(process)s, Logger=%(name)s, File=%(filename)s, ' \
Expand All @@ -31,5 +29,35 @@ def setup_logging(level, log_format=DEFAULT_LOG_FORMAT, date_format=DEFAULT_DATE
format=log_format,
datefmt=date_format)


def ensure_binary(s, encoding='utf-8', errors='strict'):
"""
- `str` -> encoded to `bytes`
- `bytes` -> `bytes`
"""
if isinstance(s, str):
return s.encode(encoding, errors)

if isinstance(s, bytes):
return s

raise TypeError(f"not expecting type '{type(s)}'")


def ensure_str(s, encoding='utf-8', errors='strict'):
"""
- `str` -> `str`
- `bytes` -> decoded to `str`
"""
if isinstance(s, bytes):
return s.decode(encoding, errors)

if isinstance(s, str):
return s

raise TypeError(f"not expecting type '{type(s)}'")


__version_info__ = (1, 6, 19)

__version__ = ".".join(map(str, __version_info__))
Loading