~sylvain-pineau/checkbox/jinja_exporter_FileSystemLoader

« back to all changes in this revision

Viewing changes to plainbox/plainbox/impl/unit/validators.py

  • Committer: Daniel Manrique
  • Author(s): Zygmunt Krynicki
  • Date: 2015-03-27 20:47:36 UTC
  • mfrom: (3626.1.1 launchpad/more-pods)
  • Revision ID: daniel_manrique-20150327204736-sr2plieces35h5bk
"automatic merge of lp:~zyga/checkbox/more-pods/ by tarmac [r=roadmr][bug=][author=zyga]"

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
 
31
31
from plainbox.i18n import gettext as _
32
32
from plainbox.i18n import ngettext
 
33
from plainbox.impl import pod
 
34
from plainbox.abc import IProvider1
33
35
from plainbox.impl.unit import get_accessed_parameters
34
36
from plainbox.impl.validation import Issue
35
37
from plainbox.impl.validation import Problem
65
67
    return str(field).replace('-', '_')
66
68
 
67
69
 
68
 
class UnitValidationContext:
 
70
class UnitValidationContext(pod.POD):
69
71
    """
70
72
    Helper class for validating units in a bigger context
71
73
 
74
76
    1) to allow a the validated object to see "everything" (other units)
75
77
    2) to allow validators to share temporary data structures
76
78
       and to prevent O(N**2) complexity of some checks.
77
 
 
78
 
    :attr provider_list:
79
 
        A list of Provider1 objects
80
79
    """
81
80
 
82
 
    def __init__(self, provider_list):
83
 
        """
84
 
        Initialize a new validation context
85
 
 
86
 
        :param provider_list:
87
 
            A list of Provider1 objects
88
 
        """
89
 
        self._provider_list = provider_list
90
 
        self._shared_cache = {}
91
 
 
92
 
    @property
93
 
    def provider_list(self):
94
 
        return self._provider_list
 
81
    provider_list = pod.Field(
 
82
        "list of all the providers", list, pod.MANDATORY,
 
83
        assign_filter_list=[pod.typed, pod.typed.sequence(IProvider1)])
 
84
 
 
85
    shared_cache = pod.Field(
 
86
        "cached computations", dict, initial_fn=dict,
 
87
        assign_filter_list=[pod.typed])
95
88
 
96
89
    def compute_shared(self, cache_key, func, *args, **kwargs):
97
90
        """
115
108
            The caller is responsible for ensuring that ``args`` and ``kwargs``
116
109
            match the `cache_key` each time this function is called.
117
110
        """
118
 
        if cache_key not in self._shared_cache:
119
 
            self._shared_cache[cache_key] = func(*args, **kwargs)
120
 
        return self._shared_cache[cache_key]
 
111
        if cache_key not in self.shared_cache:
 
112
            self.shared_cache[cache_key] = func(*args, **kwargs)
 
113
        return self.shared_cache[cache_key]
121
114
 
122
115
 
123
116
class UnitFieldIssue(Issue):