gawel / pyquery

A jquery-like library for python
http://pyquery.rtfd.org/
Other
2.3k stars 182 forks source link

Preserve namespaces attribute on PyQuery copies. #120

Closed jcushman closed 8 years ago

jcushman commented 8 years ago

This ensures that the namespaces argument passed into PyQuery() will also be passed into any internally created copies. That allows you to set namespaces a single time rather than over and over.

Example before this pull:

namespaces = {'foo':'http://example.com/foo'}
d = pq(xml, parser='xml')
val = d('foo|bar', namespaces=namespaces).closest('foo|baz', namespaces=namespaces).children('foo|boo', namespaces=namespaces)

Example after this pull:

namespaces = {'foo':'http://example.com/foo'}
d = pq(xml, parser='xml', namespaces=namespaces)
val = d('foo|bar').closest('foo|baz').children('foo|boo')

Also added a couple of tests to ensure that namespaces are passed to copies.