def test_simple_serialize(self): tuple = create_table([1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000], 0) table = tuple[1] state = TableState(table) str = dumps(state) new_state = loads(str) self.assertEquals(state.name, new_state.name) self.assertEquals(10, len(new_state.seats))
def prompt_player(self, table, username, actions): """ Called by a table to prompt a player with a list of actions. """ log_msg = "Table %s: Prompting %s with actions:" % (table.id, username) serialized_actions = [] for action in actions: log_msg += "\n %s" % action serialized_actions.append(dumps(action)) logger.debug(log_msg) self.users[username].prompt(table.id, serialized_actions)
def open_table(self, table_id, user): """ Subscribe a user to a table. Returns a tuple of the user's newly created table view, and a TableState snapshot the client can use to draw the current table state. """ logger.debug("Opening table %s for user %s" % (table_id, user.username)) # TODO: check if user should be allowed to observe this table. table = self.table_views[table_id].table table.add_observer(user.username) state = TableState(table) return (self.table_views[table_id], dumps(state))
def list_tables(self): """ Returns a list of visible tables to the client. """ tables = [] for t in self.table_views.values(): tables.append(dumps(TableListing(t.table))) return tables
def notify(self, table_id, username, event): serialized_event = dumps(event) self.users[username].notify(table_id, serialized_event)