本文整理汇总了Python中pulsar.utils.system.json.dumps函数的典型用法代码示例。如果您正苦于以下问题:Python dumps函数的具体用法?Python dumps怎么用?Python dumps使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dumps函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: json_params
def json_params(self):
for name, value in self.cfg.items():
try:
json.dumps(value)
except Exception:
continue
yield name, value
开发者ID:dejlek,项目名称:pulsar-queue,代码行数:7,代码来源:consumer.py
示例2: query_model_view
def query_model_view(self, model, view_name, key=None, keys=None,
group=None, limit=None, include_docs=None,
reduce=True, method=None):
'''Query an existing view
All view parameters here:
http://wiki.apache.org/couchdb/HTTP_view_API
'''
meta = model._meta
kwargs = {}
if key:
kwargs['key'] = json.dumps(key)
elif keys:
kwargs['keys'] = json.dumps(keys)
if group:
kwargs['group'] = 'true'
if limit:
kwargs['limit'] = int(limit)
if include_docs:
kwargs['include_docs'] = 'true'
if not reduce:
kwargs['reduce'] = 'false'
return self.request(method or 'get', self._database, '_design',
meta.table_name, '_view', view_name, **kwargs)
开发者ID:huobao36,项目名称:pulsar,代码行数:25,代码来源:store.py
示例3: test_create_instance
def test_create_instance(self):
models = self.mapper(Task)
yield models.create_tables()
task = yield models.task.create(id='bjbhjscbhj', name='foo')
self.assertEqual(task['id'], 'bjbhjscbhj')
data = task.to_json()
self.assertEqual(len(data), 2)
self.assertFalse(task._modified)
# make sure it is serializable
json.dumps(data)
task = yield models.task(task.id)
yield models.drop_tables()
开发者ID:axisofentropy,项目名称:pulsar,代码行数:13,代码来源:__init__.py
示例4: _consume_in_subprocess
def _consume_in_subprocess(self, job, kwargs):
params = dict(self.json_params())
loop = job._loop
transport, protocol = yield from loop.subprocess_exec(
lambda: StreamProtocol(job),
sys.executable,
PROCESS_FILE,
json.dumps(sys.path),
json.dumps(params),
job.task.serialise())
process = Process(transport, protocol, loop)
yield from process.communicate()
if job.task.stacktrace:
raise RemoteStackTrace
return job.task.result
开发者ID:dejlek,项目名称:pulsar-queue,代码行数:16,代码来源:consumer.py
示例5: to_json
def to_json(self):
self.body._tag = None
body = yield multi_async(self.body.stream(request))
self.head._tag = None
data = {'body': body}
data.extend(self.head.to_json())
coroutine_return(json.dumps(data))
开发者ID:pombredanne,项目名称:lux,代码行数:7,代码来源:wrappers.py
示例6: do_stream
def do_stream(self, request):
if self.require:
yield ('<script type="text/javascript">\n'
'var require = %s;\n'
'</script>\n') % json.dumps(self.require_script())
for child in self.children:
yield child
开发者ID:imclab,项目名称:pulsar,代码行数:7,代码来源:content.py
示例7: __call__
def __call__(self, server, data=None):
headers = {}
for hv in bytes(data).decode('utf-8').split('\r\n'):
hv = hv.split(':')
if len(hv) >= 2:
headers[hv[0].strip()] = (':'.join(hv[1:])).strip()
self.headers = json.dumps(headers).encode('utf-8')
开发者ID:quantmind,项目名称:pulsar,代码行数:7,代码来源:manage.py
示例8: _encode_body
def _encode_body(self, data, files, json):
body = None
if isinstance(data, (str, bytes)):
if files:
raise ValueError('data cannot be a string or bytes when '
'files are present')
body = to_bytes(data, self.charset)
elif data and is_streamed(data):
if files:
raise ValueError('data cannot be an iterator when '
'files are present')
if 'content-length' not in self.headers:
self.headers['transfer-encoding'] = 'chunked'
return data
elif data or files:
if files:
body, content_type = self._encode_files(data, files)
else:
body, content_type = self._encode_params(data)
self.headers['Content-Type'] = content_type
elif json:
body = _json.dumps(json).encode(self.charset)
self.headers['Content-Type'] = 'application/json'
if body:
self.headers['content-length'] = str(len(body))
return body
开发者ID:wilddom,项目名称:pulsar,代码行数:28,代码来源:__init__.py
示例9: serialise
def serialise(self, method=None):
'''Serialise this task using the serialisation ``method``
'''
method = method or 'json'
if method == 'json':
return json.dumps(self.__dict__)
else:
raise ImproperlyConfigured('Unknown serialisation "%s"' % method)
开发者ID:dejlek,项目名称:pulsar-queue,代码行数:8,代码来源:task.py
示例10: publish
def publish(self, websocket, channel, message=''):
user, authenticated = self.user(websocket)
msg = {'message': message,
'user': user,
'authenticated': authenticated,
'channel': channel}
channel = '%s:%s' % (websocket.cfg.exc_id, channel)
return self._pubsub.publish(channel, json.dumps(msg))
开发者ID:JinsongBian,项目名称:pulsar,代码行数:8,代码来源:views.py
示例11: _call
def _call(self, name, *args, **kwargs):
data = self._get_data(name, *args, **kwargs)
body = json.dumps(data).encode('utf-8')
resp = self.http.post(self.url, data=body)
if self._full_response:
return resp
res = resp.on_finished.add_callback(self._end_call)
return res.result if self.http.force_sync else res
开发者ID:BazookaShao,项目名称:pulsar,代码行数:8,代码来源:jsonrpc.py
示例12: _call
def _call(self, name, *args, **kwargs):
data = self._get_data(name, *args, **kwargs)
is_ascii = self._encoding == 'ascii'
body = json.dumps(data, ensure_ascii=is_ascii).encode(self._encoding)
if not self._batch:
self._batch = []
self._batch.append(body)
return data['id']
开发者ID:quantmind,项目名称:pulsar,代码行数:8,代码来源:jsonrpc.py
示例13: on_message
def on_message(self, websocket, msg):
request = websocket.request
client = request.cache.mailclient
if msg and client:
msg = json.loads(msg)
if 'mailbox' in msg:
mailbox = yield client.examine(msg['mailbox'])
self.write(request, json.dumps({'mailbox': mailbox}))
开发者ID:JinsongBian,项目名称:pulsar,代码行数:8,代码来源:manage.py
示例14: coveralls
def coveralls(http=None, url=None, data_file=None, repo_token=None,
git=None, service_name=None, service_job_id=None,
strip_dirs=None, ignore_errors=False, stream=None):
'''Send a coverage report to coveralls.io.
:param http: optional http client
:param url: optional url to send data to. It defaults to ``coveralls``
api url.
:param data_file: optional data file to load coverage data from. By
default, coverage uses ``.coverage``.
:param repo_token: required when not submitting from travis.
https://coveralls.io/docs/api
'''
stream = stream or sys.stdout
coverage = Coverage(data_file=data_file)
coverage.load()
if http is None:
http = HttpClient(loop=new_event_loop())
if not git:
try:
git = gitrepo()
except Exception: # pragma nocover
pass
data = {'source_files': coverage.coveralls(strip_dirs=strip_dirs,
ignore_errors=ignore_errors)}
if git:
data['git'] = git
if os.environ.get('TRAVIS'):
data['service_name'] = service_name or 'travis-ci'
data['service_job_id'] = os.environ.get('TRAVIS_JOB_ID')
else:
assert repo_token, 'Requires repo_token if not submitting from travis'
if repo_token:
data['repo_token'] = repo_token
url = url or COVERALLS_URL
stream.write('Submitting coverage report to %s\n' % url)
response = http.post(url, files={'json_file': json.dumps(data)})
stream.write('Response code: %s\n' % response.status_code)
try:
info = response.json()
code = 0
if 'error' in info:
stream.write('An error occured while sending coverage'
' report to coverall.io')
code = 1
stream.write('\n%s\n' % info['message'])
except Exception:
code = 1
stream.write('Critical error %s\n' % response.status_code)
return code
开发者ID:Danzeer,项目名称:pulsar,代码行数:56,代码来源:cov.py
示例15: test_json_with_async_string2
def test_json_with_async_string2(self):
d = Deferred()
astr = wsgi.AsyncString(d)
response = wsgi.Json({'bla': astr})
self.assertEqual(len(response.children), 1)
result = response.render()
self.assertIsInstance(result, Deferred)
d.callback('ciao')
result = yield result
self.assertEqual(result, json.dumps({'bla': 'ciao'}))
开发者ID:BazookaShao,项目名称:pulsar,代码行数:10,代码来源:content.py
示例16: test_json_with_async_string2
def test_json_with_async_string2(self):
d = Future()
astr = wsgi.AsyncString(d)
response = wsgi.Json({"bla": astr})
self.assertEqual(len(response.children), 1)
result = response.render()
self.assertIsInstance(result, Future)
d.set_result("ciao")
result = yield from result
self.assertEqual(result, json.dumps({"bla": "ciao"}))
开发者ID:dejlek,项目名称:pulsar,代码行数:10,代码来源:content.py
示例17: _call
def _call(self, name, *args, **kwargs):
data = self._get_data(name, *args, **kwargs)
body = json.dumps(data).encode('utf-8')
resp = yield self._http.post(self._url, data=body)
if self._full_response:
coroutine_return(resp)
else:
content = resp.decode_content()
if resp.is_error:
if 'error' not in content:
resp.raise_for_status()
coroutine_return(self.loads(content))
开发者ID:Ghost-script,项目名称:dyno-chat,代码行数:12,代码来源:jsonrpc.py
示例18: info_get
def info_get(self, request):
response = request.response
response.content_type = APPJSON
data = {'websocket': self.websockets_enabled,
'entropy': randint(0, MAXSIZE),
'cookie_needed': self.cookie_needed,
'origins': ['*:*']}
response.content = json.dumps(data)
nocache(response)
cors(request)
response._can_store_cookies = False
return response
开发者ID:pombredanne,项目名称:lux,代码行数:12,代码来源:views.py
示例19: json_response
def json_response(self, data, status_code=None):
ct = 'application/json'
content_types = self.content_types
if not content_types or ct in content_types:
response = self.response
response.content_type = ct
response.content = json.dumps(data)
if status_code:
response.status_code = status_code
return response
else:
raise HttpException(status=415, msg=content_types)
开发者ID:quantmind,项目名称:pulsar,代码行数:12,代码来源:wrappers.py
示例20: _encode_params
def _encode_params(self, data):
content_type = self.headers.get("content-type")
# No content type given
if not content_type:
if self.encode_multipart:
return encode_multipart_formdata(data, boundary=self.multipart_boundary, charset=self.charset)
else:
content_type = "application/x-www-form-urlencoded"
body = urlencode(data).encode(self.charset)
elif content_type in JSON_CONTENT_TYPES:
body = json.dumps(data).encode(self.charset)
else:
raise ValueError("Don't know how to encode body for %s" % content_type)
return body, content_type
开发者ID:nmg1986,项目名称:pulsar,代码行数:14,代码来源:__init__.py
注:本文中的pulsar.utils.system.json.dumps函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论