Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
class Fn(object):
"""Hook for defining custom function (like the jQuery.fn)
>>> PyQuery.fn.listOuterHtml = lambda: this.map(lambda i, el: PyQuery(this).outerHtml())
>>> S = PyQuery('<ol> <li>Coffee</li> <li>Tea</li> <li>Milk</li> </ol>')
>>> S('li').listOuterHtml()
['<li>Coffee</li>', '<li>Tea</li>', '<li>Milk</li>']
"""
def __setattr__(self, name, func):
def fn(self, *args):
func_globals(func)['this'] = self
return func(*args)
fn.__name__ = name
setattr(PyQuery, name, fn)
fn = Fn()
#####################################################
# Additional methods that are not in the jQuery API #
#####################################################
@property
def base_url(self):
"""Return the url of current html document or None if not available.
"""
if self._base_url is not None:
return self._base_url
if self._parent is not no_default:
return self._parent.base_url
def make_links_absolute(self, base_url=None):
"""Make all links absolute.
>>> fn = lambda: this.map(lambda i, el: PyQuery(this).outerHtml())
>>> PyQuery.fn.listOuterHtml = fn
>>> S = PyQuery(
... '<ol> <li>Coffee</li> <li>Tea</li> <li>Milk</li> </ol>')
>>> S('li').listOuterHtml()
['<li>Coffee</li>', '<li>Tea</li>', '<li>Milk</li>']
"""
def __setattr__(self, name, func):
def fn(self, *args, **kwargs):
func.__globals__['this'] = self
return func(*args, **kwargs)
fn.__name__ = name
setattr(PyQuery, name, fn)
fn = Fn()
########
# AJAX #
########
@with_camel_case_alias
def serialize_array(self):
"""Serialize form elements as an array of dictionaries, whose structure
mirrors that produced by the jQuery API. Notably, it does not handle
the deprecated `keygen` form element.
>>> d = PyQuery('<form><input value="spam" name="order"></form>')
>>> d.serialize_array() == [{'name': 'order', 'value': 'spam'}]
True
>>> d.serializeArray() == [{'name': 'order', 'value': 'spam'}]
True