當前位置: 首頁>>代碼示例>>Python>>正文


Python _speedups.encode_basestring_ascii方法代碼示例

本文整理匯總了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 
開發者ID:linuxscout,項目名稱:mishkal,代碼行數:8,代碼來源:encoder.py

示例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) 
開發者ID:linuxscout,項目名稱:mishkal,代碼行數:31,代碼來源:encoder.py

示例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 
開發者ID:uwdata,項目名稱:termite-visualizations,代碼行數:9,代碼來源:encoder.py


注:本文中的simplejson._speedups.encode_basestring_ascii方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。