def test_valid_sublist(self): """subscription_list_is_valid parse proper json and abort when it sees invalid json data""" sys.stdout = self.capture goodsubfile = """ { "pb://vysqjw7x7hfiuozjsggpd5lmyj35pggu@iyawu4w66gd2356vguey2veyn7jbpyzqgpmb74wd2gxzvkuzbxya.b32.i2p/introducer": { "name": "duck", "contact": "<[email protected]> (http://duck.i2p)", "active": false, "reasonRemoved": "This node has been down for a long time now and has therefore been disabled. We're patiently awaiting duck's return though." } } """ badsubfile = """ { "pb://vysqjw7x7hfiuozjsggpd5lmyj35pggu@iyawu4w66gd2356vguey2veyn7jbpyzqgpmb74wd2gxzvkuzbxya.b32.i2p/introducer": "name": "duck", "reasonRemoved": "This node has been down for a long time now and has therefore been disabled. We're patiently awaiting duck's return though." } } """ self.assertFalse(functions.subscription_list_is_valid(badsubfile)) self.assertTrue(functions.subscription_list_is_valid(goodsubfile))
def create_intro_dict(self, json_response): """Compile a dictionary of introducers (uri->name,active) from a JSON object.""" intro_dict = {} try: new_list = json_response.read().decode('utf8') except: # TODO specific exception print("ERROR: Couldn't read introducer list.", file=sys.stderr) return if not subscription_list_is_valid(new_list, self.verbosity): return for uri in json.loads(new_list).keys(): name = json.loads(new_list)[uri]['name'] active = json.loads(new_list)[uri]['active'] if is_valid_introducer(uri): if self.verbosity > 2: print('DEBUG: Valid introducer address: %s' % uri) intro_dict[uri] = (name, active) else: if self.verbosity > 0: print("WARN: '%s' is not a valid Tahoe-LAFS introducer " "address. Skipping.") return intro_dict
def dl_sharelist(self): """ Attempt to retrieve sharelist from the grid. If the sharelist is determined to be valid, the sharelist is returned. """ shares = tahoe_dl_file(self.subscription_uri, self.verbosity).read().decode('utf8') if subscription_list_is_valid(shares, self.verbosity): return shares else: return