本文整理汇总了Python中entities.Entity.list方法的典型用法代码示例。如果您正苦于以下问题:Python Entity.list方法的具体用法?Python Entity.list怎么用?Python Entity.list使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类entities.Entity
的用法示例。
在下文中一共展示了Entity.list方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_40_list
# 需要导入模块: from entities import Entity [as 别名]
# 或者: from entities.Entity import list [as 别名]
def test_40_list(self):
for e in Entity.list(None, None): print e
for e in Entity.list(100, None): print e
for e in Entity.list(101, None): print e
for e in Entity.list(None, 'Power%'): print e
for e in Entity.list(101, 'Power%'): print e
for e in Entity.list(100, 'Power%'): print e
print 'Serialized:'
for e in Entity.list(None, None):
print e.serialize()
print 'As list:'
rsp = ''
for e in Entity.list(None, None):
rsp = rsp + e.serialize() + ','
if len(rsp) > 0:
rsp = rsp[0:-1]
rsp = '[' + rsp + ']'
print rsp
示例2: handle_received_message
# 需要导入模块: from entities import Entity [as 别名]
# 或者: from entities.Entity import list [as 别名]
def handle_received_message(self, handler, sender, header, message):
''' Handles received messages from client connections. '''
if header == Header.MSG_A_LOGIN:
if ClientModule.DEBUG:
print 'Login Message received from', sender, ':', header, message
try:
username, password = message.split(':')
session_id, admin = Authentication.instance().authenticate(username, password)
if session_id is not None:
handler.authentication_succeeded(session_id, sender)
self.respond(handler, header, session_id + ('*' if admin else ''), sender)
else:
handler.authentication_failed(sender)
except:
handler.authentication_failed(sender)
# needs session checking
elif handler.is_valid_session(message, sender):
original_message = message
message = handler.strip_session_prefix(message)
if ClientModule.DEBUG:
print 'Message received from', sender, ':', header,
print '\'' + message + '\'',
print '| original was', '\'' + original_message + '\''
if header == Header.MSG_A_KEEPALIVE:
self.respond(handler, header, None, sender)
elif header == Header.MSG_A_LIST_DEVICE_TYPES:
rsp = ''
for t in EntityType.all():
rsp = rsp + t.serialize() + ','
if len(rsp) > 0:
rsp = rsp[0:-1]
rsp = '[' + rsp + ']'
self.respond(handler, header, rsp, sender)
elif header == Header.MSG_A_LIST_DEVICES:
typeid, name_pattern = None, None
if re.match('^[0-9]+;.*$', message):
typeid, name_pattern = message.split(';')
typeid = int(typeid)
elif re.match('^[0-9]+', message):
typeid = int(message)
elif len(message) > 0:
name_pattern = message
rsp = ''
for e in Entity.list(typeid, name_pattern):
rsp = rsp + e.serialize() + ','
if len(rsp) > 0:
rsp = rsp[0:-1]
rsp = '[' + rsp + ']'
self.respond(handler, header, rsp, sender)
elif header == Header.MSG_A_SEND_COMMAND:
entity_id, cmd = message.split('#')
cmd_param = None
if ';' in cmd:
cmd, cmd_param = cmd.split(';')
entity = Entity.find(entity_id)
if entity:
command = EntityCommand.find( int(cmd) )
if command:
entity.control(self, command, cmd_param)
self.respond(handler, header, None, sender)
else:
self.respond(handler, Header.MSG_A_ERROR, _('error.not.found.command') + ': ' + str(cmd), sender)
else:
self.respond(handler, Header.MSG_A_ERROR, _('error.not.found.device') + ': ' + str(entity_id), sender)
elif header == Header.MSG_A_LOAD_TYPE_IMAGE:
imgname = message
content = None
image_path = self.__find_image_path(imgname)
if image_path:
imgfile = file(image_path)
try:
content = base64.b64encode(imgfile.read())
finally:
imgfile.close()
if content:
self.respond(handler, header, content, sender)
else:
self.respond(handler, Header.MSG_A_ERROR, _('error.load.image') + ': ' + imgname, sender)
elif header == Header.MSG_A_RENAME_DEVICE:
eid, name = message.split(';', 1)
entity = Entity.find(eid)
#.........这里部分代码省略.........