olauzanne / pyquery (http://pypi.python.org/pypi/pyquery)

A jquery-like library for python

Clone this repository (size: 130.4 KB): HTTPS / SSH
$ hg clone http://bitbucket.org/olauzanne/pyquery/
commit 73: 3bce8f544387
parent 72: b45eaa021356
branch: default
documentation
Olivier Lauzanne / olauzanne
15 months ago

Changed (Δ1.3 KB):

raw changeset »

pyquery/README.txt (37 lines added, 8 lines removed)

pyquery/pyquery.py (2 lines added, 0 lines removed)

Up to file-list pyquery/README.txt:

@@ -11,6 +11,18 @@ told myself "Hey let's make jquery in py
11
11
12
12
It can be used for many purposes, one idea that I might try in the future is to
13
13
use it for templating with pure http templates that you modify using pyquery.
14
I can also be used for web scrapping or for theming applications with
15
`Deliverance`_.
16
17
The project is being actively developped on `Bitbucket`_ and I have the policy
18
of giving push access to anyone who wants it and then to review what he does.
19
So if you want to contribute just email me.
20
21
The Sphinx documentation is available on `pyquery.org`_.
22
23
.. _deliverance: http://www.gawel.org/weblog/en/2008/12/skinning-with-pyquery-and-deliverance
24
.. _bitbucket: http://www.bitbucket.org/olauzanne/pyquery/
25
.. _pyquery.org: http://pyquery.org/
14
26
15
27
.. contents::
16
28
@@ -42,7 +54,8 @@ Now d is like the $ in jquery::
42
54
    'you know Python rocks'
43
55
44
56
You can use some of the pseudo classes that are available in jQuery but that
45
are not standard in css such as :first :last :even :odd :eq :lt :gt::
57
are not standard in css such as :first :last :even :odd :eq :lt :gt :checked
58
:selected :file::
46
59
47
60
    >>> d('p:first')
48
61
    [<p#hello.hello>]
@@ -296,6 +309,19 @@ You can make links absolute which can be
296
309
    >>> d('a[title="W3C Activities"]').attr('href')
297
310
    'http://www.w3.org/Consortium/activities'
298
311
312
Using different parsers
313
-----------------------
314
315
By default pyquery uses the lxml xml parser and then if it doesn't work goes on
316
to try the html parser. It can sometimes be problematic when parsing xhtml pages
317
because the parser will not raise an error but give an unusable tree.
318
319
You can also choose which parser to use explicitly::
320
321
   >>> pq('<p>toto</p>', parser='html')
322
   [<html>]
323
   >>> pq('<p>toto</p>', parser='xml')
324
   [<p>]
299
325
300
326
Testing
301
327
-------
@@ -320,21 +346,24 @@ If you don't already have lxml installed
320
346
Other documentations
321
347
--------------------
322
348
323
For more documentation about the API use the jquery website http://docs.jquery.com/
349
First there is the Sphinx documentation `here`_.
350
Then for more documentation about the API you can use the jquery website http://docs.jquery.com/.
351
The reference I'm now using for the API is ... the `color cheat sheet`_.
352
Then you can always look at the `code`_.
324
353
325
The reference I'm now using for the API is ... the color cheat sheet
326
http://colorcharge.com/wp-content/uploads/2007/12/jquery12_colorcharge.png
354
.. _code: http://www.bitbucket.org/olauzanne/pyquery/src/tip/pyquery/pyquery.py
355
.. _here: http://pyquery.org
356
.. _color cheat sheet: http://colorcharge.com/wp-content/uploads/2007/12/jquery12_colorcharge.png
327
357
328
358
TODO
329
359
----
330
360
331
- SELECTORS: it works fine but missing all the :xxx (:first, :last, ...) can be
332
  done by patching lxml.cssselect
361
- SELECTORS: still missing some jQuery pseudo classes (:radio, :password, ...)
333
362
- ATTRIBUTES: done
334
363
- CSS: done
335
364
- HTML: done
336
- MANIPULATING: did all but the "wrap" methods
337
- TRAVERSING: did a few
365
- MANIPULATING: missing the wrapAll and wrapInner methods
366
- TRAVERSING: about half done
338
367
- EVENTS: nothing to do with server side might be used later for automatic ajax
339
368
- CORE UI EFFECTS: did hide and show the rest doesn't really makes sense on
340
369
  server side

Up to file-list pyquery/pyquery.py:

@@ -67,6 +67,8 @@ class PyQuery(list):
67
67
        elements = []
68
68
        self._base_url = None
69
69
        parser = kwargs.get('parser')
70
        if 'parser' in kwargs:
71
            del kwargs['parser']
70
72
71
73
        if 'parent' in kwargs:
72
74
            self._parent = kwargs.pop('parent')