| @@ 315-342 (lines=28) @@ | ||
| 312 |     hardware = HardwareField('HardWare') | |
| 313 | ||
| 314 | ||
| 315 | def create_reply(reply, message=None, render=False): | |
| 316 | """ | |
| 317 | Create a reply quickly | |
| 318 | """ | |
| 319 | r = None | |
| 320 | if not reply: | |
| 321 | r = EmptyReply() | |
| 322 | elif isinstance(reply, BaseReply): | |
| 323 | r = reply | |
| 324 | if message: | |
| 325 | r.source = message.target | |
| 326 | r.target = message.source | |
| 327 | elif isinstance(reply, six.string_types): | |
| 328 | r = TextReply( | |
| 329 | message=message, | |
| 330 | content=reply | |
| 331 | ) | |
| 332 | elif isinstance(reply, (tuple, list)): | |
| 333 | if len(reply) > 10: | |
| 334 |             raise AttributeError("Can't add more than 10 articles" | |
| 335 | " in an ArticlesReply") | |
| 336 | r = ArticlesReply( | |
| 337 | message=message, | |
| 338 | articles=reply | |
| 339 | ) | |
| 340 | if r and render: | |
| 341 | return r.render() | |
| 342 | return r | |
| 343 | ||
| 344 | ||
| 345 | def deserialize_reply(xml, update_time=False): | |
| @@ 45-68 (lines=24) @@ | ||
| 42 |     agent = IntegerField('AgentID', 0) | |
| 43 | ||
| 44 | ||
| 45 | def create_reply(reply, message=None, render=False): | |
| 46 | r = None | |
| 47 | if isinstance(reply, replies.BaseReply): | |
| 48 | r = reply | |
| 49 | if message: | |
| 50 | r.source = message.target | |
| 51 | r.target = message.source | |
| 52 | r.agent = message.agent | |
| 53 | elif isinstance(reply, six.string_types): | |
| 54 | r = TextReply( | |
| 55 | message=message, | |
| 56 | content=reply | |
| 57 | ) | |
| 58 | elif isinstance(reply, (tuple, list)): | |
| 59 | if len(reply) > 10: | |
| 60 |             raise AttributeError("Can't add more than 10 articles" | |
| 61 | " in an ArticlesReply") | |
| 62 | r = ArticlesReply( | |
| 63 | message=message, | |
| 64 | articles=reply | |
| 65 | ) | |
| 66 | if r and render: | |
| 67 | return r.render() | |
| 68 | return r | |
| 69 | ||