merge default doc-dc
authorDamien Correia
Wed, 20 Jun 2018 12:20:54 +0200
branchdoc-dc
changeset 270 3f729a99d55b
parent 269 4815c9f22461 (current diff)
parent 204 759e1c6838ee (diff)
child 271 770bac310903
merge default
--- 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*.
--- 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
 
--- 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'
 
 
--- 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')