Exemple #1
0
 def test_cyrillic_path(self):
     url1 = URL.from_url(
         u'http://test.ru/тест'.encode('utf-8'))  # encoded unicode
     url2 = URL.from_url(u'http://test.ru/тест')  # decoded unicode
     # should work both without errors
     self.assertEqual(url1.path, '/%D1%82%D0%B5%D1%81%D1%82')
     self.assertEqual(url1.path, url2.path)
Exemple #2
0
    def test_broken_idna(self):
        src = u'http://xn--.xn--p1ai/'

        url = URL.from_url(src.encode('utf-8'))
        self.assertEqual(url.get_readable(), u'http://xn--.рф/')
        self.assertEqual(str(url), src)

        url = URL.from_url(src)
        self.assertEqual(url.get_readable(), u'http://xn--.рф/')
Exemple #3
0
    def test_broken_idna(self):
        src = u'http://xn--.xn--p1ai/'

        url = URL.from_url(src.encode('utf-8'))
        self.assertEqual(url.get_readable(),
                         u'http://xn--.рф/')
        self.assertEqual(str(url), src)

        url = URL.from_url(src)
        self.assertEqual(url.get_readable(),
                         u'http://xn--.рф/')
Exemple #4
0
    def test_from_url_idna(self):
        src = (u'http://xn--80aswg.xn--p1ai'
                                u'/%D1%83%D1%80%D0%BB/'
                                u'?q=%D0%BF%D0%BE%D0%B8%D1%81%D0%BA'
                                u'#%D1%8F%D0%BA%D0%BE%D1%80%D1%8C')

        url = URL.from_url(src.encode('utf-8'))
        self.assertEqual(url.get_readable(),
                         u'http://сайт.рф/урл/?q=поиск#якорь')

        url = URL.from_url(src)
        self.assertEqual(url.get_readable(),
                         u'http://сайт.рф/урл/?q=поиск#якорь')
Exemple #5
0
    def test_from_url_idna(self):
        src = (u'http://xn--80aswg.xn--p1ai'
                                u'/%D1%83%D1%80%D0%BB/'
                                u'?q=%D0%BF%D0%BE%D0%B8%D1%81%D0%BA'
                                u'#%D1%8F%D0%BA%D0%BE%D1%80%D1%8C')

        url = URL.from_url(src.encode('utf-8'))
        self.assertEqual(url.get_readable(),
                         u'http://сайт.рф/урл/?q=поиск#якорь')

        url = URL.from_url(src)
        self.assertEqual(url.get_readable(),
                         u'http://сайт.рф/урл/?q=поиск#якорь')
Exemple #6
0
    def test_copy_url(self):
        url_orig = URL.from_url(u"http://test.ru/тест?arg=value#anchor")
        url_copy = copy.copy(url_orig)
        self.assertEqual(str(url_orig), str(url_copy))

        url_deepcopy = copy.deepcopy(url_orig)
        self.assertEqual(str(url_orig), str(url_deepcopy))
Exemple #7
0
 def test_from_url_unicode(self):
     url = URL.from_url(u'http://сайт.рф/', show_host=False)
     self.assertEqual(url.schema, 'http')
     self.assertEqual(url.host, u'сайт.рф')
     self.assertEqual(url.port, '')
     self.assertEqual(url.path, '/')
     self.assertEqual(url.show_host, False)
Exemple #8
0
 def test_from_url_path(self):
     url = URL.from_url('/url?a=1&b=2&b=3')
     self.assertEqual(url.schema, 'http')
     self.assertEqual(url.host, '')
     self.assertEqual(url.port, '')
     self.assertEqual(url.path, '/url')
     self.assertEqual(url.query.items(), [('a' ,'1'), ('b', '2'), ('b', '3')])
Exemple #9
0
    def test_copy_url(self):
        url_orig = URL.from_url(u"http://test.ru/тест?arg=value#anchor")
        url_copy = copy.copy(url_orig)
        self.assertEqual(str(url_orig), str(url_copy))

        url_deepcopy = copy.deepcopy(url_orig)
        self.assertEqual(str(url_orig), str(url_deepcopy))
Exemple #10
0
 def test_from_url_unicode(self):
     url = URL.from_url(u'http://сайт.рф/', show_host=False)
     self.assertEqual(url.scheme, 'http')
     self.assertEqual(url.host, u'сайт.рф')
     self.assertEqual(url.port, '')
     self.assertEqual(url.path, '/')
     self.assertEqual(url.show_host, False)
Exemple #11
0
 def test_from_url_path(self):
     url = URL.from_url('/url?a=1&b=2&b=3')
     self.assertEqual(url.scheme, 'http')
     self.assertEqual(url.host, '')
     self.assertEqual(url.port, '')
     self.assertEqual(url.path, '/url')
     self.assertEqual(set(url.query.items()), {('a' ,'1'), ('b', '2'), ('b', '3')})
