@@ -105,8 +105,8 @@ code example below:
105
105
from web_poet.pages import ItemWebPage
106
106
from web_poet import PageObjectRegistry
107
107
108
- primary_registry = PageObjectRegistry()
109
- secondary_registry = PageObjectRegistry()
108
+ primary_registry = PageObjectRegistry(name = " primary " )
109
+ secondary_registry = PageObjectRegistry(name = " secondary " )
110
110
111
111
class GenericProductPage (ItemWebPage ):
112
112
def to_item (self ):
@@ -196,11 +196,22 @@ like ``web_poet my_project.page_objects`` would produce the following:
196
196
197
197
.. code-block ::
198
198
199
- Use this instead of for the URL patterns except for the patterns with priority meta
200
- ---------------------------------------------------- ------------------------------------------ -------------------------------------- ------------------------- --------------- ------
201
- my_project.page_objects.ExampleProductPage my_project.page_objects.GenericProductPage ['example.com'] [] 500 {}
202
- my_project.page_objects.AnotherExampleProductPage my_project.page_objects.GenericProductPage ['anotherexample.com'] ['/digital-goods/'] 500 {}
203
- my_project.page_objects.DualExampleProductPage my_project.page_objects.GenericProductPage ['dualexample.com/shop/?product=*', 'dualexample.net/store/?pid=*'] [] 500 {}
199
+ Registry Use this instead of for the URL patterns except for the patterns with priority meta
200
+ --------- ---------------------------------------------------- ------------------------------------------ ------------------------------------------------------------------- ------------------------- --------------- ------
201
+ default my_project.page_objects.ExampleProductPage my_project.page_objects.GenericProductPage ['example.com'] [] 500 {}
202
+ default my_project.page_objects.AnotherExampleProductPage my_project.page_objects.GenericProductPage ['anotherexample.com'] ['/digital-goods/'] 500 {}
203
+ default my_project.page_objects.DualExampleProductPage my_project.page_objects.GenericProductPage ['dualexample.com/shop/?product=*', 'dualexample.net/store/?pid=*'] [] 500 {}
204
+
205
+ You can also filter them via the **name ** of :class: `~.PageObjectRegistry `. For example,
206
+ invoking ``web_poet my_project.page_objects --registry_name=custom `` would produce
207
+ something like:
208
+
209
+ .. code-block ::
210
+
211
+ Registry Use this instead of for the URL patterns except for the patterns with priority meta
212
+ ---------- ---------------------------------------------------- ------------------------------------------ ---------------------- ------------------------- --------------- ------
213
+ custom my_project.page_objects.CustomProductPage my_project.page_objects.GenericProductPage ['example.com'] [] 500 {}
214
+ custom my_project.page_objects.AnotherCustomProductPage my_project.page_objects.GenericProductPage ['anotherexample.com'] ['/digital-goods/'] 500 {}
204
215
205
216
Organizing Page Object Overrides
206
217
--------------------------------
@@ -320,10 +331,52 @@ organize them using our own instances of the :class:`~.PageObjectRegistry` inste
320
331
321
332
from web_poet import PageObjectRegistry
322
333
323
- cool_gadget_registry = PageObjectRegistry()
324
- cool_gadget_us_registry = PageObjectRegistry()
325
- cool_gadget_fr_registry = PageObjectRegistry()
326
- furniture_shop_registry = PageObjectRegistry()
334
+ cool_gadget_registry = PageObjectRegistry(name = " cool_gadget" )
335
+ cool_gadget_us_registry = PageObjectRegistry(name = " cool_gadget_us" )
336
+ cool_gadget_fr_registry = PageObjectRegistry(name = " cool_gadget_fr" )
337
+ furniture_shop_registry = PageObjectRegistry(name = " furniture_shop" )
338
+
339
+ Note that you can access all of the :class: `~.PageObjectRegistry ` that were
340
+ ever instantiated via ``web_poet.registry_pool `` which is simply a mapping
341
+ structured as ``Dict[str, PageObjectRegistry] ``:
342
+
343
+ .. code-block :: python
344
+
345
+ from web_poet import registry_pool
346
+
347
+ print (registry_pool)
348
+ # {
349
+ # 'default': <web_poet.overrides.PageObjectRegistry object at 0x7f47d654d8b0>,
350
+ # 'cool_gadget' = <my_page_obj_project.PageObjectRegistry object at 0x7f47d654382a>,
351
+ # 'cool_gadget_us' = <my_page_obj_project.PageObjectRegistry object at 0xb247d65433c3>,
352
+ # 'cool_gadget_fr' = <my_page_obj_project.PageObjectRegistry object at 0xd93746549dea>,
353
+ # 'furniture_shop' = <my_page_obj_project.PageObjectRegistry object at 0x82n78654441b>
354
+ # }
355
+
356
+ .. warning ::
357
+
358
+ Please be aware that there might be some :class: `~.PageObjectRegistry `
359
+ that are not available, most especially if you're using them from external
360
+ packages.
361
+
362
+ Thus, it's imperative to use :func: `~.web_poet.overrides.consume_modules `
363
+ beforehand:
364
+
365
+ .. code-block :: python
366
+
367
+ from web_poet import registry_pool, consume_modules
368
+
369
+ consume_modules(" external_pkg" )
370
+
371
+ print (registry_pool)
372
+ # {
373
+ # 'default': <web_poet.overrides.PageObjectRegistry object at 0x7f47d654d8b0>,
374
+ # 'cool_gadget' = <my_page_obj_project.PageObjectRegistry object at 0x7f47d654382a>,
375
+ # 'cool_gadget_us' = <my_page_obj_project.PageObjectRegistry object at 0xb247d65433c3>,
376
+ # 'cool_gadget_fr' = <my_page_obj_project.PageObjectRegistry object at 0xd93746549dea>,
377
+ # 'furniture_shop' = <my_page_obj_project.PageObjectRegistry object at 0x82n78654441b>,
378
+ # 'ecommerce': <external_pkg.PageObjectRegistry object at 0xbc45d8328420>
379
+ # }
327
380
328
381
After declaring the :class: `~.PageObjectRegistry ` instances, they can be used
329
382
in each of the Page Object packages like so:
@@ -412,7 +465,7 @@ our Override Rules.
412
465
413
466
from web_poet import PageObjectRegistry
414
467
415
- product_listings_registry = PageObjectRegistry()
468
+ product_listings_registry = PageObjectRegistry(name = " product_listings " )
416
469
417
470
Using the additional registry instance above, we'll use it to provide another
418
471
annotation for the Page Objects in each of the ``product_listings.py `` module.
@@ -477,7 +530,7 @@ packages** in your project, you can do it like:
477
530
# attribute of the registry even before calling `PageObjectRegistry.get_overrides()`
478
531
consume_modules(" ecommerce_page_objects" , " gadget_sites_page_objects" )
479
532
480
- combined_registry = PageObjectRegistry()
533
+ combined_registry = PageObjectRegistry(name = " combined " )
481
534
combined_registry.data = {
482
535
# Since ecommerce_page_objects is using web_poet.default_registry, then
483
536
# it functions like a global registry which we can access as:
0 commit comments