File: rules.rst

package info (click to toggle)
python-web-poet 0.23.2-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 908 kB
  • sloc: python: 6,112; makefile: 19
file content (24 lines) | stat: -rw-r--r-- 856 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
.. _framework-rules:

================
Supporting rules
================

Ideally, a framework should support returning the right :ref:`page object
<page-objects>` or :ref:`output item <items>` given a target URL and a desired
:ref:`output item class <items>` when :ref:`rules <rules>` are used.

To provide basic support for rules in your framework, use the
:class:`~.RulesRegistry` object at ``web_poet.default_registry`` to choose
a page object based on rules:

.. code-block:: python

    from web_poet import default_registry

    page_cls = default_registry.page_cls_for_item("https://example.com", MyItem)

You should also let your users know what is the best approach to :ref:`load
rules <load-rules>` when using your framework. For example, let them know the
best location for their calls to the :func:`~.web_poet.rules.consume_modules`
function.