Exemple #12
0
 def test_from_url(self):
     url = URL.from_url('http://example.com/url?a=1&b=2&b=3', show_host=False)
     self.assertEqual(url.schema, 'http')
     self.assertEqual(url.host, 'example.com')
     self.assertEqual(url.port, '')
     self.assertEqual(url.path, '/url')
     self.assertEqual(url.query.items(), [('a' ,'1'), ('b', '2'), ('b', '3')])
     self.assertEqual(url.show_host, False)
Exemple #13
0
 def test_from_url(self):
     url = URL.from_url('http://example.com/url?a=1&b=2&b=3#anchor', show_host=False)
     self.assertEqual(url.scheme, 'http')
     self.assertEqual(url.host, 'example.com')
     self.assertEqual(url.port, '')
     self.assertEqual(url.path, '/url')
     self.assertEqual(url.fragment, 'anchor')
     self.assertEqual(set(url.query.items()), {('a' ,'1'), ('b', '2'), ('b', '3')})
     self.assertEqual(url.show_host, False)
Exemple #14
0
 def test_from_url(self):
     url = URL.from_url('http://example.com/url?a=1&b=2&b=3#anchor', show_host=False)
     self.assertEqual(url.scheme, 'http')
     self.assertEqual(url.host, 'example.com')
     self.assertEqual(url.port, '')
     self.assertEqual(url.path, '/url')
     self.assertEqual(url.fragment, 'anchor')
     self.assertEqual(set(url.query.items()), {('a' ,'1'), ('b', '2'), ('b', '3')})
     self.assertEqual(url.show_host, False)
Exemple #15
0
 def test_from_url_idna(self):
     url = URL.from_url('http://xn--80aswg.xn--p1ai/%D1%83%D1%80%D0%BB/?q=%D0%BF%D0%BE%D0%B8%D1%81%D0%BA')
     self.assertEqual(url.get_readable(),
                      u'http://сайт.рф/урл/?q=поиск')
Exemple #16
0
 def test_from_url_broken_unicode(self):
     url = URL.from_url('/search%E3%81?q=hello%E3%81#hash%E3%81')
     self.assertEqual(url.get_readable(),
                      u'/search\N{REPLACEMENT CHARACTER}'
                             u'?q=hello\N{REPLACEMENT CHARACTER}'
                              u'#hash\N{REPLACEMENT CHARACTER}')
Exemple #17
0
    def test_empty_fragment(self):
        self.assertEqual(URL.from_url('/').fragment, None)
        self.assertEqual(URL.from_url('/#').fragment, '')

        self.assertEqual(URL('/', fragment=None), '/')
        self.assertEqual(URL('/', fragment='') ,'/#')
Exemple #18
0
 def test_parse_cp_1251(self):
     url_string = u"http://test.com/?query=привет".encode('cp1251')
     url = URL.from_url(url_string)
     self.assertEqual(url.host, 'test.com')
     self.assertEqual(url.query['query'], u'\N{REPLACEMENT CHARACTER}'*6)
Exemple #19
0
 def test_from_url_broken_unicode(self):
     url = URL.from_url('/search%E3%81?q=hello%E3%81#hash%E3%81')
     self.assertEqual(url.get_readable(),
                      u'/search\N{REPLACEMENT CHARACTER}'
                             u'?q=hello\N{REPLACEMENT CHARACTER}'
                              u'#hash\N{REPLACEMENT CHARACTER}')
Exemple #20
0
    def test_empty_fragment(self):
        self.assertEqual(URL.from_url('/').fragment, None)
        self.assertEqual(URL.from_url('/#').fragment, '')

        self.assertEqual(URL('/', fragment=None), '/')
        self.assertEqual(URL('/', fragment='') ,'/#')
Exemple #21
0
 def test_from_url_broken_unicode(self):
     url = URL.from_url('/search?q=hello%E3%81')
     self.assertEqual(url.get_readable(),
                      u'/search?q=hello�')
Exemple #22
0
 def test_parse_cp_1251(self):
     url_string = u"http://test.com/?query=привет".encode('cp1251')
     url = URL.from_url(url_string)
     self.assertEqual(url.host, 'test.com')
     self.assertEqual(url.query['query'], u'\N{REPLACEMENT CHARACTER}'*6)
Exemple #23
0
 def test_cyrillic_path(self):
     url1 = URL.from_url('http://test.ru/тест') # encoded unicode
     url2 = URL.from_url(u'http://test.ru/тест') # decoded unicode
     # should work both without errors
     self.assertEqual(url1.path, '/%D1%82%D0%B5%D1%81%D1%82')
     self.assertEqual(url1.path, url2.path)