Imported Debian patch 0.5-1
Jonathan Wiltshire
14 years ago
0 | 0 | Metadata-Version: 1.0 |
1 | 1 | Name: pyquery |
2 | Version: 0.4 | |
2 | Version: 0.5 | |
3 | 3 | Summary: A jquery-like library for python |
4 | 4 | Home-page: http://www.bitbucket.org/olauzanne/pyquery/ |
5 | 5 | 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 | ||
0 | 7 | pyquery (0.4-1) unstable; urgency=low |
1 | 8 | |
2 | 9 | * New upstream release. |
6 | 6 | DM-Upload-Allowed: yes |
7 | 7 | Build-Depends: debhelper (>= 7), python-all (>= 2.5) |
8 | 8 | Build-Depends-Indep: python-support (>= 0.5.3), python-setuptools |
9 | Standards-Version: 3.8.3 | |
9 | Standards-Version: 3.8.4 | |
10 | 10 | Vcs-Svn: svn://svn.debian.org/python-modules/packages/pyquery/trunk/ |
11 | 11 | Vcs-Browser: http://svn.debian.org/viewsvn/python-modules/packages/pyquery/trunk/ |
12 | 12 | Homepage: http://pyquery.org/ |
68 | 68 | html = None |
69 | 69 | elements = [] |
70 | 70 | self._base_url = None |
71 | parser = kwargs.get('parser') | |
71 | self.parser = kwargs.get('parser', None) | |
72 | 72 | if 'parser' in kwargs: |
73 | 73 | del kwargs['parser'] |
74 | 74 | if not kwargs and len(args) == 1 and isinstance(args[0], basestring) \ |
96 | 96 | self._base_url = url |
97 | 97 | else: |
98 | 98 | raise ValueError('Invalid keyword arguments %s' % kwargs) |
99 | elements = fromstring(html, parser) | |
99 | elements = fromstring(html, self.parser) | |
100 | 100 | else: |
101 | 101 | # get nodes |
102 | 102 | |
114 | 114 | # get context |
115 | 115 | if isinstance(context, basestring): |
116 | 116 | try: |
117 | elements = fromstring(context, parser) | |
117 | elements = fromstring(context, self.parser) | |
118 | 118 | except Exception, e: |
119 | 119 | raise ValueError('%r, %s' % (e, context)) |
120 | 120 | elif isinstance(context, self.__class__): |
307 | 307 | """ |
308 | 308 | elements = [child for tag in self for child in tag.getchildren()] |
309 | 309 | 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)) | |
310 | 328 | |
311 | 329 | def filter(self, selector): |
312 | 330 | """Filter elements in self using selector (string or function). |
670 | 688 | for tag in self: |
671 | 689 | for child in tag.getchildren(): |
672 | 690 | tag.remove(child) |
673 | root = etree.fromstring('<root>' + new_html + '</root>') | |
691 | root = fromstring('<root>' + new_html + '</root>', self.parser)[0] | |
674 | 692 | children = root.getchildren() |
675 | 693 | if children: |
676 | 694 | tag.extend(children) |
726 | 744 | |
727 | 745 | def _get_root(self, value): |
728 | 746 | if isinstance(value, basestring): |
729 | root = etree.fromstring('<root>' + value + '</root>') | |
747 | root = fromstring('<root>' + value + '</root>', self.parser)[0] | |
730 | 748 | elif isinstance(value, etree._Element): |
731 | 749 | root = self.__class__(value) |
732 | 750 | elif isinstance(value, PyQuery): |
921 | 939 | def replaceWith(self, value): |
922 | 940 | """replace nodes by value |
923 | 941 | """ |
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) | |
928 | 952 | return self |
929 | 953 | |
930 | 954 | def replaceAll(self, expr): |
243 | 243 | assert len(self.klass('div', self.html).find('span').end()) == 2 |
244 | 244 | assert len(self.klass('#node2', self.html).find('span').end()) == 1 |
245 | 245 | |
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') == [] | |
246 | 250 | |
247 | 251 | class TestOpener(unittest.TestCase): |
248 | 252 | |
274 | 278 | def test_proxy(self): |
275 | 279 | e = self.klass([]) |
276 | 280 | 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) | |
278 | 282 | |
279 | 283 | def test_get(self): |
280 | 284 | e = self.klass(app=application) |
320 | 324 | val = d('a:last').html() |
321 | 325 | assert val == ' My link text 2', repr(val) |
322 | 326 | |
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‐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&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&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 | ||
323 | 364 | if __name__ == '__main__': |
324 | 365 | fails, total = unittest.main() |
325 | 366 | if fails == 0: |