def give_advice(self, player, group, action, **info): if player not in self._advice: self._advice[player] = tlist() advice = info advice.update({'group': group, 'action': action}) self._advice[player].append(advice)
def unjsonify(obj, tfm=None): ''' Convert from a json readable python data structure (containing dict, list, tuples, humpack objects etc.) to a json conpatible object (only dicts, lists, and primitives). :param obj: Input data structure to be unjsonified :param tfm: Custom transform function to unjsonify certain data structures (use with caution) ''' if tfm is not None: try: return tfm(obj, unjsonify) except UnknownElementError: pass if isinstance(obj, primitive): return obj if isinstance(obj, list): return tlist([unjsonify(o, tfm=tfm) for o in obj]) if isinstance(obj, dict): if len(obj) == 1 and '_tuple' in obj: return tuple(unjsonify(o, tfm=tfm) for o in obj['_tuple']) if len(obj) == 1 and '_set' in obj: return tset(unjsonify(o, tfm=tfm) for o in obj['_set']) if len(obj) == 2 and '_ndarray' in obj and '_dtype' in obj: return np.array(unjsonify(obj['_ndarray'], tfm=tfm), dtype=obj['_dtype']) return tdict({k: unjsonify(v, tfm=tfm) for k, v in obj.items()}) raise UnknownElementError(obj)
def __unpack__(self, data): self.players = unpack_member(data['players']) self.players_list = tlist(self.players.values()) self._in_transaction = unpack_member(data['_in_transaction']) self.meta_info = unpack_member(data['meta_info']) self.default_player = unpack_member(data['default_player']) self.force_player_type = unpack_member(data['force_player_type']) self.hide_name = unpack_member(data['hide_name'])
def __init__(self, indent_level=None, debug=False, end='\n'): super().__init__() self.text = tlist() self.debug = debug self.indent_level = indent_level self._shadow_indent = None self._in_transaction = None self.end = end
def test_init(): ''' Test creating some standard humpack objects ''' x = tdict() assert len(x) == 0 x = tlist() assert len(x) == 0 x = tset() assert len(x) == 0
def __init__(self, indent_level=None, debug=False, end='\n'): self.log = tlist() self.update = None self.debug = debug self.indent_level = indent_level self.end = end self._shadow = None self.players = None self.targets = None
def __init__( self, force_include_type=False, hide_name=False, ): super().__init__() self.force_player_type = force_include_type self.hide_name = hide_name self.players = tdict() self.players_list = tlist() self.meta_info = tdict() self._in_transaction = False
def get_tdict(): x = tdict() x.a = 1 x.x = x x.l = [tlist(), tset()] x[100] = '100' x[None] = 1.2 x.m = None x[True] = tlist x[list] = complex x['<>)dksfl_ ds: gkal'] = '<>1234543224' x['d = ds=a _+ sd;'] = bytes(range(256)) x[12.2344 + .023j] = range(123, 456, 7) # np.random.seed(1) # x.b = np.random.randn(3).tobytes() x[b'\xaa'] = 'running' return x
def _process_msg(self): if 'error' in self.msg: print('*** ERROR: {} ***'.format(self.msg.error.type)) print(self.msg.error.msg) print('****************************') if 'end' in self.msg: self.in_progress = False if 'options' in self.msg: self.actions = tlist() for name, opts in self.msg.options.items(): self.actions.extend( (name, action) for action in decode_action_set(opts.actions)) if 'key' in self.msg: self.key = self.msg.key
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.log = tlist()
def sort_by(ls, order): return tlist(x[0] for x in sorted(zip(ls, order), key=lambda x: x[1]))
def get(self, n=None): objs = tlist(self._registered(x) for x in self._get(1 if n is None else n)) if n is None: return objs[0] return objs
def reset(self, ctrl): self.players = tlist(ctrl.manager)
def reset(self, ctrl): self.players = tlist(ctrl.manager.names()) # TODO maybe change to full player objects self.clear() self.update = tdict({player:tlist() for player in self.players})