2.2.2.1. The Plugin Architechure

Knowing the ins-and-outs of this module is probably not very useful, but it is probably good to have a basic understanding of how the lib.browser.Browser‘s plugin system works.

class lib.browser.plugins.BaseBrowserPlugin

A lib.browser.Browser plugin is defined as a set of patches to be applied to a Browser object. This class defines a base for browser plugins.

__init__()

Sets up everything the plugin needs. Subclasses should be sure to call this.

overrides

A list of methods overriden by this plugin instance.

extensions

A list of methods adding to the browser’s internal list of methods, but not overriding pre-existing methods. Note that if two functions attempt to extend with methods of the same name, Pluggable will throw an exception.

property_extensions

Like extensions, but refering to properties instead.

handlers

A list of objects extended from urllib.request.BaseHandler to add to the browser’s interal urllib.request.OpenerDirector instance automatically.

addheaders

A list of headers to add to the browser’s internal urllib.request.OpenerDirector instance automatically, using urllib.request.OpenerDirector.addheaders()

_get_instance_functions()

Returns the object’s list of methods, useful for the _load_list() method.

_load_list(marker)

Finds all methods with a specific marker and returns them

Keyword arguments:

marker
A string representing the marker to look for on each function. If the value of this marker is True, the value is returned.
class lib.browser.plugins.Pluggable(*plugins)

Takes in plugins, allowing one to configure an object on the fly, with a strutured monkey-patching like system

__init__(*plugins)

Sets up everything the object needs, and adds plugins specified by the positional arguments (they can be added later too). Subclasses should be sure to call this.

plugins

The list of plugins already loaded into the Pluggable.

_register_plugin_attribute(name, handler)
__getattr__(name)

Used to intercept getting attributes with the Pluggable instance, translating them to alternate “extended” attributes.

__setattr__(name, value)

Used to intercept setting attributes with the Pluggable instance, translating them to alternate “extended” attributes.

load_plugins(*plugins)

Loads in one or a group of plugins. Rather than overriding this, subclasses should use the lib.browser.plugins.decorators.plugin_attribute() and lib.browser.plugins.decorators.plugin_attribute_handler() decorators. Attributes are loaded from plugins, and then parsed to be used in extending the Pluggable subclass’ object.

overrides(name, overriding_function)

The handler for the lib.browser.plugins.decorators.override() decorator. name is the name of the property it is set to override, overriding_function is the function that we should set to that name. It should take at least 2 arguments (in addition to self, which would refer to the plugin instance), the browser instance and the function object that is being overridden.

extensions(name, extending_function)

The handler for the lib.browser.plugins.decorators.extension() decorator. name is the name of the property it is set to extension, extending_function is the function that we should set to that name. It should take the browser instance as an argument in addition to self, which would refer to the plugin instance. Any additional arguments are passed through.

property_extensions(name, value)

The handler for the lib.browser.plugins.decorators.property_extension() decorator. Adds a virtual property with the given name, by calling value with the browser instance and recieving a property object.

extensions(name, extending_function)

The handler for the lib.browser.plugins.decorators.extension() decorator. name is the name of the property it is set to extension, extending_function is the function that we should set to that name. It should take the browser instance as an argument in addition to self, which would refer to the plugin instance. Any additional arguments are passed through.

load_plugins(*plugins)

Loads in one or a group of plugins. Rather than overriding this, subclasses should use the lib.browser.plugins.decorators.plugin_attribute() and lib.browser.plugins.decorators.plugin_attribute_handler() decorators. Attributes are loaded from plugins, and then parsed to be used in extending the Pluggable subclass’ object.

overrides(name, overriding_function)

The handler for the lib.browser.plugins.decorators.override() decorator. name is the name of the property it is set to override, overriding_function is the function that we should set to that name. It should take at least 2 arguments (in addition to self, which would refer to the plugin instance), the browser instance and the function object that is being overridden.

property_extensions(name, value)

The handler for the lib.browser.plugins.decorators.property_extension() decorator. Adds a virtual property with the given name, by calling value with the browser instance and recieving a property object.