コード例 #1
0
def test_split__ip6():
    assert split('http://[::1]/') == ('http', '[::1]', '/', '', '')
    assert split('http://[::1]:8080/') == ('http', '[::1]:8080', '/', '', '')
    assert split('[::1]') == ('', '', '[::1]', '', '')
    assert split('[::1]:8080') == ('', '', '[::1]:8080', '', '')
    assert split('[::ffff:127.0.0.1]:8080') == ('', '',
                                                '[::ffff:127.0.0.1]:8080', '',
                                                '')
コード例 #2
0
def test_split__no_scheme():
    # no scheme -> everything until query is path
    assert split('example.com') == ('', '', 'example.com', '', '')
    assert split('example.com.') == ('', '', 'example.com.', '', '')
    assert split('www.example.com') == ('', '', 'www.example.com', '', '')
    assert split('www.example.com/abc') == ('', '', 'www.example.com/abc', '', '')
    assert split('www.example.com:8080') == ('', '', 'www.example.com:8080', '', '')
    assert split('www.example.com:8080/abc') == ('', '', 'www.example.com:8080/abc', '', '')
    assert split('www.example.com:8080/abc?x=1') == ('', '', 'www.example.com:8080/abc', 'x=1', '')
    assert split('www.example.com:8080/abc#foo') == ('', '', 'www.example.com:8080/abc', '', 'foo')
コード例 #3
0
def test_split__no_scheme():
    # no scheme -> everything until query is path
    assert split('example.com') == ('', '', 'example.com', '', '')
    assert split('example.com.') == ('', '', 'example.com.', '', '')
    assert split('www.example.com') == ('', '', 'www.example.com', '', '')
    assert split('www.example.com/abc') == ('', '', 'www.example.com/abc', '',
                                            '')
    assert split('www.example.com:8080') == ('', '', 'www.example.com:8080',
                                             '', '')
    assert split('www.example.com:8080/abc') == ('', '',
                                                 'www.example.com:8080/abc',
                                                 '', '')
    assert split('www.example.com:8080/abc?x=1') == (
        '', '', 'www.example.com:8080/abc', 'x=1', '')
    assert split('www.example.com:8080/abc#foo') == (
        '', '', 'www.example.com:8080/abc', '', 'foo')
コード例 #4
0
ファイル: test_urltools.py プロジェクト: vinilios/urltools
def test_split():
    assert split("http://www.example.com") == ('http', 'www.example.com', '', '', '')
    assert split("http://www.example.com/") == ('http', 'www.example.com', '/', '', '')
    assert split("http://www.example.com/abc") == ('http', 'www.example.com', '/abc', '', '')

    assert split("http://www.example.com:80") == ('http', 'www.example.com:80', '', '', '')
    assert split("http://www.example.com:8080") == ('http', 'www.example.com:8080', '', '', '')
    assert split("http://www.example.com:8080/abc") == ('http', 'www.example.com:8080', '/abc', '', '')

    assert split("http://www.example.com/?x=1") == ('http', 'www.example.com', '/', 'x=1', '')
    assert split("http://www.example.com/abc?x=1") == ('http', 'www.example.com', '/abc', 'x=1', '')
    assert split("http://www.example.com/abc?x=1&y=2") == ('http', 'www.example.com', '/abc', 'x=1&y=2', '')

    assert split("http://www.example.com/abc#foo") == ('http', 'www.example.com', '/abc', '', 'foo')
    assert split("http://www.example.com/abc?x=1&y=2#foo") == ('http', 'www.example.com', '/abc', 'x=1&y=2', 'foo')

    assert split("mailto:[email protected]") == ('mailto', '*****@*****.**', '', '', '')

    assert split("example.com") == ('', '', 'example.com', '', '')
    assert split("example.com.") == ('', '', 'example.com.', '', '')
    assert split("www.example.com") == ('', '', 'www.example.com', '', '')
    assert split("www.example.com/abc") == ('', '', 'www.example.com/abc', '', '')
    assert split("www.example.com:8080") == ('', '', 'www.example.com:8080', '', '')
    assert split("www.example.com:8080/abc") == ('', '', 'www.example.com:8080/abc', '', '')

    assert split("foo/bar") == ('', '', 'foo/bar', '', '')
    assert split("/foo/bar") == ('', '', '/foo/bar', '', '')

    assert split("http://example.com?foo") == ('http', 'example.com', '', 'foo', '')
    assert split("http://example.com/?foo") == ('http', 'example.com', '/', 'foo', '')
    assert split("http://example.com/#foo") == ('http', 'example.com', '/', '', 'foo')
    assert split("http://example.com#foo") == ('http', 'example.com', '', '', 'foo')
    assert split("http://example.com?foo#bar") == ('http', 'example.com', '', 'foo', 'bar')
    assert split("http://example.com/#foo?bar") == ('http', 'example.com', '/', '', 'foo?bar')

    assert split("http://192.168.1.1/") == ('http', '192.168.1.1', '/', '', '')
    assert split("http://192.168.1.1:8080/") == ('http', '192.168.1.1:8080', '/', '', '')
    assert split("192.168.1.1") == ('', '', '192.168.1.1', '', '')

    assert split("http://[::1]/") == ('http', '[::1]', '/', '', '')
    assert split("http://[::1]:8080/") == ('http', '[::1]:8080', '/', '', '')
    assert split("[::1]") == ('', '', '[::1]', '', '')
    assert split("[::1]:8080") == ('', '', '[::1]:8080', '', '')
