text
stringlengths 0
828
|
|---|
4583,"def to_unicode(obj, encoding='utf-8'):
|
""""""Convert obj to unicode (if it can be be converted)
|
from http://farmdev.com/talks/unicode/""""""
|
if isinstance(obj, basestring):
|
if not isinstance(obj, unicode):
|
obj = unicode(obj, encoding)
|
return obj"
|
4584,"def besttype(x, encoding=""utf-8"", percentify=True):
|
""""""Convert string x to the most useful type, i.e. int, float or unicode string.
|
If x is a quoted string (single or double quotes) then the quotes are
|
stripped and the enclosed string returned. The string can contain any
|
number of quotes, it is only important that it begins and ends with either
|
single or double quotes.
|
*percentify* = ``True`` turns ""34.4%"" into the float 0.344.
|
.. Note::
|
Strings will be returned as Unicode strings (using
|
:func:`unicode`), based on the *encoding* argument, which is
|
utf-8 by default.
|
""""""
|
def unicodify(x):
|
return to_unicode(x, encoding)
|
def percent(x):
|
try:
|
if x.endswith(""%""):
|
x = float(x[:-1]) / 100.
|
else:
|
raise ValueError
|
except (AttributeError, ValueError):
|
raise ValueError
|
return x
|
x = unicodify(x) # make unicode as soon as possible
|
try:
|
x = x.strip()
|
except AttributeError:
|
pass
|
m = re.match(r""""""(?P<quote>['""])(?P<value>.*)(?P=quote)$"""""", x) # matches ""<value>"" or '<value>' where <value> COULD contain "" or '!
|
if m is None:
|
# not a quoted string, try different types
|
for converter in int, float, percent, unicodify: # try them in increasing order of lenience
|
try:
|
return converter(x)
|
except ValueError:
|
pass
|
else:
|
# quoted string
|
x = unicodify(m.group('value'))
|
return x"
|
4585,"def _onsuccess(cls, kmsg, result):
|
"""""" To execute on execution success
|
:param kser.schemas.Message kmsg: Kafka message
|
:param kser.result.Result result: Execution result
|
:return: Execution result
|
:rtype: kser.result.Result
|
""""""
|
logger.info(
|
""{}.Success: {}[{}]: {}"".format(
|
cls.__name__, kmsg.entrypoint, kmsg.uuid, result
|
),
|
extra=dict(
|
kmsg=kmsg.dump(),
|
kresult=ResultSchema().dump(result) if result else dict()
|
)
|
)
|
return cls.onsuccess(kmsg, result)"
|
4586,"def _onerror(cls, kmsg, result):
|
"""""" To execute on execution failure
|
:param kser.schemas.Message kmsg: Kafka message
|
:param kser.result.Result result: Execution result
|
:return: Execution result
|
:rtype: kser.result.Result
|
""""""
|
logger.error(
|
""{}.Failed: {}[{}]: {}"".format(
|
cls.__name__, kmsg.entrypoint, kmsg.uuid, result
|
),
|
extra=dict(
|
kmsg=kmsg.dump(),
|
kresult=ResultSchema().dump(result) if result else dict()
|
)
|
)
|
return cls.onerror(kmsg, result)"
|
4587,"def _onmessage(cls, kmsg):
|
"""""" Call on received message
|
:param kser.schemas.Message kmsg: Kafka message
|
:return: Kafka message
|
:rtype: kser.schemas.Message
|
""""""
|
logger.debug(
|
""{}.ReceivedMessage {}[{}]"".format(
|
cls.__name__, kmsg.entrypoint, kmsg.uuid
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.