def delete_rscref_rset(c_obj, rsc_id): ''' Drop all reference to rsc_id. ''' c_modified = False l = [] for rref in c_obj.node.xpath("resource_set/resource_ref"): if rsc_id == rref.get("id"): l.append(rref) c_obj.updated = True c_modified = True rmnodes(l) l = [] cnt = 0 nonseq_rset = False for rset in c_obj.node.findall("resource_set"): rref_cnt = len(rset.findall("resource_ref")) if rref_cnt == 0: l.append(rset) c_obj.updated = True c_modified = True elif not get_boolean(rset.get("sequential"), True) and rref_cnt > 1: nonseq_rset = True cnt += rref_cnt rmnodes(l) if not nonseq_rset and cnt == 2: rset_convert(c_obj) return c_modified
def set_public_command(instance, player, arguments): """ Set the public membership field for an instance. Args: instance: The GameInstance database model to change. player: The player requesting the change. This player must be the current leader of the instance. arguments: A single item list containing the desired boolean value for the public field of instance. A public game can be joined by players without first being invited. Changing the value of public does not change the current membership of the game. Returns: The new value of public for the instance. Raises: ValueError if the requesting player is not the leader of the instance. ValueError if the argument is unable to be parsed into a boolean. """ instance.check_leader(player) value = utils.get_boolean(arguments[0]) instance.public = value return value
def parseattr(self, p): attrs = {"sequential": "sequential", "require-all": "require_all"} l = p.split('=') if len(l) != 2 or l[0] not in attrs: return False k, v = l if not verify_boolean(v): return False setattr(self, attrs[k], get_boolean(v)) return True
def test_booleans(): truthy = ['yes', 'Yes', 'True', 'true', 'TRUE', 'YES', 'on', 'On', 'ON'] falsy = ['no', 'false', 'off', 'OFF', 'FALSE', 'nO'] not_truthy = ['', 'not', 'ONN', 'TRUETH', 'yess'] for case in chain(truthy, falsy): assert utils.verify_boolean(case) is True for case in truthy: assert utils.is_boolean_true(case) is True assert utils.is_boolean_false(case) is False assert utils.get_boolean(case) is True for case in falsy: assert utils.is_boolean_true(case) is False assert utils.is_boolean_false(case) is True assert utils.get_boolean(case, dflt=True) is False for case in not_truthy: assert utils.verify_boolean(case) is False assert utils.is_boolean_true(case) is False assert utils.is_boolean_false(case) is False assert utils.get_boolean(case) is False
def post(self): """ Execute new_instance and write the response to the handler. Request parameters: gid: The game id of the parent Game. iid: The proposed instance id of the new instance. The instance id of the created instance could differ from this if the proposed id is already in use. pid: The player id of the requesting player. make_public: A boolean indicating whether this instance should be able to be seen and joined by anyone. """ logging.debug('/newinstance?%s\n|%s|' % (self.request.query_string, self.request.body)) gid = self.request.get(GAME_ID_KEY) iid = self.request.get(INSTANCE_ID_KEY) pid = self.request.get(PLAYER_ID_KEY) make_public = False try: make_public = utils.get_boolean(self.request.get(INSTANCE_PUBLIC_KEY)) except ValueError: pass run_with_response_as_transaction(self, new_instance, gid, iid, pid, make_public)
def boolean_maybe(v): "returns True/False or None" if v is None: return None return utils.get_boolean(v)