本文整理匯總了Python中botocore.compat.six.PY3屬性的典型用法代碼示例。如果您正苦於以下問題:Python six.PY3屬性的具體用法?Python six.PY3怎麽用?Python six.PY3使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類botocore.compat.six
的用法示例。
在下文中一共展示了six.PY3屬性的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _get_text_writer
# 需要導入模塊: from botocore.compat import six [as 別名]
# 或者: from botocore.compat.six import PY3 [as 別名]
def _get_text_writer(stream, errors):
# In python3, all the sys.stdout/sys.stderr streams are in text
# mode. This means they expect unicode, and will encode the
# unicode automatically before actually writing to stdout/stderr.
# In python2, that's not the case. In order to provide a consistent
# interface, we can create a wrapper around sys.stdout that will take
# unicode, and automatically encode it to the preferred encoding.
# That way consumers can just call get_text_writer(stream) and write
# unicode to the returned stream. Note that get_text_writer
# just returns the stream in the PY3 section above because python3
# handles this.
# We're going to use the preferred encoding, but in cases that there is
# no preferred encoding we're going to fall back to assuming ASCII is
# what we should use. This will currently break the use of
# PYTHONIOENCODING, which would require checking stream.encoding first,
# however, the existing behavior is to only use
# locale.getpreferredencoding() and so in the hope of not breaking what
# is currently working, we will continue to only use that.
encoding = locale.getpreferredencoding()
if encoding is None:
encoding = "ascii"
return codecs.getwriter(encoding)(stream, errors)
示例2: is_resource_action
# 需要導入模塊: from botocore.compat import six [as 別名]
# 或者: from botocore.compat.six import PY3 [as 別名]
def is_resource_action(action_handle):
if six.PY3:
return inspect.isfunction(action_handle)
else:
return inspect.ismethod(action_handle)
示例3: _is_binary
# 需要導入模塊: from botocore.compat import six [as 別名]
# 或者: from botocore.compat.six import PY3 [as 別名]
def _is_binary(self, value):
if isinstance(value, Binary):
return True
elif isinstance(value, bytearray):
return True
elif six.PY3 and isinstance(value, six.binary_type):
return True
return False
示例4: compat_open
# 需要導入模塊: from botocore.compat import six [as 別名]
# 或者: from botocore.compat.six import PY3 [as 別名]
def compat_open(filename, mode='r', encoding=None):
# See docstring for compat_open in the PY3 section above.
if 'b' not in mode:
encoding = locale.getpreferredencoding()
return io.open(filename, mode, encoding=encoding)