Exemple #1
0
 def test_simple_url(self):
     urlp = UrlParser('http://www.example.com/')
     self.assertEqual('www.example.com', urlp.host)
     self.assertEqual('http', urlp.schema)
     self.assertEqual('', urlp.path)
     self.assertListEqual([''], urlp.path_parts())
     self.assertListEqual([], urlp.query)
     self.assertIsNone(urlp.tag)
     self.assertIsNone(urlp.port)
Exemple #2
0
 def test_simple_url_with_path(self):
     urlp = UrlParser('http://www.example.com/path/to/some/file.html')
     self.assertEqual('www.example.com', urlp.host)
     self.assertEqual('http', urlp.schema)
     self.assertListEqual(['path', 'to', 'some', 'file.html'],
                          urlp.path_parts())
     self.assertListEqual([], urlp.query)
     self.assertIsNone(urlp.tag)
     self.assertIsNone(urlp.port)
 def test_simple_url(self):
     urlp = UrlParser('http://www.example.com/')
     self.assertEqual('www.example.com', urlp.host)
     self.assertEqual('http', urlp.schema)
     self.assertEqual('', urlp.path)
     self.assertListEqual([''], urlp.path_parts())
     self.assertListEqual([], urlp.query)
     self.assertIsNone(urlp.tag)
     self.assertIsNone(urlp.port)
 def test_simple_url_with_path(self):
     urlp = UrlParser('http://www.example.com/path/to/some/file.html')
     self.assertEqual('www.example.com', urlp.host)
     self.assertEqual('http', urlp.schema)
     self.assertListEqual(['path', 'to', 'some', 'file.html'],
                          urlp.path_parts())
     self.assertListEqual([], urlp.query)
     self.assertIsNone(urlp.tag)
     self.assertIsNone(urlp.port)
Exemple #5
0
 def test_the_bomb_with_tag(self):
     urlp = UrlParser('https://[email protected]:123/some/file.html'
                      '#sometag')
     self.assertEqual('www.example.com', urlp.host)
     self.assertEqual('https', urlp.schema)
     self.assertListEqual(['some', 'file.html'], urlp.path_parts())
     self.assertListEqual([], urlp.query)
     self.assertEqual('sometag', urlp.tag)
     self.assertEqual('123', urlp.port)
     self.assertEqual('user', urlp.user)
     self.assertIsNone(urlp.password)
Exemple #6
0
 def test_the_bomb_with_qs(self):
     urlp = UrlParser('https://*****:*****@www.example.com:123/some/file.html'
                      '?p1=v1&p2=v2')
     self.assertEqual('www.example.com', urlp.host)
     self.assertEqual('https', urlp.schema)
     self.assertListEqual(['some', 'file.html'], urlp.path_parts())
     self.assertListEqual(['p1=v1', 'p2=v2'], urlp.query)
     self.assertIsNone(urlp.tag)
     self.assertEqual('123', urlp.port)
     self.assertEqual('user', urlp.user)
     self.assertEqual('pass', urlp.password)
 def test_the_bomb_with_tag(self):
     urlp = UrlParser('https://[email protected]:123/some/file.html'
                      '#sometag')
     self.assertEqual('www.example.com', urlp.host)
     self.assertEqual('https', urlp.schema)
     self.assertListEqual(['some', 'file.html'],
                          urlp.path_parts())
     self.assertListEqual([], urlp.query)
     self.assertEqual('sometag', urlp.tag)
     self.assertEqual('123', urlp.port)
     self.assertEqual('user', urlp.user)
     self.assertIsNone(urlp.password)
 def test_the_bomb_with_qs(self):
     urlp = UrlParser('https://*****:*****@www.example.com:123/some/file.html'
                      '?p1=v1&p2=v2')
     self.assertEqual('www.example.com', urlp.host)
     self.assertEqual('https', urlp.schema)
     self.assertListEqual(['some', 'file.html'],
                          urlp.path_parts())
     self.assertListEqual(['p1=v1', 'p2=v2'], urlp.query)
     self.assertIsNone(urlp.tag)
     self.assertEqual('123', urlp.port)
     self.assertEqual('user', urlp.user)
     self.assertEqual('pass', urlp.password)
Exemple #9
0
 def fromWpMediaItem(cls, wp_media_item):
     """Build a new ImageAttachment instance based on a XmlRpc Media object.
     
     :type wp_media_item: XmlRpcMedia
     """
     new_object = cls()
     mapping = [
         'id',
         'parent',
         'title',
         'description',
         'caption',
         'link',
     ]
     for attr in mapping:
         setattr(new_object, attr, getattr(wp_media_item, attr))
     new_object._filename = UrlParser(wp_media_item.link).path_parts()[-1]
     new_object._get_image_data = lambda: urllib2.urlopen(new_object.link)
     return new_object