def decode_furl(furl): """Returns (encrypted, tubID, location_hints, name)""" # pb://key@{ip:port,host:port,[ipv6]:port}[/unix]/swissnumber # i.e. pb://tubID@{locationHints..}/name # # it can live at any one of a (TODO) variety of network-accessible # locations, or (TODO) at a single UNIX-domain socket. # # there is also an unauthenticated form, which does not have a TubID mo_auth_furl = AUTH_STURDYREF_RE.search(furl) mo_nonauth_furl = NONAUTH_STURDYREF_RE.search(furl) if mo_auth_furl: encrypted = True # we only pay attention to the first 32 base32 characters # of the tubid string. Everything else is left for future # extensions. tubID_s = mo_auth_furl.group(1) tubID = tubID_s[:32] if not base32.is_base32(tubID): raise BadFURLError("'%s' is not a valid tubid" % (tubID,)) hints = mo_auth_furl.group(2) location_hints = decode_location_hints(hints) name = mo_auth_furl.group(3) elif mo_nonauth_furl: encrypted = False tubID = None hints = mo_nonauth_furl.group(1) location_hints = decode_location_hints(hints) name = mo_nonauth_furl.group(2) else: raise ValueError("unknown FURL prefix in %r" % (furl,)) return (encrypted, tubID, location_hints, name)
def decode_furl(furl): """Returns (tubID, location_hints, name)""" # pb://key@{ip:port,host:port,[ipv6]:port}[/unix]/swissnumber # i.e. pb://tubID@{locationHints..}/name # # it can live at any one of a (TODO) variety of network-accessible # locations, or (TODO) at a single UNIX-domain socket. mo_auth_furl = AUTH_STURDYREF_RE.search(furl) if mo_auth_furl: # we only pay attention to the first 32 base32 characters # of the tubid string. Everything else is left for future # extensions. tubID_s = mo_auth_furl.group(1) tubID = tubID_s[:32] if not base32.is_base32(tubID): raise BadFURLError("'%s' is not a valid tubid" % (tubID,)) hints = mo_auth_furl.group(2) location_hints = hints.split(",") if location_hints == [""]: location_hints = [] if "" in location_hints: raise BadFURLError("no connection hint may be empty") # it is legal to have no hints at all: an empty string turns into an # empty list name = mo_auth_furl.group(3) else: raise ValueError("unknown FURL prefix in %r" % (furl,)) return (tubID, location_hints, name)
def decode_furl(furl): """Returns (tubID, location_hints, name)""" # pb://key@{ip:port,host:port,[ipv6]:port}[/unix]/swissnumber # i.e. pb://tubID@{locationHints..}/name # # it can live at any one of a (TODO) variety of network-accessible # locations, or (TODO) at a single UNIX-domain socket. mo_auth_furl = AUTH_STURDYREF_RE.search(furl) if mo_auth_furl: # we only pay attention to the first 32 base32 characters # of the tubid string. Everything else is left for future # extensions. tubID_s = mo_auth_furl.group(1) tubID = tubID_s[:32] if not base32.is_base32(tubID): raise BadFURLError("'%s' is not a valid tubid" % (tubID, )) hints = mo_auth_furl.group(2) location_hints = hints.split(",") if location_hints == [""]: location_hints = [] if "" in location_hints: raise BadFURLError("no connection hint may be empty") # it is legal to have no hints at all: an empty string turns into an # empty list name = mo_auth_furl.group(3) else: raise ValueError("unknown FURL prefix in %r" % (furl, )) return (tubID, location_hints, name)
def test_is_base32(self): self.failUnless(base32.is_base32("abc456")) self.failUnless(base32.is_base32("456")) self.failUnless(base32.is_base32("")) self.failIf(base32.is_base32("123")) # 1 is not in rfc4648 base32 self.failIf(base32.is_base32(".123")) self.failIf(base32.is_base32("_")) self.failIf(base32.is_base32("a b c"))
def test_is_base32(self): self.assertTrue(base32.is_base32("abc456")) self.assertTrue(base32.is_base32("456")) self.assertTrue(base32.is_base32("")) self.assertFalse(base32.is_base32("123")) # 1 is not in rfc4648 base32 self.assertFalse(base32.is_base32(".123")) self.assertFalse(base32.is_base32("_")) self.assertFalse(base32.is_base32("a b c"))