mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Bring in salt.utils.stringio from develop branch
This commit is contained in:
parent
6a6ef0adf8
commit
d551b0d857
1 changed files with 39 additions and 0 deletions
39
salt/utils/stringio.py
Normal file
39
salt/utils/stringio.py
Normal file
|
@ -0,0 +1,39 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
Functions for StringIO objects
|
||||
'''
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
# Import 3rd-party libs
|
||||
from salt.ext import six
|
||||
|
||||
# Not using six's fake cStringIO since we need to be able to tell if the object
|
||||
# is readable, and this can't be done via what six exposes.
|
||||
if six.PY2:
|
||||
import StringIO
|
||||
import cStringIO
|
||||
readable_types = (StringIO.StringIO, cStringIO.InputType)
|
||||
writable_types = (StringIO.StringIO, cStringIO.OutputType)
|
||||
else:
|
||||
import io
|
||||
readable_types = (io.StringIO,)
|
||||
writable_types = (io.StringIO,)
|
||||
|
||||
|
||||
def is_stringio(obj):
|
||||
return isinstance(obj, readable_types)
|
||||
|
||||
|
||||
def is_readable(obj):
|
||||
if six.PY2:
|
||||
return isinstance(obj, readable_types)
|
||||
else:
|
||||
return isinstance(obj, readable_types) and obj.readable()
|
||||
|
||||
|
||||
def is_writable(obj):
|
||||
if six.PY2:
|
||||
return isinstance(obj, writable_types)
|
||||
else:
|
||||
return isinstance(obj, writable_types) and obj.writable()
|
Loading…
Add table
Reference in a new issue