- 9E92E286E45F8D293DF0EF2126DBCD90E95FD853434D94FA37E55705D2DC7517CF768ACAD7B54029A666926E2E489541EBBE618334600B8166EE8898FD01D094
+ 9C0C2889E379F46AD66B27BE027EA4C37355442DEF1D39B79EADBBBEB437D3729D847F3F66D8F829410BD48A334F7468F772FF8B4C21835EE5999DDF0BB15760
blatta/lib/channel.py
(5 . 58)(5 . 11)
474 self.server = server
475 self.name = name
476 self.members = set()
477 self._topic = ""
478 self._key = None
479 if self.server.statedir:
480 self._state_path = "%s/%s" % (
481 self.server.statedir,
482 name.replace("_", "__").replace("/", "_"))
483 self._read_state()
484 else:
485 self._state_path = None
486
487 def add_member(self, client):
488 self.members.add(client)
489
490 def get_topic(self):
491 return self._topic
492
493 def set_topic(self, value):
494 self._topic = value
495 self._write_state()
496
497 topic = property(get_topic, set_topic)
498
499 def get_key(self):
500 return self._key
501
502 def set_key(self, value):
503 self._key = value
504 self._write_state()
505
506 key = property(get_key, set_key)
507
508 def remove_client(self, client):
509 self.members.discard(client)
510 if not self.members:
511 self.server.remove_channel(self)
512
513 def _read_state(self):
514 if not (self._state_path and os.path.exists(self._state_path)):
515 return
516 data = {}
517 exec(open(self._state_path), {}, data)
518 self._topic = data.get("topic", "")
519 self._key = data.get("key")
520
521 def _write_state(self):
522 if not self._state_path:
523 return
524 (fd, path) = tempfile.mkstemp(dir=os.path.dirname(self._state_path))
525 fp = os.fdopen(fd, "w")
526 fp.write("topic = %r\n" % self.topic)
527 fp.write("key = %r\n" % self.key)
528 fp.close()
529 os.rename(path, self._state_path)
530
531