コード例 #1
0
 def test_uri_errors(self):
     for test_str, err in parsed_uri_raises:
         try:
             URI.from_uri_string(test_str)
         except URIParseError:
             pass
         else:
             print("\nSuccessfully parsed invalid url: " + test_str)
         self.assertRaises(err, URI.from_uri_string, test_str)
コード例 #2
0
    def test_uri_parse(self):
        for test_string, expected_uri_obj, is_channel in parsed_uri_matches:
            try:
                # string -> URI
                self.assertEqual(URI.from_uri_string(test_string), expected_uri_obj, test_string)
                # URI -> dict -> URI
                self.assertEqual(URI.from_dict(expected_uri_obj.to_dict()), expected_uri_obj,
                                  test_string)
                # is_channel
                self.assertEqual(URI.from_uri_string(test_string).is_channel, is_channel,
                                  test_string)

                # convert-to-string test only works if protocol is present in test_string
                if test_string.startswith('lbry://'):
                    # string -> URI -> string
                    self.assertEqual(URI.from_uri_string(test_string).to_uri_string(), test_string,
                                      test_string)
                    # string -> URI -> dict -> URI -> string
                    uri_dict = URI.from_uri_string(test_string).to_dict()
                    self.assertEqual(URI.from_dict(uri_dict).to_uri_string(), test_string,
                                      test_string)
                    # URI -> dict -> URI -> string
                    self.assertEqual(URI.from_dict(expected_uri_obj.to_dict()).to_uri_string(),
                                      test_string, test_string)
            except URIParseError as err:
                print("ERROR: " + test_string)
                raise
コード例 #3
0
from .test_data import nist384p_private_key, claim_010_signed_nist384p, nist384p_cert
from .test_data import secp256k1_private_key, claim_010_signed_secp256k1, secp256k1_cert
from .test_data import hex_encoded_003, decoded_hex_encoded_003, malformed_secp256k1_cert
from lbrynet import schema
from lbrynet.schema.claim import ClaimDict
from lbrynet.schema.schema import NIST256p, NIST384p, SECP256k1
from lbrynet.schema.legacy.migrate import migrate
from lbrynet.schema.signer import get_signer
from lbrynet.schema.uri import URI, URIParseError
from lbrynet.schema.decode import smart_decode
from lbrynet.schema.error import DecodeError, InvalidAddress
from lbrynet.schema.address import decode_address, encode_address


parsed_uri_matches = [
    ("test", URI("test"), False),
    ("test#%s" % claim_id_1, URI("test", claim_id=claim_id_1), False),
    ("test:1", URI("test", claim_sequence=1), False),
    ("test$1", URI("test", bid_position=1), False),
    ("lbry://test", URI("test"), False),
    ("lbry://test#%s" % claim_id_1, URI("test", claim_id=claim_id_1), False),
    ("lbry://*****:*****@test", URI("@test"), True),
    ("@test#%s" % claim_id_1, URI("@test", claim_id=claim_id_1), True),
    ("@test:1", URI("@test", claim_sequence=1), True),
    ("@test$1", URI("@test", bid_position=1), True),
    ("lbry://@test1:1/fakepath", URI("@test1", claim_sequence=1, path="fakepath"), True),
    ("lbry://@test1$1/fakepath", URI("@test1", bid_position=1, path="fakepath"), True),
    ("lbry://@test1#abcdef/fakepath", URI("@test1", claim_id="abcdef", path="fakepath"), True),
    ("@z", URI("@z"), True),