本文整理汇总了Python中pulsar.utils.pep.to_string函数的典型用法代码示例。如果您正苦于以下问题:Python to_string函数的具体用法?Python to_string怎么用?Python to_string使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了to_string函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: login_response
def login_response(self, request, user):
session = self.create_session(request, user)
request.cache.session = session
token = to_string(session.encoded)
request.response.status_code = 201
return Json({'success': True,
'token': token}).http_response(request)
示例2: decript
def decript(self, password=None):
if password:
p = self.crypt_module.decrypt(to_bytes(password, self.encoding),
self.secret_key)
return to_string(p, self.encoding)
else:
return UNUSABLE_PASSWORD
示例3: parse_info
def parse_info(response):
info = {}
response = to_string(response)
def get_value(value):
if "," not in value or "=" not in value:
try:
if "." in value:
return float(value)
else:
return int(value)
except ValueError:
return value
else:
sub_dict = {}
for item in value.split(","):
k, v = item.rsplit("=", 1)
sub_dict[k] = get_value(v)
return sub_dict
for line in response.splitlines():
if line and not line.startswith("#"):
key, value = line.split(":", 1)
info[key] = get_value(value)
return info
示例4: _form_message
def _form_message(self, container, key, msg):
if msg:
msg = to_string(msg)
if key in container:
container[key].append(msg)
else:
container[key] = [msg]
示例5: values
def values(self, bfield):
'''Generator of values in select'''
for o in self.all(bfield):
if isinstance(o, Widget):
v = o.attr('value')
else:
v = to_string(o[0])
yield v
示例6: _to_string
def _to_string(self, value):
if isinstance(value, Mapping):
raise BuildError('A dictionary found when coverting to string')
elif isinstance(value, (list, tuple)):
return ', '.join(self._to_string(v) for v in value)
elif isinstance(value, date):
return iso8601(value)
else:
return to_string(value)
示例7: to_string
def to_string(self, stream):
'''Once the :class:`.Future`, returned by :meth:`content`
method, is ready, this method get called to transform the stream into
the content string. This method can be overwritten by derived classes.
:param stream: a collections containing ``strings/bytes`` used to
build the final ``string/bytes``.
:return: a string or bytes
'''
return to_string(''.join(stream_to_string(stream)))
示例8: to_string
def to_string(self, streams):
'''Called to transform the collection of
``streams`` into the content string.
This method can be overwritten by derived classes.
:param streams: a collection (list or dictionary) containing
``strings/bytes`` used to build the final ``string/bytes``.
:return: a string or bytes
'''
return to_string(''.join(stream_to_string(streams)))
示例9: _render_meta
def _render_meta(self, value, context):
if isinstance(value, Mapping):
return dict(((k, self._render_meta(v, context))
for k, v in value.items()))
elif isinstance(value, (list, tuple)):
return [self._render_meta(v, context) for v in value]
elif isinstance(value, date):
return value
elif value is not None:
return self._engine(to_string(value), context)
示例10: _clean_simple
def _clean_simple(self, value, bfield):
'''Invoked by :meth:`clean` if :attr:`model` is not defined.'''
choices = self.choices
if hasattr(choices, '__call__'):
choices = choices(bfield)
if not isinstance(choices, Mapping):
choices = dict(choices)
values = value if self.multiple else (value,)
for v in values:
v = to_string(v)
if v not in choices:
raise ValidationError('%s is not a valid choice' % v)
return value
示例11: broadcast
def broadcast(self, channel, message):
'''Broadcast ``message`` to all :attr:`clients`.'''
remove = set()
channel = to_string(channel)
message = self.decode(message)
clients = tuple(self.clients)
for client in clients:
try:
client(channel, message)
except Exception:
LOGGER.exception('Exception while processing pub/sub client. '
'Removing it.')
remove.add(client)
self.clients.difference_update(remove)
示例12: dataReceived
def dataReceived(self, data):
sep = self.separator
idx = data.find(sep)
if idx >= 0:
if self.buffer:
msg = self.buffer + msg
self.buffer = b''
id, msg, data = data[:8], data[8:idx], data[idx+len(sep):]
d = self.requests.pop(id)
d.callback(to_string(msg))
if data:
self.dataReceived(data)
else:
self.buffer += data
示例13: _clean
def _clean(self, value, bfield):
try:
value = to_string(value)
except Exception:
raise ValidationError
if self.toslug:
value = slugify(value, self.toslug)
if self.char_transform:
if self.char_transform == 'u':
value = value.upper()
else:
value = value.lower()
if self.required and not value:
raise ValidationError(
self.validation_error.format(bfield.name, value))
return value
示例14: broadcast
def broadcast(self, response):
'''Broadcast ``message`` to all :attr:`clients`.'''
remove = set()
channel = to_string(response[0])
message = response[1]
if self._protocol:
message = self._protocol.decode(message)
for client in self._clients:
try:
client(channel, message)
except IOError:
remove.add(client)
except Exception:
self._loop.logger.exception(
'Exception while processing pub/sub client. Removing it.')
remove.add(client)
self._clients.difference_update(remove)
示例15: execute
def execute(self, request):
'''Execute a new ``request``.
'''
handle = None
if request:
request[0] = command = to_string(request[0]).lower()
info = COMMANDS_INFO.get(command)
if info:
handle = getattr(self.store, info.method_name)
#
if self.channels or self.patterns:
if command not in self.store.SUBSCRIBE_COMMANDS:
return self.reply_error(self.store.PUBSUB_ONLY)
if self.blocked:
return self.reply_error('Blocked client cannot request')
if self.transaction is not None and command not in 'exec':
self.transaction.append((handle, request))
return self._transport.write(self.store.QUEUED)
self._execute_command(handle, request)