Commits

Olivier Lauzanne  committed 493f589 Merge

append and prepend methods

  • Participants
  • Parent commits e4eb183, d1110d4
  • Branches tip

Comments (0)

Files changed (7)

 # use glob syntax.
 syntax: glob
 
-*.elc
+develop-eggs/
+bin/
+.installed.cfg
+*.egg-info
 *.pyc
+*.swp
 *~

File bootstrap.py

+##############################################################################
+#
+# Copyright (c) 2006 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Bootstrap a buildout-based project
+
+Simply run this script in a directory containing a buildout.cfg.
+The script accepts buildout command-line options, so you can
+use the -c option to specify an alternate configuration file.
+
+$Id$
+"""
+
+import os, shutil, sys, tempfile, urllib2
+
+tmpeggs = tempfile.mkdtemp()
+
+is_jython = sys.platform.startswith('java')
+
+try:
+    import pkg_resources
+except ImportError:
+    ez = {}
+    exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py'
+                         ).read() in ez
+    ez['use_setuptools'](to_dir=tmpeggs, download_delay=0)
+
+    import pkg_resources
+
+if sys.platform == 'win32':
+    def quote(c):
+        if ' ' in c:
+            return '"%s"' % c # work around spawn lamosity on windows
+        else:
+            return c
+else:
+    def quote (c):
+        return c
+
+cmd = 'from setuptools.command.easy_install import main; main()'
+ws  = pkg_resources.working_set
+
+if is_jython:
+    import subprocess
+    
+    assert subprocess.Popen([sys.executable] + ['-c', quote(cmd), '-mqNxd', 
+           quote(tmpeggs), 'zc.buildout'], 
+           env=dict(os.environ,
+               PYTHONPATH=
+               ws.find(pkg_resources.Requirement.parse('setuptools')).location
+               ),
+           ).wait() == 0
+
+else:
+    assert os.spawnle(
+        os.P_WAIT, sys.executable, quote (sys.executable),
+        '-c', quote (cmd), '-mqNxd', quote (tmpeggs), 'zc.buildout',
+        dict(os.environ,
+            PYTHONPATH=
+            ws.find(pkg_resources.Requirement.parse('setuptools')).location
+            ),
+        ) == 0
+
+ws.add_entry(tmpeggs)
+ws.require('zc.buildout')
+import zc.buildout.buildout
+zc.buildout.buildout.main(sys.argv[1:] + ['bootstrap'])
+shutil.rmtree(tmpeggs)

File buildout.cfg

+[buildout]
+newest = true
+parts = eggs
+develop = .
+[eggs]
+recipe = zc.recipe.egg
+eggs =
+    lxml
+    pyquery
+    nose
+scripts =
+    nosetests=test
+    
+

File pyquery/README.txt

+pyquery: a jquery-like library
+====================================
+
+pyquery allows you to make jquery queries on xml documents.
+The API is as much as possible the similar to jquery. PyQuery use lxml for fast
+xml and html manipulation.
+
+This is not (or at least not yet) a library to produce or interact with
+javascript code. I just liked the jquery API and I missed it in python so I
+told myself "Hey let's make jquery in python". This is the result.
+
+It can be used for many purposes, one idea that I might try in the future is to
+use it for templating with pure http templates that you modify using pyquery.
+
+You can use the PyQuery class to load an xml document from a string, from a
+file or from an url::
+
+    >>> from pyquery import PyQuery
+    >>> d = PyQuery(html="<html></html>")
+    >>> d = PyQuery(url='http://w3c.org/')
+    >>> d = PyQuery(filename="pyquery/test.html")
+
+Now d is like the $ in jquery::
+
+    >>> d("#hello")
+    [<p#hello.hello>]
+    >>> p = d("#hello")
+    >>> p.html()
+    'Hello world !'
+    >>> p.html("you know <a href='http://python.org/'>Python</a> rocks")
+    [<p#hello.hello>]
+    >>> p.html()
+    'you know <a href="http://python.org/">Python</a> rocks'
+    >>> p.text()
+    'you know Python rocks'
+
+You can play with the attributes::
+
+    >>> p.attr("id")
+    'hello'
+    >>> p.attr("id", "plop")
+    [<p#plop.hello>]
+    >>> p.attr("id", "hello")
+    [<p#hello.hello>]
+
+And the class::
+
+    >>> p.addClass("toto")
+    [<p#hello.toto.hello>]
+    >>> p.toggleClass("titi toto")
+    [<p#hello.titi.hello>]
+    >>> p.removeClass("titi")
+    [<p#hello.hello>]
+
+Or the style::
+
+    >>> p.css("font-size", "15px")
+    [<p#hello.hello>]
+    >>> p.attr("style")
+    'font-size: 15px'
+    >>> p.css({"font-size": "17px"})
+    [<p#hello.hello>]
+    >>> p.attr("style")
+    'font-size: 17px'
+
+You can also add content to the end of tags::
+
+    >>> d('p').append('check out <a href="http://reddit.com/r/python"><span>reddit</span></a>')
+    [<p#hello.hello>, <p#test>]
+    >>> print d
+    <html>
+    ...
+    <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">
+    hello <a href="http://python.org">python</a> !
+    check out <a href="http://python.org/">Python</a> rockscheck out <a href="http://reddit.com/r/python"><span>reddit</span></a></p>
+    ...
+
+Or to the beginning::
+
+    >>> p.prepend('check out <a href="http://reddit.com/r/python">reddit</a>')
+    [<p#hello.hello>]
+    >>> p.html()
+    'check out <a href="http://reddit.com/r/python">reddit</a>you know ...'
+
+Prepend or append an element into an other::
+
+    >>> p.prependTo(d('#test'))
+    [<p#hello.hello>]
+    >>> d('#test').html()
+    '<p class="hello" ...</p>...hello...python...'
+
+And you can get back the modified html::
+
+    >>> print d #doctest: +ELLIPSIS
+    <html>
+    ...style="font-size: 17px"...
+    </html>
+
+For more documentation about the API use the jquery website http://jquery.com/
+
+You can run the doctests that you just read by running the test function or by
+running "$ python pyquery.py" in the pyquery source folder.
+
+The reference I'm using for the API now is ... the color cheat sheet
+http://colorcharge.com/wp-content/uploads/2007/12/jquery12_colorcharge.png
+
+- SELECTORS: it works fine but missing all the :xxx (:first, :last, ...) can be
+  done by patching lxml.cssselect
+- ATTRIBUTES: done
+- CSS: done
+- HTML: done
+- MANIPULATING: TODO (this is the priority very useful)
+- TRAVERSING: TODO (may prove troublesome)
+- EVENTS: nothing to do with server side might be used later for automatic ajax
+- CORE UI EFFECTS: did hide and show the rest doesn't really makes sense on
+  server side
+- AJAX: don't make sense on server side

File pyquery/__init__.py

 #
 # Distributed under the BSD license, see LICENSE.txt
 
-'''pyquery: a jquery-like library
-====================================
-
-pyquery allows you to make jquery queries on xml documents.
-The API is as much as possible the similar to jquery. PyQuery use lxml for fast
-xml and html manipulation.
-
-This is not (or at least not yet) a library to produce or interact with
-javascript code. I just liked the jquery API and I missed it in python so I
-told myself 'Hey let's make jquery in python'. This is the result.
-
-It can be used for many purposes, one idea that I might try in the future is to
-use it for templating with pure http templates that you modify using pyquery.
-
-You can use the PyQuery class to load an xml document from a string, from a
-file or from an url.
-
-    >>> d = PyQuery(html='<html></html>')
-    >>> d = PyQuery(url='http://w3c.org/')
-    >>> d = PyQuery(filename='test.html')
-
-Now d is like the $ in jquery.
-
-    >>> d('#hello')
-    [<p#hello.hello>]
-    >>> p = d('#hello')
-    >>> p.html()
-    'Hello world !'
-    >>> p.html('you know <a href="http://python.org/">Python</a> rocks')
-    [<p#hello.hello>]
-    >>> p.html()
-    'you know <a href="http://python.org/">Python</a> rocks'
-    >>> p.text()
-    'you know Python rocks'
-
-You can play with the attributes
-
-    >>> p.attr('id')
-    'hello'
-    >>> p.attr('id', 'plop')
-    [<p#plop.hello>]
-    >>> p.attr('id', 'hello')
-    [<p#hello.hello>]
-
-And the class
-
-    >>> p.addClass('toto')
-    [<p#hello.toto.hello>]
-    >>> p.toggleClass('titi toto')
-    [<p#hello.titi.hello>]
-    >>> p.removeClass('titi')
-    [<p#hello.hello>]
-
-Or the style
-
-    >>> p.css('font-size', '15px')
-    [<p#hello.hello>]
-    >>> p.attr('style')
-    'font-size: 15px'
-    >>> p.css({'font-size': '17px'})
-    [<p#hello.hello>]
-    >>> p.attr('style')
-    'font-size: 17px'
-
-You can also add content to the end of tags
-
-    >>> d('p').append('check out <a href="http://reddit.com/r/python"><span>reddit</span></a>')
-    [<p#hello.hello>, <p#test>]
-    >>> print d
-    <html>
-    ...
-    <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">
-    hello <a href="http://python.org">python</a> !
-    check out <a href="http://python.org/">Python</a> rockscheck out <a href="http://reddit.com/r/python"><span>reddit</span></a></p>
-    ...
-
-
-Or to the beginning
-
-    >>> p.prepend('check out <a href="http://reddit.com/r/python">reddit</a>')
-    [<p#hello.hello>]
-    >>> p.html()
-    'check out <a href="http://reddit.com/r/python">reddit</a>you know ...'
-
-Prepend or append an element into an other
-
-    >>> p.prependTo(d('#test'))
-    [<p#hello.hello>]
-    >>> d('#test').html()
-    '<p class="hello" ...</p>...hello...python...'
-
-
-And you can get back the modified html
-
-    >>> print d
-    <html>
-    ...style="font-size: 17px"...
-    </html>
-
-For more documentation about the API use the jquery website http://jquery.com/
-
-You can run the doctests that you just read by running the test function or by
-running '$ python pyquery.py' in the pyquery source folder.
-
-The reference I'm using for the API now is ... the color cheat sheet
-http://colorcharge.com/wp-content/uploads/2007/12/jquery12_colorcharge.png
-
-- SELECTORS: it works fine but missing all the :xxx (:first, :last, ...) can be
-  done by patching lxml.cssselect
-- ATTRIBUTES: done
-- CSS: done
-- HTML: done
-- MANIPULATING: TODO (this is the priority very useful)
-- TRAVERSING: TODO (may prove troublesome)
-- EVENTS: nothing to do with server side might be used later for automatic ajax
-- CORE UI EFFECTS: did hide and show the rest doesn't really makes sense on
-  server side
-- AJAX: don't make sense on server side
-'''
-
 from lxml.cssselect import css_to_xpath
 from lxml import etree
 from copy import deepcopy
+[nosetests]
+with-doctest=true
+doctest-extension=.txt
 from setuptools import setup, find_packages
 import sys, os
 
-import pyquery
+long_description = open(os.path.join('pyquery', 'README.txt')).read()
 
 version = '0.1'
 
 setup(name='pyquery',
       version=version,
       description='A jquery-like library for manipulating html and xml documents',
-      long_description=pyquery.__doc__,
+      long_description=long_description,
       classifiers=[], # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
       keywords='jquery html xml',
       author='Olivier Lauzanne',