本文整理汇总了Python中util.Util.empty_str方法的典型用法代码示例。如果您正苦于以下问题:Python Util.empty_str方法的具体用法?Python Util.empty_str怎么用?Python Util.empty_str使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类util.Util
的用法示例。
在下文中一共展示了Util.empty_str方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: callback
# 需要导入模块: from util import Util [as 别名]
# 或者: from util.Util import empty_str [as 别名]
def callback(self, cmd, msg):
if Util.empty_str(msg):
cancel_flag = u"取消"
finish_flag = u"完成"
self._home.publish_msg(
cmd
, u"请输入内容, 输入\"%s\"或\"%s\"结束:" % (finish_flag, cancel_flag)
, cmd_type="input"
)
msg = UserInput(self._home).waitForInput(
finish=finish_flag,
cancel=cancel_flag)
if msg is None:
self._home.publish_msg(cmd, u"无翻译内容")
elif len(msg) > 200:
self._home.publish_msg(cmd, u"翻译内容过长(<200字)")
else:
try:
values = {
"keyfrom":"11111testt111",
"key":"2125866912",
"type":"data",
"doctype":"json",
"version":"1.1",
"q":msg.encode("utf-8")
}
url = translate_callback.base_url + "?" + urllib.urlencode(values)
res = urllib2.urlopen(url).read()
res = " ".join(json.loads(res)["translation"])
self._home.publish_msg(cmd, u"翻译结果:\n" + res)
except Exception, ex:
ERROR("request error:", ex)
self._home.publish_msg(cmd, u"翻译失败")
return True
示例2: callback
# 需要导入模块: from util import Util [as 别名]
# 或者: from util.Util import empty_str [as 别名]
def callback(self, cmd, action, target, msg, pre_value):
if Util.empty_str(target):
INFO("empty location target.")
self._home.publish_msg(cmd, u"无定位目标")
return False
INFO("send location request to %s" % target)
self._home.publish_msg(cmd, u"发起定位:%s" % target)
self._home.publish_msg(cmd, target, cmd_type="req_loc")
return True, "location"
示例3: callback
# 需要导入模块: from util import Util [as 别名]
# 或者: from util.Util import empty_str [as 别名]
def callback(self, cmd, action, target, msg, pre_value):
if Util.empty_str(target):
INFO("empty geo location target.")
return False
if msg is None or len(msg) == 0:
INFO("send geo location request to %s" % target)
# self._home.publish_msg(cmd, u"发起定位:%s" % target)
self._home.publish_msg(cmd, target, cmd_type="req_geo")
return True, "geo_location"
else:
return True