Exemplo n.º 1
0
def test_base36():
    assert [base36_encode(x) for x in range(128)] == [
        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
        'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
        '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '1A', '1B', '1C', '1D', '1E',
        '1F', '1G', '1H', '1I', '1J', '1K', '1L', '1M', '1N', '1O', '1P', '1Q', '1R', '1S', '1T',
        '1U', '1V', '1W', '1X', '1Y', '1Z', '20', '21', '22', '23', '24', '25', '26', '27', '28',
        '29', '2A', '2B', '2C', '2D', '2E', '2F', '2G', '2H', '2I', '2J', '2K', '2L', '2M', '2N',
        '2O', '2P', '2Q', '2R', '2S', '2T', '2U', '2V', '2W', '2X', '2Y', '2Z', '30', '31', '32',
        '33', '34', '35', '36', '37', '38', '39', '3A', '3B', '3C', '3D', '3E', '3F', '3G', '3H',
        '3I', '3J'
    ]

    assert [base36_decode(base36_encode(x)) for x in range(128)] == list(map(int, range(128)))
Exemplo n.º 2
0
def test_base36():
    assert [base36_encode(x) for x in range(128)] == [
        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D',
        'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',
        'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '10', '11', '12', '13', '14',
        '15', '16', '17', '18', '19', '1A', '1B', '1C', '1D', '1E', '1F', '1G',
        '1H', '1I', '1J', '1K', '1L', '1M', '1N', '1O', '1P', '1Q', '1R', '1S',
        '1T', '1U', '1V', '1W', '1X', '1Y', '1Z', '20', '21', '22', '23', '24',
        '25', '26', '27', '28', '29', '2A', '2B', '2C', '2D', '2E', '2F', '2G',
        '2H', '2I', '2J', '2K', '2L', '2M', '2N', '2O', '2P', '2Q', '2R', '2S',
        '2T', '2U', '2V', '2W', '2X', '2Y', '2Z', '30', '31', '32', '33', '34',
        '35', '36', '37', '38', '39', '3A', '3B', '3C', '3D', '3E', '3F', '3G',
        '3H', '3I', '3J'
    ]

    assert [base36_decode(base36_encode(x))
            for x in range(128)] == list(map(int, range(128)))
Exemplo n.º 3
0
def process_signature(request, max_age=60 * 60 * 24 * 10):
    """Given a request object this validates the signature from the
    current request and returns the user.
    """
    sig = request.GET.get('_') or request.POST.get('_sentry_request_signature')
    if not sig or sig.count(':') < 2:
        return None

    signed_data = '%s|%s|%s' % (request.build_absolute_uri('/').rstrip('/'), request.path, sig)
    try:
        data = get_signer().unsign(signed_data, max_age=max_age)
    except signing.BadSignature:
        return None

    _, signed_path, user_id = data.rsplit('|', 2)
    if signed_path != request.path:
        return None

    try:
        return User.objects.get(pk=base36_decode(user_id))
    except (ValueError, User.DoesNotExist):
        return None
Exemplo n.º 4
0
def process_signature(request, max_age=60 * 60 * 24 * 10):
    """Given a request object this validates the signature from the
    current request and returns the user.
    """
    sig = request.GET.get("_") or request.POST.get("_sentry_request_signature")
    if not sig or sig.count(":") < 2:
        return None

    signed_data = "{}|{}|{}".format(request.build_absolute_uri("/").rstrip("/"), request.path, sig)
    try:
        data = get_signer().unsign(signed_data, max_age=max_age)
    except signing.BadSignature:
        return None

    _, signed_path, user_id = data.rsplit("|", 2)
    if signed_path != request.path:
        return None

    try:
        return User.objects.get(pk=base36_decode(user_id))
    except (ValueError, User.DoesNotExist):
        return None
