本文整理匯總了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