本文整理汇总了Python中z3c.json.minjson.write函数的典型用法代码示例。如果您正苦于以下问题:Python write函数的具体用法?Python write怎么用?Python write使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了write函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: testWriteDecimal
def testWriteDecimal(self):
try:
from decimal import Decimal
s = Decimal('1.33')
assert json.write(s) == "1.33"
except ImportError:
pass
开发者ID:zopefoundation,项目名称:z3c.json,代码行数:7,代码来源:tests.py
示例2: write
def write(self, anObject):
if hasCJson:
try:
return unicode(cjson.encode(anObject))
except cjson.EncodeError:
# fall back to minjson
pass
try:
return minjson.write(anObject)
except minjson.WriteException, e:
raise TypeError, e
开发者ID:jean,项目名称:z3c.json,代码行数:11,代码来源:converter.py
示例3: testWriteWithEncodingBaseCases
def testWriteWithEncodingBaseCases(self):
#input_uni = u"'Ă�rvĂztĹąrĹ� tĂźkĂśrfĂşrĂłgĂŠp'"
input_uni = u'\xc1rv\xedzt\u0171r\u0151 t\xfck\xf6rf\xfar\xf3g\xe9p'
#print "input_uni is %s" % input_uni.encode('latin2')
# the result supposes doUxxxx = False
good_result = u'"\xc1rv\xedzt\u0171r\u0151 t\xfck\xf6rf\xfar\xf3g\xe9p"'
# from utf8
obj = input_uni.encode('utf-8')
r = json.write(obj, 'utf-8',outputEncoding='utf-8')
self.assertEqual(unicode(r,'utf-8'), good_result)
# from unicode
obj = input_uni
r = json.write(obj, outputEncoding='utf-8')
self.assertEqual(unicode(r,'utf-8'), good_result)
# from latin2
obj = input_uni.encode('latin2')
r = json.write(obj, 'latin2', outputEncoding='latin2')
self.assertEqual(unicode(r,'latin2'), good_result)
# from unicode, encoding is ignored
obj = input_uni
r = json.write(obj, 'latin2', outputEncoding='latin2')
self.assertEqual(unicode(r,'latin2'), good_result)
# same with composite types, uni
good_composite_result = \
u'["\xc1rv\xedzt\u0171r\u0151 t\xfck\xf6rf\xfar\xf3g\xe9p","\xc1rv\xedzt\u0171r\u0151 t\xfck\xf6rf\xfar\xf3g\xe9p"]'
#print "Good composite result = %s" % good_composite_result.encode('latin2')
obj = [input_uni, input_uni]
r = json.write(obj, outputEncoding='utf-8')
#print "r is %s, length is %s." % (r, len(r))
self.assertEqual(unicode(r,'utf-8'), good_composite_result)
# same with composite types, utf-8
obj = [input_uni.encode('utf-8'), input_uni.encode('utf-8')]
r = json.write(obj, 'utf-8')
# print unicode(r,'utf-8'), good_composite_result
#self.assertEqual(unicode(r,'utf-8'), good_composite_result)
# same with composite types, latin2
obj = [input_uni.encode('latin2'), input_uni.encode('latin2')]
r = json.write(obj, 'latin2')
#cannot assertEqual here, but the printed representation should be readable
#self.assertEqual(unicode(r,'latin2'), good_composite_result)
# same with composite types, mixed utf-8 with unicode
obj = [input_uni, input_uni.encode('utf-8')]
r = json.write(obj, 'utf-8')
开发者ID:zopefoundation,项目名称:z3c.json,代码行数:51,代码来源:tests.py
示例4: set_next_response_json
def set_next_response_json(result, jsonId=None, error=None):
jsonId = jsonId or "jsonrpc"
wrapper = {'id': jsonId}
wrapper['result'] = result
wrapper['error'] = error
json = JSONWriter()
data = json.write(wrapper)
set_next_response(data,
response_type="application/x-javascript;charset=utf-8"
)
开发者ID:zopefoundation,项目名称:z3c.json,代码行数:12,代码来源:tests.py
示例5: __call__
def __call__(self, uids):
rc = getToolByName(self.context, 'reference_catalog')
uids = uids.split(',')
result = {}
result['container'] = self.context.restrictedTraverse("@@sl_controls")()
result['items'] = []
for key in uids:
if not key:
continue
uid = key.split('_')[1]
object_ = rc.lookupObject(uid)
if object_ is not None:
controls = object_.restrictedTraverse("@@sl_controls")
result['items'].append(dict(id=key, data=controls()))
return json.write(result)
开发者ID:4teamwork,项目名称:simplelayout.ui.base,代码行数:15,代码来源:views.py
示例6: testWriteHexUnicode1
def testWriteHexUnicode1(self):
s = unicode('\xff\xfe\xbf\x00Q\x00u\x00\xe9\x00 \x00p\x00a\x00s\x00a\x00?\x00','utf-16')
p = json.write(s, 'latin-1')
self.assertEqual(p, u'"¿Qué pasa?"')
开发者ID:zopefoundation,项目名称:z3c.json,代码行数:4,代码来源:tests.py
示例7: testWriteDosPath
def testWriteDosPath(self):
s = 'c:\\windows\\system'
assert json.write(s) == r'"c:\\windows\\system"'
开发者ID:zopefoundation,项目名称:z3c.json,代码行数:3,代码来源:tests.py
示例8: testWriteNegInt
def testWriteNegInt(self):
s = -1
assert json.write(s) == '-1'
开发者ID:zopefoundation,项目名称:z3c.json,代码行数:3,代码来源:tests.py
示例9: testWriteMixedTuple
def testWriteMixedTuple(self):
o = ('OIL',34,199L,38.5)
assert spaceless(json.write(o)) == '["OIL",34,199,38.5]'
开发者ID:zopefoundation,项目名称:z3c.json,代码行数:3,代码来源:tests.py
示例10: testWriteVirtualTuple
def testWriteVirtualTuple(self):
s = 4,4,5,6
w = json.write(s)
assert spaceless(w) == '[4,4,5,6]'
开发者ID:zopefoundation,项目名称:z3c.json,代码行数:4,代码来源:tests.py
示例11: testWriteShortLong
def testWriteShortLong(self):
s = 1L
self.assertEqual(json.write(s), "1")
开发者ID:zopefoundation,项目名称:z3c.json,代码行数:3,代码来源:tests.py
示例12: testWriteNewLine
def testWriteNewLine(self):
s = u'\n'
assert json.write(s) == r'"\n"'
开发者ID:zopefoundation,项目名称:z3c.json,代码行数:3,代码来源:tests.py
示例13: testWriteListOfDicts
def testWriteListOfDicts(self):
s = [{},{}]
assert spaceless(json.write(s)) == "[{},{}]"
开发者ID:zopefoundation,项目名称:z3c.json,代码行数:3,代码来源:tests.py
示例14: testWriteStringWithDoubleQuote
def testWriteStringWithDoubleQuote(self):
s = "do\"nt"
w = json.write(s)
assert w == '"do\\\"nt"'
开发者ID:zopefoundation,项目名称:z3c.json,代码行数:4,代码来源:tests.py
示例15: testWriteStringWithEscapedDoubleQuote
def testWriteStringWithEscapedDoubleQuote(self):
s = 'he said, \"hi.'
t = json.write(s)
assert json.write(s) == '"he said, \\\"hi."'
开发者ID:zopefoundation,项目名称:z3c.json,代码行数:4,代码来源:tests.py
示例16: testWriteListofStringsWithRandomQuoting
def testWriteListofStringsWithRandomQuoting(self):
s = ["hasn't","do\"n't","isn't",True,"wo\"n't"]
w = json.write(s)
assert "true" in w
开发者ID:zopefoundation,项目名称:z3c.json,代码行数:4,代码来源:tests.py
示例17: testWriteTupleofStringsWithApostrophes
def testWriteTupleofStringsWithApostrophes(self):
s = ("hasn't","don't","isn't",True,"won't")
w = json.write(s)
assert spaceless(w) == '["hasn\'t","don\'t","isn\'t",true,"won\'t"]'
开发者ID:zopefoundation,项目名称:z3c.json,代码行数:4,代码来源:tests.py
示例18: testWriteStringWithWhiteSpace
def testWriteStringWithWhiteSpace(self):
s = 'hello \tworld'
assert json.write(s) == r'"hello \tworld"'
开发者ID:zopefoundation,项目名称:z3c.json,代码行数:3,代码来源:tests.py
示例19: testWriteDosPathInList
def testWriteDosPathInList(self):
s = ['c:\windows\system','c:\\windows\\system',r'c:\windows\system']
self.assertEqual(json.write(s) , r'["c:\\windows\\system","c:\\windows\\system","c:\\windows\\system"]')
开发者ID:zopefoundation,项目名称:z3c.json,代码行数:3,代码来源:tests.py
示例20: testWriteSimpleUnicode
def testWriteSimpleUnicode(self):
s = u'hello'
assert json.write(s) == '"hello"'
开发者ID:zopefoundation,项目名称:z3c.json,代码行数:3,代码来源:tests.py
注:本文中的z3c.json.minjson.write函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论