Permalink
Browse files

remove the unwanted sections from the page using pyquery

instead of hiding it using css.

Signed-off-by: Santhosh Thottingal <santhosh.thottingal@gmail.com>
  • Loading branch information...
1 parent 93332bd commit bf0d2be7684f286a6d0e49fffc362082debe4686 @santhoshtr committed May 23, 2010
Showing with 1,867 additions and 28 deletions.
  1. +2 −28 content/bits.wikimedia.org/skins-1.5/vector/main-ltr.css
  2. +62 −0 pyquery/README.txt
  3. +13 −0 pyquery/__init__.py
  4. +81 −0 pyquery/ajax.py
  5. +238 −0 pyquery/cssselectpatch.py
  6. +1,019 −0 pyquery/pyquery.py
  7. +31 −0 pyquery/rules.py
  8. +368 −0 pyquery/test.py
  9. +32 −0 pyquery/tests.txt
  10. +21 −0 wiki2cd.py
@@ -27,34 +27,8 @@ body {
background-color: #f3f3f3;
background-image: url(images/page-base.png?1);
}
-.noprint,
-div#jump-to-nav,
-div.top,
-div#column-one,
-div#siteNotice,
-div#purl,
-div#footer,
-div#stub,
-div#noprint,
-div#disambig,
-div.NavFrame,
-#colophon,
-.editsection,
-.toctoggle,
-.tochidden,
-.catlinks,
-.navbox,
-.sisterproject,
-.ambox,
-.toccolours,
-.topicon
-div#f-poweredbyico,
-div#f-copyrightico,
-div#featured-star,
-li#f-viewcount,
-li#f-about,
-li#f-disclaimer,
-li#f-privacy {
+.noprint
+{
/* Hides all the elements irrelevant for printing */
display: none;
}
View
@@ -0,0 +1,62 @@
+pyquery: a jquery-like library for python
+=========================================
+
+pyquery allows you to make jquery queries on xml documents.
+The API is as much as possible the similar to jquery. pyquery uses 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.
+I can also be used for web scrapping or for theming applications with
+`Deliverance`_.
+
+The `project`_ is being actively developped on a mercurial repository on
+Bitbucket. I have the policy of giving push access to anyone who wants it
+and then to review what he does. So if you want to contribute just email me.
+
+The full documentation is available on `pyquery.org`_.
+
+.. _deliverance: http://www.gawel.org/weblog/en/2008/12/skinning-with-pyquery-and-deliverance
+.. _project: http://www.bitbucket.org/olauzanne/pyquery/
+.. _pyquery.org: http://pyquery.org/
+
+Quickstart
+==========
+
+You can use the PyQuery class to load an xml document from a string, a lxml
+document, from a file or from an url::
+
+ >>> from pyquery import PyQuery as pq
+ >>> from lxml import etree
+ >>> import urllib
+ >>> d = pq("<html></html>")
+ >>> d = pq(etree.fromstring("<html></html>"))
+ >>> d = pq(url='http://google.com/')
+ >>> d = pq(url='http://google.com/', opener=lambda url: urllib.urlopen(url).read())
+ >>> d = pq(filename=path_to_html_file)
+
+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()
+ u'you know <a href="http://python.org/">Python</a> rocks'
+ >>> p.text()
+ 'you know Python rocks'
+
+You can use some of the pseudo classes that are available in jQuery but that
+are not standard in css such as :first :last :even :odd :eq :lt :gt :checked
+:selected :file::
+
+ >>> d('p:first')
+ [<p#hello.hello>]
+
View
@@ -0,0 +1,13 @@
+#-*- coding:utf-8 -*-
+#
+# Copyright (C) 2008 - Olivier Lauzanne <olauzanne@gmail.com>
+#
+# Distributed under the BSD license, see LICENSE.txt
+
+try:
+ import webob
+except ImportError:
+ from pyquery import PyQuery
+else:
+ from ajax import PyQuery
+
View
@@ -0,0 +1,81 @@
+# -*- coding: utf-8 -*-
+from webob import Request, Response
+from pyquery import PyQuery as Base
+from pyquery import no_default
+
+try:
+ from paste.proxy import Proxy
+except ImportError:
+ Proxy = no_default
+
+class PyQuery(Base):
+
+ def __init__(self, *args, **kwargs):
+ if 'response' in kwargs:
+ self.response = kwargs.pop('response')
+ else:
+ self.response = Response()
+ if 'app' in kwargs:
+ self.app = kwargs.pop('app')
+ if len(args) == 0:
+ args = [[]]
+ else:
+ self.app = no_default
+ Base.__init__(self, *args, **kwargs)
+ if self._parent is not no_default:
+ self.app = self._parent.app
+
+ def _wsgi_get(self, path_info, **kwargs):
+ if path_info.startswith('/'):
+ if 'app' in kwargs:
+ app = kwargs.pop('app')
+ elif self.app is not no_default:
+ app = self.app
+ else:
+ raise ValueError('There is no app available')
+ else:
+ if Proxy is not no_default:
+ app = Proxy(path_info)
+ path_info = '/'
+ else:
+ raise ImportError('Paste is not installed')
+
+ if 'environ' in kwargs:
+ environ = kwargs.pop('environ').copy()
+ else:
+ environ = {}
+ if path_info:
+ kwargs['PATH_INFO'] = path_info
+ environ.update(kwargs)
+
+ # unsuported (came from Deliverance)
+ for key in ['HTTP_ACCEPT_ENCODING', 'HTTP_IF_MATCH', 'HTTP_IF_UNMODIFIED_SINCE',
+ 'HTTP_RANGE', 'HTTP_IF_RANGE']:
+ if key in environ:
+ del environ[key]
+
+ req = Request(environ)
+ resp = req.get_response(app)
+ status = resp.status.split()
+ ctype = resp.content_type.split(';')[0]
+ if status[0] not in '45' and ctype == 'text/html':
+ body = resp.body
+ else:
+ body = []
+ result = self.__class__(body,
+ parent=self._parent,
+ app=self.app, # always return self.app
+ response=resp)
+ return result
+
+ def get(self, path_info, **kwargs):
+ """GET a path from wsgi app or url
+ """
+ kwargs['REQUEST_METHOD'] = 'GET'
+ return self._wsgi_get(path_info, **kwargs)
+
+ def post(self, path_info, **kwargs):
+ """POST a path from wsgi app or url
+ """
+ kwargs['REQUEST_METHOD'] = 'POST'
+ return self._wsgi_get(path_info, **kwargs)
Oops, something went wrong.

0 comments on commit bf0d2be

Please sign in to comment.