コード例 #5
0
def test_split__ip6():
    assert split('http://[::1]/') == ('http', '[::1]', '/', '', '')
    assert split('http://[::1]:8080/') == ('http', '[::1]:8080', '/', '', '')
    assert split('[::1]') == ('', '', '[::1]', '', '')
    assert split('[::1]:8080') == ('', '', '[::1]:8080', '', '')
    assert split('[::ffff:127.0.0.1]:8080') == ('', '', '[::ffff:127.0.0.1]:8080', '', '')
コード例 #6
0
def test_split__ip4():
    assert split('http://192.168.1.1/') == ('http', '192.168.1.1', '/', '', '')
    assert split('http://192.168.1.1:8080/') == ('http', '192.168.1.1:8080', '/', '', '')
    assert split('192.168.1.1') == ('', '', '192.168.1.1', '', '')
コード例 #7
0
def test_split__path_only():
    assert split('foo/bar') == ('', '', 'foo/bar', '', '')
    assert split('/foo/bar') == ('', '', '/foo/bar', '', '')
コード例 #8
0
def test_split():
    assert split('http://www.example.com') == ('http', 'www.example.com', '', '', '')
    assert split('http://www.example.com/') == ('http', 'www.example.com', '/', '', '')
    assert split('http://www.example.com/abc') == ('http', 'www.example.com', '/abc', '', '')

    assert split('http://www.example.com:80') == ('http', 'www.example.com:80', '', '', '')
    assert split('http://www.example.com:8080/abc') == ('http', 'www.example.com:8080', '/abc', '', '')

    assert split('http://www.example.com/?x=1') == ('http', 'www.example.com', '/', 'x=1', '')
    assert split('http://www.example.com/abc?x=1&y=2') == ('http', 'www.example.com', '/abc', 'x=1&y=2', '')

    assert split('http://www.example.com/abc#foo') == ('http', 'www.example.com', '/abc', '', 'foo')
    assert split('http://www.example.com/abc?x=1&y=2#foo') == ('http', 'www.example.com', '/abc', 'x=1&y=2', 'foo')

    assert split('http://example.com?foo') == ('http', 'example.com', '', 'foo', '')
    assert split('http://example.com/?foo') == ('http', 'example.com', '/', 'foo', '')
    assert split('http://example.com/#foo') == ('http', 'example.com', '/', '', 'foo')
    assert split('http://example.com#foo') == ('http', 'example.com', '', '', 'foo')
    assert split('http://example.com?foo#bar') == ('http', 'example.com', '', 'foo', 'bar')
    assert split('http://example.com/#foo?bar') == ('http', 'example.com', '/', '', 'foo?bar')

    assert split('mailto:[email protected]') == ('mailto', '*****@*****.**', '', '', '')
コード例 #9
0
def test_split__ip4():
    assert split('http://192.168.1.1/') == ('http', '192.168.1.1', '/', '', '')
    assert split('http://192.168.1.1:8080/') == ('http', '192.168.1.1:8080',
                                                 '/', '', '')
    assert split('192.168.1.1') == ('', '', '192.168.1.1', '', '')
コード例 #10
0
def test_split__path_only():
    assert split('foo/bar') == ('', '', 'foo/bar', '', '')
    assert split('/foo/bar') == ('', '', '/foo/bar', '', '')
