本文整理汇总了Python中simplejson._speedups.encode_basestring_ascii方法的典型用法代码示例。如果您正苦于以下问题:Python _speedups.encode_basestring_ascii方法的具体用法?Python _speedups.encode_basestring_ascii怎么用?Python _speedups.encode_basestring_ascii使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类simplejson._speedups
的用法示例。
在下文中一共展示了_speedups.encode_basestring_ascii方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _import_speedups
# 需要导入模块: from simplejson import _speedups [as 别名]
# 或者: from simplejson._speedups import encode_basestring_ascii [as 别名]
def _import_speedups():
try:
from simplejson import _speedups
return _speedups.encode_basestring_ascii, _speedups.make_encoder
except ImportError:
return None, None
示例2: encode
# 需要导入模块: from simplejson import _speedups [as 别名]
# 或者: from simplejson._speedups import encode_basestring_ascii [as 别名]
def encode(self, o):
"""Return a JSON string representation of a Python data structure.
>>> from simplejson import JSONEncoder
>>> JSONEncoder().encode({"foo": ["bar", "baz"]})
'{"foo": ["bar", "baz"]}'
"""
# This is for extremely simple cases and benchmarks.
if isinstance(o, basestring):
if isinstance(o, str):
_encoding = self.encoding
if (_encoding is not None
and not (_encoding == 'utf-8')):
o = o.decode(_encoding)
if self.ensure_ascii:
return encode_basestring_ascii(o)
else:
return encode_basestring(o)
# This doesn't pass the iterator directly to ''.join() because the
# exceptions aren't as detailed. The list call should be roughly
# equivalent to the PySequence_Fast that ''.join() would do.
chunks = self.iterencode(o, _one_shot=True)
if not isinstance(chunks, (list, tuple)):
chunks = list(chunks)
if self.ensure_ascii:
return ''.join(chunks)
else:
return u''.join(chunks)
示例3: _import_speedups
# 需要导入模块: from simplejson import _speedups [as 别名]
# 或者: from simplejson._speedups import encode_basestring_ascii [as 别名]
def _import_speedups():
try:
raise ImportError # because assumes simplejson in path
from simplejson import _speedups
return _speedups.encode_basestring_ascii, _speedups.make_encoder
except ImportError:
return None, None