def from_identifier(self, identifier): components = identifier.split("-") if len(components) == 2: (board_number_string, deal_and_history_identifier) = components if ':' in deal_and_history_identifier: deal_identifier, call_history_identifier = deal_and_history_identifier.split(':') # We have to do a bit of a dance to convert from the board url system that # the JS code uses to the one the python uses. call_history = CallHistory.from_board_number_and_calls_string(int(board_number_string), call_history_identifier) else: deal_identifier = deal_and_history_identifier call_history = CallHistory.empty_for_board_number(int(board_number_string)) else: (board_number_string, deal_identifier, call_history_identifier) = components call_history = CallHistory.from_identifier(call_history_identifier) board_number = int(board_number_string) deal = Deal.from_identifier(deal_identifier) return Board(number=board_number, deal=deal, call_history=call_history)
def test_identifier(self): deal = Deal.from_string("23456789TJQKA... .23456789TJQKA.. ..23456789TJQKA. ...23456789TJQKA") self.assertEquals(deal.identifier(), '0000001555555aaaaaabffffff') self.assertEquals(deal.pretty_one_line(), Deal.from_identifier(deal.identifier()).pretty_one_line())