pyquery

changeset 83:fe14faeb9947

doc refactoring
author gpasgrimaud@boiboite.local
date Mon Feb 16 17:58:04 2009 +0100 (12 months ago)
parents 9c6892dbd3c8
children 885c218b5a4f
files docs/Makefile docs/ajax.txt docs/api.txt docs/attributes.txt docs/css.txt docs/future.txt docs/index.txt docs/manipulating.txt docs/testing.txt docs/tips.txt docs/traversing.txt pyquery/README.txt
line diff
     1.1 --- a/docs/Makefile	Tue Jan 27 14:11:23 2009 +0100
     1.2 +++ b/docs/Makefile	Mon Feb 16 17:58:04 2009 +0100
     1.3 @@ -32,7 +32,7 @@
     1.4  	@echo
     1.5  	@echo "Build finished. The HTML pages are in .build/html."
     1.6  
     1.7 -osx: html
     1.8 +open: html
     1.9  	open .build/html/index.html
    1.10  
    1.11  pickle:
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/docs/ajax.txt	Mon Feb 16 17:58:04 2009 +0100
     2.3 @@ -0,0 +1,56 @@
     2.4 +:mod:`pyquery.ajax` -- PyQuery AJAX extension
     2.5 +=============================================
     2.6 +
     2.7 +.. automodule:: pyquery.ajax
     2.8 +
     2.9 +
    2.10 +.. fake imports
    2.11 +
    2.12 +    >>> from ajax import PyQuery as pq
    2.13 +
    2.14 +You can query some wsgi app if `WebOb`_ is installed (it's not a pyquery
    2.15 +dependencie). IN this example the test app returns a simple input at `/` and a
    2.16 +submit button at `/submit`::
    2.17 +
    2.18 +    >>> d = pq('<form></form>', app=input_app)
    2.19 +    >>> d.append(d.get('/'))
    2.20 +    [<form>]
    2.21 +    >>> print d
    2.22 +    <form><input name="youyou" type="text" value=""/></form>
    2.23 +
    2.24 +The app is also available in new nodes::
    2.25 +
    2.26 +    >>> d.get('/').app is d.app is d('form').app
    2.27 +    True
    2.28 +
    2.29 +You can also request another path::
    2.30 +
    2.31 +    >>> d.append(d.get('/submit'))
    2.32 +    [<form>]
    2.33 +    >>> print d
    2.34 +    <form><input name="youyou" type="text" value=""/><input type="submit" value="OK"/></form>
    2.35 +
    2.36 +If `Paste`_ is installed, you are able to get url directly with a `Proxy`_ app::
    2.37 +
    2.38 +    >>> a = d.get('http://pyquery.org/')
    2.39 +    >>> a
    2.40 +    [<html>]
    2.41 +
    2.42 +You can retrieve the app response::
    2.43 +
    2.44 +    >>> print a.response.status
    2.45 +    200 OK
    2.46 +
    2.47 +The response attribute is a `WebOb`_ `Response`_
    2.48 +
    2.49 +.. _webob: http://pythonpaste.org/webob/
    2.50 +.. _response: http://pythonpaste.org/webob/#response
    2.51 +.. _paste: http://pythonpaste.org/
    2.52 +.. _proxy: http://pythonpaste.org/modules/proxy.html#paste.proxy.Proxy
    2.53 +
    2.54 +Api
    2.55 +---
    2.56 +
    2.57 +.. autoclass:: PyQuery
    2.58 +   :members:
    2.59 +
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/docs/api.txt	Mon Feb 16 17:58:04 2009 +0100
     3.3 @@ -0,0 +1,9 @@
     3.4 +:mod:`~pyquery.pyquery` -- PyQuery complete API
     3.5 +==============================================
     3.6 +
     3.7 +.. automodule:: pyquery.pyquery
     3.8 +
     3.9 +.. autoclass:: PyQuery
    3.10 +   :members:
    3.11 +
    3.12 +
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/docs/attributes.txt	Mon Feb 16 17:58:04 2009 +0100
     4.3 @@ -0,0 +1,28 @@
     4.4 +Attributes
     4.5 +----------
     4.6 +
     4.7 +You can play with the attributes with the jquery API::
     4.8 +
     4.9 +    >>> p.attr("id")
    4.10 +    'hello'
    4.11 +    >>> p.attr("id", "plop")
    4.12 +    [<p#plop.hello>]
    4.13 +    >>> p.attr("id", "hello")
    4.14 +    [<p#hello.hello>]
    4.15 +
    4.16 +
    4.17 +Or in a more pythonic way::
    4.18 +
    4.19 +    >>> p.attr.id = "plop"
    4.20 +    >>> p.attr.id
    4.21 +    'plop'
    4.22 +    >>> p.attr["id"] = "ola"
    4.23 +    >>> p.attr["id"]
    4.24 +    'ola'
    4.25 +    >>> p.attr(id='hello', class_='hello2')
    4.26 +    [<p#hello.hello2>]
    4.27 +    >>> p.attr.class_
    4.28 +    'hello2'
    4.29 +    >>> p.attr.class_ = 'hello'
    4.30 +
    4.31 +
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/docs/css.txt	Mon Feb 16 17:58:04 2009 +0100
     5.3 @@ -0,0 +1,40 @@
     5.4 +CSS
     5.5 +---
     5.6 +
     5.7 +You can also play with css classes::
     5.8 +
     5.9 +    >>> p.addClass("toto")
    5.10 +    [<p#hello.toto.hello>]
    5.11 +    >>> p.toggleClass("titi toto")
    5.12 +    [<p#hello.titi.hello>]
    5.13 +    >>> p.removeClass("titi")
    5.14 +    [<p#hello.hello>]
    5.15 +
    5.16 +Or the css style::
    5.17 +
    5.18 +    >>> p.css("font-size", "15px")
    5.19 +    [<p#hello.hello>]
    5.20 +    >>> p.attr("style")
    5.21 +    'font-size: 15px'
    5.22 +    >>> p.css({"font-size": "17px"})
    5.23 +    [<p#hello.hello>]
    5.24 +    >>> p.attr("style")
    5.25 +    'font-size: 17px'
    5.26 +
    5.27 +Same thing the pythonic way ('_' characters are translated to '-')::
    5.28 +
    5.29 +    >>> p.css.font_size = "16px"
    5.30 +    >>> p.attr.style
    5.31 +    'font-size: 16px'
    5.32 +    >>> p.css['font-size'] = "15px"
    5.33 +    >>> p.attr.style
    5.34 +    'font-size: 15px'
    5.35 +    >>> p.css(font_size="16px")
    5.36 +    [<p#hello.hello>]
    5.37 +    >>> p.attr.style
    5.38 +    'font-size: 16px'
    5.39 +    >>> p.css = {"font-size": "17px"}
    5.40 +    >>> p.attr.style
    5.41 +    'font-size: 17px'
    5.42 +
    5.43 +
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/docs/future.txt	Mon Feb 16 17:58:04 2009 +0100
     6.3 @@ -0,0 +1,22 @@
     6.4 +Future
     6.5 +-------
     6.6 +
     6.7 +- SELECTORS: still missing some jQuery pseudo classes (:radio, :password, ...)
     6.8 +
     6.9 +- ATTRIBUTES: done
    6.10 +
    6.11 +- CSS: done
    6.12 +
    6.13 +- HTML: done
    6.14 +
    6.15 +- MANIPULATING: missing the wrapAll and wrapInner methods
    6.16 +
    6.17 +- TRAVERSING: about half done
    6.18 +
    6.19 +- EVENTS: nothing to do with server side might be used later for automatic ajax
    6.20 +
    6.21 +- CORE UI EFFECTS: did hide and show the rest doesn't really makes sense on
    6.22 +  server side
    6.23 +
    6.24 +- AJAX: some with wsgi app
    6.25 +
     7.1 --- a/docs/index.txt	Tue Jan 27 14:11:23 2009 +0100
     7.2 +++ b/docs/index.txt	Mon Feb 16 17:58:04 2009 +0100
     7.3 @@ -1,19 +1,42 @@
     7.4  .. include:: ../pyquery/README.txt
     7.5  
     7.6 -:mod:`pyquery.pyquery` -- PyQuery complete API
     7.7 -==============================================
     7.8 +Full documentation
     7.9 +==================
    7.10  
    7.11 -.. automodule:: pyquery.pyquery
    7.12 +.. toctree::
    7.13 +   :maxdepth: 1
    7.14  
    7.15 -.. autoclass:: PyQuery
    7.16 -   :members:
    7.17 +   attributes
    7.18 +   css
    7.19 +   manipulating
    7.20 +   traversing
    7.21 +   api
    7.22 +   ajax
    7.23 +   tips
    7.24 +   testing
    7.25 +   future
    7.26  
    7.27 -:mod:`pyquery.ajax` -- PyQuery AJAX extension
    7.28 -=============================================
    7.29 +More documentation
    7.30 +==================
    7.31  
    7.32 -.. automodule:: pyquery.ajax
    7.33 +First there is the Sphinx documentation `here`_.
    7.34 +Then for more documentation about the API you can use the `jquery website`_.
    7.35 +The reference I'm now using for the API is ... the `color cheat sheet`_.
    7.36 +Then you can always look at the `code`_.
    7.37  
    7.38 -.. autoclass:: PyQuery
    7.39 -   :members:
    7.40 +.. _jquery website: http://docs.jquery.com/
    7.41 +.. _code: http://www.bitbucket.org/olauzanne/pyquery/src/tip/pyquery/pyquery.py
    7.42 +.. _here: http://pyquery.org
    7.43 +.. _color cheat sheet: http://colorcharge.com/wp-content/uploads/2007/12/jquery12_colorcharge.png
    7.44  
    7.45 +Indices and tables
    7.46 +==================
    7.47  
    7.48 +* :ref:`genindex`
    7.49 +* :ref:`modindex`
    7.50 +* :ref:`search`
    7.51 +
    7.52 +
    7.53 +
    7.54 +
    7.55 +
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/docs/manipulating.txt	Mon Feb 16 17:58:04 2009 +0100
     8.3 @@ -0,0 +1,91 @@
     8.4 +Manipulating
     8.5 +------------
     8.6 +
     8.7 +You can also add content to the end of tags::
     8.8 +
     8.9 +    >>> d('p').append('check out <a href="http://reddit.com/r/python"><span>reddit</span></a>')
    8.10 +    [<p#hello.hello>, <p#test>]
    8.11 +    >>> print d
    8.12 +    <html>
    8.13 +    ...
    8.14 +    <p class="hello" id="hello" style="font-size: 17px">you know <a href="http://python.org/">Python</a> rockscheck out <a href="http://reddit.com/r/python"><span>reddit</span></a></p><p id="test">
    8.15 +    hello <a href="http://python.org">python</a> !
    8.16 +    check out <a href="http://python.org/">Python</a> rockscheck out <a href="http://reddit.com/r/python"><span>reddit</span></a></p>
    8.17 +    ...
    8.18 +
    8.19 +Or to the beginning::
    8.20 +
    8.21 +    >>> p.prepend('check out <a href="http://reddit.com/r/python">reddit</a>')
    8.22 +    [<p#hello.hello>]
    8.23 +    >>> p.html()
    8.24 +    'check out <a href="http://reddit.com/r/python">reddit</a>you know ...'
    8.25 +
    8.26 +Prepend or append an element into an other::
    8.27 +
    8.28 +    >>> p.prependTo(d('#test'))
    8.29 +    [<p#hello.hello>]
    8.30 +    >>> d('#test').html()
    8.31 +    '<p class="hello" ...</p>...hello...python...'
    8.32 +
    8.33 +Insert an element after another::
    8.34 +
    8.35 +    >>> p.insertAfter(d('#test'))
    8.36 +    [<p#hello.hello>]
    8.37 +    >>> d('#test').html()
    8.38 +    '<a href="http://python.org">python</a> !...'
    8.39 +
    8.40 +Or before::
    8.41 +
    8.42 +    >>> p.insertBefore(d('#test'))
    8.43 +    [<p#hello.hello>]
    8.44 +    >>> d('body').html()
    8.45 +    '\n<p class="hello" id="hello" style="font-size: 17px">...'
    8.46 +
    8.47 +Doing something for each elements::
    8.48 +
    8.49 +    >>> p.each(lambda e: e.addClass('hello2'))
    8.50 +    [<p#hello.hello2.hello>]
    8.51 +
    8.52 +Remove an element::
    8.53 +
    8.54 +    >>> d.remove('p#id')
    8.55 +    [<html>]
    8.56 +    >>> d('p#id')
    8.57 +    []
    8.58 +
    8.59 +Replace an element by another::
    8.60 +
    8.61 +    >>> p.replaceWith('<p>testing</p>')
    8.62 +    [<p#hello.hello2.hello>]
    8.63 +    >>> d('p')
    8.64 +    [<p>, <p#test>]
    8.65 +
    8.66 +Or the other way around::
    8.67 +
    8.68 +    >>> d('<h1>arya stark</h1>').replaceAll('p')
    8.69 +    [<h1>]
    8.70 +    >>> d('p')
    8.71 +    []
    8.72 +    >>> d('h1')
    8.73 +    [<h1>, <h1>]
    8.74 +
    8.75 +Remove what's inside the selection::
    8.76 +
    8.77 +    >>> d('h1').empty()
    8.78 +    [<h1>, <h1>]
    8.79 +
    8.80 +And you can get back the modified html::
    8.81 +
    8.82 +    >>> print d
    8.83 +    <html>
    8.84 +    <body>
    8.85 +    <h1/><h1/></body>
    8.86 +    </html>
    8.87 +
    8.88 +You can generate html stuff::
    8.89 +
    8.90 +    >>> from pyquery import PyQuery as pq
    8.91 +    >>> print pq('<div>Yeah !</div>').addClass('myclass') + pq('<b>cool</b>')
    8.92 +    <div class="myclass">Yeah !</div><b>cool</b>
    8.93 +
    8.94 +
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/docs/testing.txt	Mon Feb 16 17:58:04 2009 +0100
     9.3 @@ -0,0 +1,21 @@
     9.4 +Testing
     9.5 +-------
     9.6 +
     9.7 +If you want to run the tests that you can see above you should do::
     9.8 +
     9.9 +    $ hg clone https://bitbucket.org/olauzanne/pyquery/
    9.10 +    $ cd pyquery
    9.11 +    $ python bootstrap.py
    9.12 +    $ bin/buildout
    9.13 +    $ bin/test
    9.14 +
    9.15 +You can build the Sphinx documentation by doing::
    9.16 +
    9.17 +    $ cd docs
    9.18 +    $ make html
    9.19 +
    9.20 +If you don't already have lxml installed use this line::
    9.21 +
    9.22 +    $ STATIC_DEPS=true bin/buildout
    9.23 +
    9.24 +
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/docs/tips.txt	Mon Feb 16 17:58:04 2009 +0100
    10.3 @@ -0,0 +1,36 @@
    10.4 +Tips
    10.5 +====
    10.6 +
    10.7 +Making links absolute
    10.8 +---------------------
    10.9 +
   10.10 +You can make links absolute which can be usefull for screen scrapping::
   10.11 +
   10.12 +    >>> d = pq(url='http://www.w3.org/', parser='html')
   10.13 +    >>> d('a[title="W3C Activities"]').attr('href')
   10.14 +    '/Consortium/activities'
   10.15 +    >>> d.make_links_absolute()
   10.16 +    [<html>]
   10.17 +    >>> d('a[title="W3C Activities"]').attr('href')
   10.18 +    'http://www.w3.org/Consortium/activities'
   10.19 +
   10.20 +Using different parsers
   10.21 +-----------------------
   10.22 +
   10.23 +By default pyquery uses the lxml xml parser and then if it doesn't work goes on
   10.24 +to try the html parser from lxml.html. The xml parser can sometimes be
   10.25 +problematic when parsing xhtml pages because the parser will not raise an error
   10.26 +but give an unusable tree (on w3c.org for example).
   10.27 +
   10.28 +You can also choose which parser to use explicitly::
   10.29 +
   10.30 +   >>> pq('<html><body><p>toto</p></body></html>', parser='xml')
   10.31 +   [<html>]
   10.32 +   >>> pq('<html><body><p>toto</p></body></html>', parser='html')
   10.33 +   [<html>]
   10.34 +   >>> pq('<html><body><p>toto</p></body></html>', parser='html_fragments')
   10.35 +   [<p>]
   10.36 +
   10.37 +The html and html_fragments parser are the ones from lxml.html.
   10.38 +
   10.39 +
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/docs/traversing.txt	Mon Feb 16 17:58:04 2009 +0100
    11.3 @@ -0,0 +1,32 @@
    11.4 +Traversing
    11.5 +----------
    11.6 +
    11.7 +Some jQuery traversal methods are supported.  Here are a few examples.
    11.8 +
    11.9 +You can filter the selection list using a string selector::
   11.10 +
   11.11 +    >>> d('p').filter('.hello')
   11.12 +    [<p#hello.hello>]
   11.13 +
   11.14 +It is possible to select a single element with eq::
   11.15 +
   11.16 +    >>> d('p').eq(0)
   11.17 +    [<p#hello.hello>]
   11.18 +
   11.19 +You can find nested elements::
   11.20 +
   11.21 +    >>> d('p').find('a')
   11.22 +    [<a>, <a>]
   11.23 +    >>> d('p').eq(1).find('a')
   11.24 +    [<a>]
   11.25 +
   11.26 +Breaking out of a level of traversal is also supported using end::
   11.27 +
   11.28 +    >>> d('p').find('a').end()
   11.29 +    [<p#hello.hello>, <p#test>]
   11.30 +    >>> d('p').eq(0).end()
   11.31 +    [<p#hello.hello>, <p#test>]
   11.32 +    >>> d('p').filter(lambda i: i == 1).end()
   11.33 +    [<p#hello.hello>, <p#test>]
   11.34 +
   11.35 +
    12.1 --- a/pyquery/README.txt	Tue Jan 27 14:11:23 2009 +0100
    12.2 +++ b/pyquery/README.txt	Mon Feb 16 17:58:04 2009 +0100
    12.3 @@ -18,16 +18,14 @@
    12.4  Bitbucket. I have the policy of giving push access to anyone who wants it
    12.5  and then to review what he does. So if you want to contribute just email me.
    12.6  
    12.7 -The Sphinx documentation is available on `pyquery.org`_.
    12.8 +The full documentation is available on `pyquery.org`_.
    12.9  
   12.10  .. _deliverance: http://www.gawel.org/weblog/en/2008/12/skinning-with-pyquery-and-deliverance
   12.11  .. _project: http://www.bitbucket.org/olauzanne/pyquery/
   12.12  .. _pyquery.org: http://pyquery.org/
   12.13  
   12.14 -.. contents::
   12.15 -
   12.16 -Usage
   12.17 ------
   12.18 +Quickstart
   12.19 +==========
   12.20  
   12.21  You can use the PyQuery class to load an xml document from a string, a lxml
   12.22  document, from a file or from an url::
   12.23 @@ -60,317 +58,3 @@
   12.24      >>> d('p:first')
   12.25      [<p#hello.hello>]
   12.26  
   12.27 -
   12.28 -Attributes
   12.29 -----------
   12.30 -
   12.31 -You can play with the attributes with the jquery API::
   12.32 -
   12.33 -    >>> p.attr("id")
   12.34 -    'hello'
   12.35 -    >>> p.attr("id", "plop")
   12.36 -    [<p#plop.hello>]
   12.37 -    >>> p.attr("id", "hello")
   12.38 -    [<p#hello.hello>]
   12.39 -
   12.40 -
   12.41 -Or in a more pythonic way::
   12.42 -
   12.43 -    >>> p.attr.id = "plop"
   12.44 -    >>> p.attr.id
   12.45 -    'plop'
   12.46 -    >>> p.attr["id"] = "ola"
   12.47 -    >>> p.attr["id"]
   12.48 -    'ola'
   12.49 -    >>> p.attr(id='hello', class_='hello2')
   12.50 -    [<p#hello.hello2>]
   12.51 -    >>> p.attr.class_
   12.52 -    'hello2'
   12.53 -    >>> p.attr.class_ = 'hello'
   12.54 -
   12.55 -CSS
   12.56 ----
   12.57 -
   12.58 -You can also play with css classes::
   12.59 -
   12.60 -    >>> p.addClass("toto")
   12.61 -    [<p#hello.toto.hello>]
   12.62 -    >>> p.toggleClass("titi toto")
   12.63 -    [<p#hello.titi.hello>]
   12.64 -    >>> p.removeClass("titi")
   12.65 -    [<p#hello.hello>]
   12.66 -
   12.67 -Or the css style::
   12.68 -
   12.69 -    >>> p.css("font-size", "15px")
   12.70 -    [<p#hello.hello>]
   12.71 -    >>> p.attr("style")
   12.72 -    'font-size: 15px'
   12.73 -    >>> p.css({"font-size": "17px"})
   12.74 -    [<p#hello.hello>]
   12.75 -    >>> p.attr("style")
   12.76 -    'font-size: 17px'
   12.77 -
   12.78 -Same thing the pythonic way ('_' characters are translated to '-')::
   12.79 -
   12.80 -    >>> p.css.font_size = "16px"
   12.81 -    >>> p.attr.style
   12.82 -    'font-size: 16px'
   12.83 -    >>> p.css['font-size'] = "15px"
   12.84 -    >>> p.attr.style
   12.85 -    'font-size: 15px'
   12.86 -    >>> p.css(font_size="16px")
   12.87 -    [<p#hello.hello>]
   12.88 -    >>> p.attr.style
   12.89 -    'font-size: 16px'
   12.90 -    >>> p.css = {"font-size": "17px"}
   12.91 -    >>> p.attr.style
   12.92 -    'font-size: 17px'
   12.93 -
   12.94 -Traversing
   12.95 -----------
   12.96 -
   12.97 -Some jQuery traversal methods are supported.  Here are a few examples.
   12.98 -
   12.99 -You can filter the selection list using a string selector::
  12.100 -
  12.101 -    >>> d('p').filter('.hello')
  12.102 -    [<p#hello.hello>]
  12.103 -
  12.104 -It is possible to select a single element with eq::
  12.105 -
  12.106 -    >>> d('p').eq(0)
  12.107 -    [<p#hello.hello>]
  12.108 -
  12.109 -You can find nested elements::
  12.110 -
  12.111 -    >>> d('p').find('a')
  12.112 -    [<a>, <a>]
  12.113 -    >>> d('p').eq(1).find('a')
  12.114 -    [<a>]
  12.115 -
  12.116 -Breaking out of a level of traversal is also supported using end::
  12.117 -
  12.118 -    >>> d('p').find('a').end()
  12.119 -    [<p#hello.hello>, <p#test>]
  12.120 -    >>> d('p').eq(0).end()
  12.121 -    [<p#hello.hello>, <p#test>]
  12.122 -    >>> d('p').filter(lambda i: i == 1).end()
  12.123 -    [<p#hello.hello>, <p#test>]
  12.124 -
  12.125 -Manipulating
  12.126 -------------
  12.127 -
  12.128 -You can also add content to the end of tags::
  12.129 -
  12.130 -    >>> d('p').append('check out <a href="http://reddit.com/r/python"><span>reddit</span></a>')
  12.131 -    [<p#hello.hello>, <p#test>]
  12.132 -    >>> print d
  12.133 -    <html>
  12.134 -    ...
  12.135 -    <p class="hello" id="hello" style="font-size: 17px">you know <a href="http://python.org/">Python</a> rockscheck out <a href="http://reddit.com/r/python"><span>reddit</span></a></p><p id="test">
  12.136 -    hello <a href="http://python.org">python</a> !
  12.137 -    check out <a href="http://python.org/">Python</a> rockscheck out <a href="http://reddit.com/r/python"><span>reddit</span></a></p>
  12.138 -    ...
  12.139 -
  12.140 -Or to the beginning::
  12.141 -
  12.142 -    >>> p.prepend('check out <a href="http://reddit.com/r/python">reddit</a>')
  12.143 -    [<p#hello.hello>]
  12.144 -    >>> p.html()
  12.145 -    'check out <a href="http://reddit.com/r/python">reddit</a>you know ...'
  12.146 -
  12.147 -Prepend or append an element into an other::
  12.148 -
  12.149 -    >>> p.prependTo(d('#test'))
  12.150 -    [<p#hello.hello>]
  12.151 -    >>> d('#test').html()
  12.152 -    '<p class="hello" ...</p>...hello...python...'
  12.153 -
  12.154 -Insert an element after another::
  12.155 -
  12.156 -    >>> p.insertAfter(d('#test'))
  12.157 -    [<p#hello.hello>]
  12.158 -    >>> d('#test').html()
  12.159 -    '<a href="http://python.org">python</a> !...'
  12.160 -
  12.161 -Or before::
  12.162 -
  12.163 -    >>> p.insertBefore(d('#test'))
  12.164 -    [<p#hello.hello>]
  12.165 -    >>> d('body').html()
  12.166 -    '\n<p class="hello" id="hello" style="font-size: 17px">...'
  12.167 -
  12.168 -Doing something for each elements::
  12.169 -
  12.170 -    >>> p.each(lambda e: e.addClass('hello2'))
  12.171 -    [<p#hello.hello2.hello>]
  12.172 -
  12.173 -Remove an element::
  12.174 -
  12.175 -    >>> d.remove('p#id')
  12.176 -    [<html>]
  12.177 -    >>> d('p#id')
  12.178 -    []
  12.179 -
  12.180 -Replace an element by another::
  12.181 -
  12.182 -    >>> p.replaceWith('<p>testing</p>')
  12.183 -    [<p#hello.hello2.hello>]
  12.184 -    >>> d('p')
  12.185 -    [<p>, <p#test>]
  12.186 -
  12.187 -Or the other way around::
  12.188 -
  12.189 -    >>> d('<h1>arya stark</h1>').replaceAll('p')
  12.190 -    [<h1>]
  12.191 -    >>> d('p')
  12.192 -    []
  12.193 -    >>> d('h1')
  12.194 -    [<h1>, <h1>]
  12.195 -
  12.196 -Remove what's inside the selection::
  12.197 -
  12.198 -    >>> d('h1').empty()
  12.199 -    [<h1>, <h1>]
  12.200 -
  12.201 -And you can get back the modified html::
  12.202 -
  12.203 -    >>> print d
  12.204 -    <html>
  12.205 -    <body>
  12.206 -    <h1/><h1/></body>
  12.207 -    </html>
  12.208 -
  12.209 -You can generate html stuff::
  12.210 -
  12.211 -    >>> from pyquery import PyQuery as pq
  12.212 -    >>> print pq('<div>Yeah !</div>').addClass('myclass') + pq('<b>cool</b>')
  12.213 -    <div class="myclass">Yeah !</div><b>cool</b>
  12.214 -
  12.215 -
  12.216 -AJAX
  12.217 -----
  12.218 -
  12.219 -.. fake imports
  12.220 -
  12.221 -    >>> from ajax import PyQuery as pq
  12.222 -
  12.223 -You can query some wsgi app if `WebOb`_ is installed (it's not a pyquery
  12.224 -dependencie). IN this example the test app returns a simple input at `/` and a
  12.225 -submit button at `/submit`::
  12.226 -
  12.227 -    >>> d = pq('<form></form>', app=input_app)
  12.228 -    >>> d.append(d.get('/'))
  12.229 -    [<form>]
  12.230 -    >>> print d
  12.231 -    <form><input name="youyou" type="text" value=""/></form>
  12.232 -
  12.233 -The app is also available in new nodes::
  12.234 -
  12.235 -    >>> d.get('/').app is d.app is d('form').app
  12.236 -    True
  12.237 -
  12.238 -You can also request another path::
  12.239 -
  12.240 -    >>> d.append(d.get('/submit'))
  12.241 -    [<form>]
  12.242 -    >>> print d
  12.243 -    <form><input name="youyou" type="text" value=""/><input type="submit" value="OK"/></form>
  12.244 -
  12.245 -If `Paste`_ is installed, you are able to get url directly with a `Proxy`_ app::
  12.246 -
  12.247 -    >>> a = d.get('http://pyquery.org/')
  12.248 -    >>> a
  12.249 -    [<html>]
  12.250 -
  12.251 -You can retrieve the app response::
  12.252 -
  12.253 -    >>> print a.response.status
  12.254 -    200 OK
  12.255 -
  12.256 -The response attribute is a `WebOb`_ `Response`_
  12.257 -
  12.258 -.. _webob: http://pythonpaste.org/webob/
  12.259 -.. _response: http://pythonpaste.org/webob/#response
  12.260 -.. _paste: http://pythonpaste.org/
  12.261 -.. _proxy: http://pythonpaste.org/modules/proxy.html#paste.proxy.Proxy
  12.262 -
  12.263 -Making links absolute
  12.264 ----------------------
  12.265 -
  12.266 -You can make links absolute which can be usefull for screen scrapping::
  12.267 -
  12.268 -    >>> d = pq(url='http://www.w3.org/', parser='html')
  12.269 -    >>> d('a[title="W3C Activities"]').attr('href')
  12.270 -    '/Consortium/activities'
  12.271 -    >>> d.make_links_absolute()
  12.272 -    [<html>]
  12.273 -    >>> d('a[title="W3C Activities"]').attr('href')
  12.274 -    'http://www.w3.org/Consortium/activities'
  12.275 -
  12.276 -Using different parsers
  12.277 ------------------------
  12.278 -
  12.279 -By default pyquery uses the lxml xml parser and then if it doesn't work goes on
  12.280 -to try the html parser from lxml.html. The xml parser can sometimes be
  12.281 -problematic when parsing xhtml pages because the parser will not raise an error
  12.282 -but give an unusable tree (on w3c.org for example).
  12.283 -
  12.284 -You can also choose which parser to use explicitly::
  12.285 -
  12.286 -   >>> pq('<html><body><p>toto</p></body></html>', parser='xml')
  12.287 -   [<html>]
  12.288 -   >>> pq('<html><body><p>toto</p></body></html>', parser='html')
  12.289 -   [<html>]
  12.290 -   >>> pq('<html><body><p>toto</p></body></html>', parser='html_fragments')
  12.291 -   [<p>]
  12.292 -
  12.293 -The html and html_fragments parser are the ones from lxml.html.
  12.294 -
  12.295 -Testing
  12.296 --------
  12.297 -
  12.298 -If you want to run the tests that you can see above you should do::
  12.299 -
  12.300 -    $ hg clone https://bitbucket.org/olauzanne/pyquery/
  12.301 -    $ cd pyquery
  12.302 -    $ python bootstrap.py
  12.303 -    $ bin/buildout
  12.304 -    $ bin/test
  12.305 -
  12.306 -You can build the Sphinx documentation by doing::
  12.307 -
  12.308 -    $ cd docs
  12.309 -    $ make html
  12.310 -
  12.311 -If you don't already have lxml installed use this line::
  12.312 -
  12.313 -    $ STATIC_DEPS=true bin/buildout
  12.314 -
  12.315 -More documentation
  12.316 -------------------
  12.317 -
  12.318 -First there is the Sphinx documentation `here`_.
  12.319 -Then for more documentation about the API you can use the `jquery website`_.
  12.320 -The reference I'm now using for the API is ... the `color cheat sheet`_.
  12.321 -Then you can always look at the `code`_.
  12.322 -
  12.323 -.. _jquery website: http://docs.jquery.com/
  12.324 -.. _code: http://www.bitbucket.org/olauzanne/pyquery/src/tip/pyquery/pyquery.py
  12.325 -.. _here: http://pyquery.org
  12.326 -.. _color cheat sheet: http://colorcharge.com/wp-content/uploads/2007/12/jquery12_colorcharge.png
  12.327 -
  12.328 -TODO
  12.329 -----
  12.330 -
  12.331 -- SELECTORS: still missing some jQuery pseudo classes (:radio, :password, ...)
  12.332 -- ATTRIBUTES: done
  12.333 -- CSS: done
  12.334 -- HTML: done
  12.335 -- MANIPULATING: missing the wrapAll and wrapInner methods
  12.336 -- TRAVERSING: about half done
  12.337 -- EVENTS: nothing to do with server side might be used later for automatic ajax
  12.338 -- CORE UI EFFECTS: did hide and show the rest doesn't really makes sense on
  12.339 -  server side
  12.340 -- AJAX: some with wsgi app

To download these repositories, get Mercurial and then type something like:

hg clone http://techn.ocracy.org/repository-name/

You can also click the "zip" or "gz" links to get an archive of the latest revision without installing anything.

The change logs of the repositories are aggregated at techn.ocracy.org/planet.

We have also some darcs repositories at techn.ocracy.org/darcs.