Exemplo n.º 5
0
def test_base36():
    assert [base36_encode(x) for x in range(128)] == [
        "0",
        "1",
        "2",
        "3",
        "4",
        "5",
        "6",
        "7",
        "8",
        "9",
        "A",
        "B",
        "C",
        "D",
        "E",
        "F",
        "G",
        "H",
        "I",
        "J",
        "K",
        "L",
        "M",
        "N",
        "O",
        "P",
        "Q",
        "R",
        "S",
        "T",
        "U",
        "V",
        "W",
        "X",
        "Y",
        "Z",
        "10",
        "11",
        "12",
        "13",
        "14",
        "15",
        "16",
        "17",
        "18",
        "19",
        "1A",
        "1B",
        "1C",
        "1D",
        "1E",
        "1F",
        "1G",
        "1H",
        "1I",
        "1J",
        "1K",
        "1L",
        "1M",
        "1N",
        "1O",
        "1P",
        "1Q",
        "1R",
        "1S",
        "1T",
        "1U",
        "1V",
        "1W",
        "1X",
        "1Y",
        "1Z",
        "20",
        "21",
        "22",
        "23",
        "24",
        "25",
        "26",
        "27",
        "28",
        "29",
        "2A",
        "2B",
        "2C",
        "2D",
        "2E",
        "2F",
        "2G",
        "2H",
        "2I",
        "2J",
        "2K",
        "2L",
        "2M",
        "2N",
        "2O",
        "2P",
        "2Q",
        "2R",
        "2S",
        "2T",
        "2U",
        "2V",
        "2W",
        "2X",
        "2Y",
        "2Z",
        "30",
        "31",
        "32",
        "33",
        "34",
        "35",
        "36",
        "37",
        "38",
        "39",
        "3A",
        "3B",
        "3C",
        "3D",
        "3E",
        "3F",
        "3G",
        "3H",
        "3I",
        "3J",
    ]

    assert [base36_decode(base36_encode(x))
            for x in range(128)] == list(range(128))
Exemplo n.º 6
0
def test_base36():
    assert [base36_encode(x) for x in xrange(128)] == [
        "0",
        "1",
        "2",
        "3",
        "4",
        "5",
        "6",
        "7",
        "8",
        "9",
        "A",
        "B",
        "C",
        "D",
        "E",
        "F",
        "G",
        "H",
        "I",
        "J",
        "K",
        "L",
        "M",
        "N",
        "O",
        "P",
        "Q",
        "R",
        "S",
        "T",
        "U",
        "V",
        "W",
        "X",
        "Y",
        "Z",
        "10",
        "11",
        "12",
        "13",
        "14",
        "15",
        "16",
        "17",
        "18",
        "19",
        "1A",
        "1B",
        "1C",
        "1D",
        "1E",
        "1F",
        "1G",
        "1H",
        "1I",
        "1J",
        "1K",
        "1L",
        "1M",
        "1N",
        "1O",
        "1P",
        "1Q",
        "1R",
        "1S",
        "1T",
        "1U",
        "1V",
        "1W",
        "1X",
        "1Y",
        "1Z",
        "20",
        "21",
        "22",
        "23",
        "24",
        "25",
        "26",
        "27",
        "28",
        "29",
        "2A",
        "2B",
        "2C",
        "2D",
        "2E",
        "2F",
        "2G",
        "2H",
        "2I",
        "2J",
        "2K",
        "2L",
        "2M",
        "2N",
        "2O",
        "2P",
        "2Q",
        "2R",
        "2S",
        "2T",
        "2U",
        "2V",
        "2W",
        "2X",
        "2Y",
        "2Z",
        "30",
        "31",
        "32",
        "33",
        "34",
        "35",
        "36",
        "37",
        "38",
        "39",
        "3A",
        "3B",
        "3C",
        "3D",
        "3E",
        "3F",
        "3G",
        "3H",
        "3I",
        "3J",
    ]

    assert [base36_decode(base36_encode(x)) for x in xrange(128)] == range(128)