# HG changeset patch # User Damien Correia # Date 1529490054 -7200 # Node ID 3f729a99d55bb065f001760918b26d3bc5697aa1 # Parent 4815c9f22461fac5c05d34aed45f934861a88902# Parent 759e1c6838ee7edb844d250045b80ecead3c2531 merge default diff -r 4815c9f22461 -r 3f729a99d55b src/pyams_utils/adapter.py --- a/src/pyams_utils/adapter.py Mon Jun 18 10:13:59 2018 +0200 +++ b/src/pyams_utils/adapter.py Wed Jun 20 12:20:54 2018 +0200 @@ -10,7 +10,7 @@ # FOR A PARTICULAR PURPOSE. # -__doc__ = """Adapters management package +"""Adapters management package This package provides a small set of standard base adapters for *context*, *context* and *request*, and *context* and *request* and *view*. diff -r 4815c9f22461 -r 3f729a99d55b src/pyams_utils/context.py --- a/src/pyams_utils/context.py Mon Jun 18 10:13:59 2018 +0200 +++ b/src/pyams_utils/context.py Wed Jun 20 12:20:54 2018 +0200 @@ -24,7 +24,7 @@ """Interface based context selector This selector can be used as a subscriber predicate to define - an interface that the context must support for the event to be applied:: + an interface that the context must support for the event to be applied: .. code-block:: python diff -r 4815c9f22461 -r 3f729a99d55b src/pyams_utils/factory.py --- a/src/pyams_utils/factory.py Mon Jun 18 10:13:59 2018 +0200 +++ b/src/pyams_utils/factory.py Wed Jun 20 12:20:54 2018 +0200 @@ -10,6 +10,45 @@ # FOR A PARTICULAR PURPOSE. # +"""Objects factory management + +This module provides a decorator and a small set of functions to handle object factories. + +Instead of directly using a class as an object factory, the object of this module is to +let you create an object based on an interface. The first step is to create an object +implementing this interface, and then to register it as a factory: + +.. code-block:: python + + @implementer(IMyInterface) + class MyClass(object): + '''Class implementing my interface''' + + register_factory(IMyInterface, MyClass) + +Factory registry can also be handle by a decorator called "factory_config": + +.. code-block:: python + + @implementer(IMyInterface) + @factory_config(IMyInterface) + class MyClass(object): + '''Class implementing my interface''' + +When a factory is registered, you can look for a factory: + +.. code-block:: python + + factory = get_object_factory(IMyInterface) + if factory is not None: + myobject = factory() + else: + myobject = MyDefaultImplementation() + +By registering their own objects factories, extension packages can easily provide their +own implementation of any PyAMS interface handled by factories. +""" + __docformat__ = 'restructuredtext' diff -r 4815c9f22461 -r 3f729a99d55b src/pyams_utils/tales.py --- a/src/pyams_utils/tales.py Mon Jun 18 10:13:59 2018 +0200 +++ b/src/pyams_utils/tales.py Wed Jun 20 12:20:54 2018 +0200 @@ -56,11 +56,16 @@ if arg.startswith('"') or arg.startswith("'"): # may be a quoted string... return arg[1:-1] - args = arg.split('.') - result = econtext.get(args.pop(0)) - for arg in args: - result = getattr(result, arg) - return result + try: + arg = int(arg) # check integer value + except ValueError: + args = arg.split('.') + result = econtext.get(args.pop(0)) + for arg in args: + result = getattr(result, arg) + return result + else: + return arg name = name.strip() context = econtext.get('context')