コード例 #11
0
def test_split():
    assert split('http://www.example.com') == ('http', 'www.example.com', '',
                                               '', '')
    assert split('http://www.example.com/') == ('http', 'www.example.com', '/',
                                                '', '')
    assert split('http://www.example.com/abc') == ('http', 'www.example.com',
                                                   '/abc', '', '')

    assert split('http://www.example.com:80') == ('http', 'www.example.com:80',
                                                  '', '', '')
    assert split('http://www.example.com:8080/abc') == ('http',
                                                        'www.example.com:8080',
                                                        '/abc', '', '')

    assert split('http://www.example.com/?x=1') == ('http', 'www.example.com',
                                                    '/', 'x=1', '')
    assert split('http://www.example.com/abc?x=1&y=2') == ('http',
                                                           'www.example.com',
                                                           '/abc', 'x=1&y=2',
                                                           '')

    assert split('http://www.example.com/abc#foo') == ('http',
                                                       'www.example.com',
                                                       '/abc', '', 'foo')
    assert split('http://www.example.com/abc?x=1&y=2#foo') == (
        'http', 'www.example.com', '/abc', 'x=1&y=2', 'foo')

    assert split('http://example.com?foo') == ('http', 'example.com', '',
                                               'foo', '')
    assert split('http://example.com/?foo') == ('http', 'example.com', '/',
                                                'foo', '')
    assert split('http://example.com/#foo') == ('http', 'example.com', '/', '',
                                                'foo')
    assert split('http://example.com#foo') == ('http', 'example.com', '', '',
                                               'foo')
    assert split('http://example.com?foo#bar') == ('http', 'example.com', '',
                                                   'foo', 'bar')
    assert split('http://example.com/#foo?bar') == ('http', 'example.com', '/',
                                                    '', 'foo?bar')

    assert split('mailto:[email protected]') == ('mailto', '*****@*****.**', '', '', '')
コード例 #12
0
def test_split():
    assert split("http://www.example.com") == ('http', 'www.example.com', '',
                                               '', '')
    assert split("http://www.example.com/") == ('http', 'www.example.com', '/',
                                                '', '')
    assert split("http://www.example.com/abc") == ('http', 'www.example.com',
                                                   '/abc', '', '')

    assert split("http://www.example.com:80") == ('http', 'www.example.com:80',
                                                  '', '', '')
    assert split("http://www.example.com:8080") == ('http',
                                                    'www.example.com:8080', '',
                                                    '', '')
    assert split("http://www.example.com:8080/abc") == ('http',
                                                        'www.example.com:8080',
                                                        '/abc', '', '')

    assert split("http://www.example.com/?x=1") == ('http', 'www.example.com',
                                                    '/', 'x=1', '')
    assert split("http://www.example.com/abc?x=1") == ('http',
                                                       'www.example.com',
                                                       '/abc', 'x=1', '')
    assert split("http://www.example.com/abc?x=1&y=2") == ('http',
                                                           'www.example.com',
                                                           '/abc', 'x=1&y=2',
                                                           '')

    assert split("http://www.example.com/abc#foo") == ('http',
                                                       'www.example.com',
                                                       '/abc', '', 'foo')
    assert split("http://www.example.com/abc?x=1&y=2#foo") == (
        'http', 'www.example.com', '/abc', 'x=1&y=2', 'foo')

    assert split("mailto:[email protected]") == ('mailto', '*****@*****.**', '', '', '')

    assert split("example.com") == ('', '', 'example.com', '', '')
    assert split("example.com.") == ('', '', 'example.com.', '', '')
    assert split("www.example.com") == ('', '', 'www.example.com', '', '')
    assert split("www.example.com/abc") == ('', '', 'www.example.com/abc', '',
                                            '')
    assert split("www.example.com:8080") == ('', '', 'www.example.com:8080',
                                             '', '')
    assert split("www.example.com:8080/abc") == ('', '',
                                                 'www.example.com:8080/abc',
                                                 '', '')

    assert split("foo/bar") == ('', '', 'foo/bar', '', '')
    assert split("/foo/bar") == ('', '', '/foo/bar', '', '')

    assert split("http://example.com?foo") == ('http', 'example.com', '',
                                               'foo', '')
    assert split("http://example.com/?foo") == ('http', 'example.com', '/',
                                                'foo', '')
    assert split("http://example.com/#foo") == ('http', 'example.com', '/', '',
                                                'foo')
    assert split("http://example.com#foo") == ('http', 'example.com', '', '',
                                               'foo')
    assert split("http://example.com?foo#bar") == ('http', 'example.com', '',
                                                   'foo', 'bar')
    assert split("http://example.com/#foo?bar") == ('http', 'example.com', '/',
                                                    '', 'foo?bar')

    assert split("http://192.168.1.1/") == ('http', '192.168.1.1', '/', '', '')
    assert split("http://192.168.1.1:8080/") == ('http', '192.168.1.1:8080',
                                                 '/', '', '')
    assert split("192.168.1.1") == ('', '', '192.168.1.1', '', '')

    assert split("http://[::1]/") == ('http', '[::1]', '/', '', '')
    assert split("http://[::1]:8080/") == ('http', '[::1]:8080', '/', '', '')
    assert split("[::1]") == ('', '', '[::1]', '', '')
    assert split("[::1]:8080") == ('', '', '[::1]:8080', '', '')