Skip to content

Commit f68d408

Browse files
authored
Merge pull request #455 from splunk/py2to3-core
Py2to3 core
2 parents 64de6a4 + 7e63b6a commit f68d408

File tree

6 files changed

+310
-1268
lines changed

6 files changed

+310
-1268
lines changed

splunklib/__init__.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
"""Python library for Splunk."""
1616

17-
from __future__ import absolute_import
18-
from splunklib.six.moves import map
1917
import logging
2018

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

32+
33+
def ensure_binary(s, encoding='utf-8', errors='strict'):
34+
"""
35+
- `str` -> encoded to `bytes`
36+
- `bytes` -> `bytes`
37+
"""
38+
if isinstance(s, str):
39+
return s.encode(encoding, errors)
40+
41+
if isinstance(s, bytes):
42+
return s
43+
44+
raise TypeError(f"not expecting type '{type(s)}'")
45+
46+
47+
def ensure_str(s, encoding='utf-8', errors='strict'):
48+
"""
49+
- `str` -> `str`
50+
- `bytes` -> decoded to `str`
51+
"""
52+
if isinstance(s, bytes):
53+
return s.decode(encoding, errors)
54+
55+
if isinstance(s, str):
56+
return s
57+
58+
raise TypeError(f"not expecting type '{type(s)}'")
59+
60+
3461
__version_info__ = (1, 6, 19)
62+
3563
__version__ = ".".join(map(str, __version_info__))

0 commit comments

Comments
 (0)