Codebase list pyquery / debian/0.5-1
Imported Debian patch 0.5-1 Jonathan Wiltshire 14 years ago
7 changed file(s) with 86 addition(s) and 14 deletion(s). Raw diff Collapse all Expand all
00 Metadata-Version: 1.0
11 Name: pyquery
2 Version: 0.4
2 Version: 0.5
33 Summary: A jquery-like library for python
44 Home-page: http://www.bitbucket.org/olauzanne/pyquery/
55 Author: Olivier Lauzanne
0 pyquery (0.5-1) unstable; urgency=low
1
2 * New upstream release.
3 * Standards version 3.8.4, no changes
4
5 -- Jonathan Wiltshire <debian@jwiltshire.org.uk> Wed, 10 Mar 2010 09:28:40 +0000
6
07 pyquery (0.4-1) unstable; urgency=low
18
29 * New upstream release.
66 DM-Upload-Allowed: yes
77 Build-Depends: debhelper (>= 7), python-all (>= 2.5)
88 Build-Depends-Indep: python-support (>= 0.5.3), python-setuptools
9 Standards-Version: 3.8.3
9 Standards-Version: 3.8.4
1010 Vcs-Svn: svn://svn.debian.org/python-modules/packages/pyquery/trunk/
1111 Vcs-Browser: http://svn.debian.org/viewsvn/python-modules/packages/pyquery/trunk/
1212 Homepage: http://pyquery.org/
6868 html = None
6969 elements = []
7070 self._base_url = None
71 parser = kwargs.get('parser')
71 self.parser = kwargs.get('parser', None)
7272 if 'parser' in kwargs:
7373 del kwargs['parser']
7474 if not kwargs and len(args) == 1 and isinstance(args[0], basestring) \
9696 self._base_url = url
9797 else:
9898 raise ValueError('Invalid keyword arguments %s' % kwargs)
99 elements = fromstring(html, parser)
99 elements = fromstring(html, self.parser)
100100 else:
101101 # get nodes
102102
114114 # get context
115115 if isinstance(context, basestring):
116116 try:
117 elements = fromstring(context, parser)
117 elements = fromstring(context, self.parser)
118118 except Exception, e:
119119 raise ValueError('%r, %s' % (e, context))
120120 elif isinstance(context, self.__class__):
307307 """
308308 elements = [child for tag in self for child in tag.getchildren()]
309309 return self._filter_only(selector, elements)
310
311 def closest(self, selector=None):
312 """
313 >>> d = PyQuery('<div class="hello"><p>This is a <strong class="hello">test</strong></p></div>')
314 >>> d('strong').closest('div')
315 [<div.hello>]
316 >>> d('strong').closest('.hello')
317 [<strong.hello>]
318 >>> d('strong').closest('form')
319 []
320 """
321 try:
322 current = self[0]
323 except IndexError:
324 current = None
325 while current is not None and not self.__class__(current).is_(selector):
326 current = current.getparent()
327 return self.__class__(current, **dict(parent=self))
310328
311329 def filter(self, selector):
312330 """Filter elements in self using selector (string or function).
670688 for tag in self:
671689 for child in tag.getchildren():
672690 tag.remove(child)
673 root = etree.fromstring('<root>' + new_html + '</root>')
691 root = fromstring('<root>' + new_html + '</root>', self.parser)[0]
674692 children = root.getchildren()
675693 if children:
676694 tag.extend(children)
726744
727745 def _get_root(self, value):
728746 if isinstance(value, basestring):
729 root = etree.fromstring('<root>' + value + '</root>')
747 root = fromstring('<root>' + value + '</root>', self.parser)[0]
730748 elif isinstance(value, etree._Element):
731749 root = self.__class__(value)
732750 elif isinstance(value, PyQuery):
921939 def replaceWith(self, value):
922940 """replace nodes by value
923941 """
924 self.before(value)
925 for tag in self:
926 parent = tag.getparent()
927 parent.remove(tag)
942 if callable(value):
943 for i, element in enumerate(self):
944 self.__class__(element).before(value(i, element) + (element.tail or ''))
945 parent = element.getparent()
946 parent.remove(element)
947 else:
948 for tag in self:
949 self.__class__(tag).before(value + (tag.tail or ''))
950 parent = tag.getparent()
951 parent.remove(tag)
928952 return self
929953
930954 def replaceAll(self, expr):
243243 assert len(self.klass('div', self.html).find('span').end()) == 2
244244 assert len(self.klass('#node2', self.html).find('span').end()) == 1
245245
246 def test_closest(self):
247 assert len(self.klass('#node1 span', self.html).closest('body')) == 1
248 assert self.klass('#node2', self.html).closest('.node3').attr('id') == 'node2'
249 assert self.klass('.node3', self.html).closest('form') == []
246250
247251 class TestOpener(unittest.TestCase):
248252
274278 def test_proxy(self):
275279 e = self.klass([])
276280 val = e.get('http://pyquery.org/')
277 assert len(val('div.document')) == 1, (val.response, val)
281 assert len(val('body')) == 1, (str(val.response), val)
278282
279283 def test_get(self):
280284 e = self.klass(app=application)
320324 val = d('a:last').html()
321325 assert val == ' My link text 2', repr(val)
322326
327 class TestHTMLParser(unittest.TestCase):
328 xml = "<div>I'm valid XML</div>"
329 html = '''
330 <div class="portlet">
331 <a href="/toto">TestimageMy link text</a>
332 <a href="/toto2">imageMy link text 2</a>
333 Behind you, a three-headed HTML&dash;Entity!
334 </div>
335 '''
336 def test_parser_persistance(self):
337 d = pq(self.xml, parser='xml')
338 self.assertRaises(etree.XMLSyntaxError, lambda: d.after(self.html))
339 d = pq(self.xml, parser='html')
340 d.after(self.html) # this should not fail
341
342 def test_replaceWith(self):
343 expected = '''<div class="portlet">
344 <a href="/toto">TestimageMy link text</a>
345 <a href="/toto2">imageMy link text 2</a>
346 Behind you, a three-headed HTML&amp;dash;Entity!
347 </div>'''
348 d = pq(self.html)
349 d('img').replaceWith('image')
350 val = d.__html__()
351 assert val == expected, (repr(val), repr(expected))
352
353 def test_replaceWith_with_function(self):
354 expected = '''<div class="portlet">
355 TestimageMy link text
356 imageMy link text 2
357 Behind you, a three-headed HTML&amp;dash;Entity!
358 </div>'''
359 d = pq(self.html)
360 d('a').replaceWith(lambda i, e: pq(e).html())
361 val = d.__html__()
362 assert val == expected, (repr(val), repr(expected))
363
323364 if __name__ == '__main__':
324365 fails, total = unittest.main()
325366 if fails == 0:
00 Metadata-Version: 1.0
11 Name: pyquery
2 Version: 0.4
2 Version: 0.5
33 Summary: A jquery-like library for python
44 Home-page: http://www.bitbucket.org/olauzanne/pyquery/
55 Author: Olivier Lauzanne
88
99 long_description = open(os.path.join('pyquery', 'README.txt')).read()
1010
11 version = '0.4'
11 version = '0.5'
1212
1313 setup(name='pyquery',
1414 version=version,