Skip to content

Commit

Permalink
Merge ee1b0cc into e6d541f
Browse files Browse the repository at this point in the history
  • Loading branch information
Pietro Berkes committed Apr 8, 2014
2 parents e6d541f + ee1b0cc commit 975251e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 22 deletions.
4 changes: 2 additions & 2 deletions codetools/contexts/api.py
Expand Up @@ -4,8 +4,8 @@
from .data_context import DataContext, ListenableMixin, PersistableMixin
from .function_filter_context import FunctionFilterContext
from .geo_context import GeoContext
from .i_context import (IContext, IListenableContext, IRestrictedContext,
IPersistableContext, ICheckpointable, defer_events)
from .i_context import (ICheckpointable, IContext, IDataContext,
IListenableContext, IPersistableContext, IRestrictedContext, defer_events)
from .iterable_adapted_data_context import IterableAdaptedDataContext
from .multi_context import MultiContext
from .traitslike_context_wrapper import TraitslikeContextWrapper
Expand Down
24 changes: 8 additions & 16 deletions codetools/contexts/data_context.py
Expand Up @@ -21,8 +21,7 @@
from traits.api import (Bool, Dict, HasTraits, Str, Supports,
adapt, provides, on_trait_change)

from .i_context import (IContext, ICheckpointable, IListenableContext,
IPersistableContext, IRestrictedContext)
from .i_context import IContext, ICheckpointable, IDataContext
from .items_modified_event import ItemsModifiedEvent, ItemsModified

# This is copied from numerical_modeling.numeric_context.constants
Expand Down Expand Up @@ -230,9 +229,7 @@ def save(self, file_or_path):
file_object.close()



@provides(ICheckpointable, IListenableContext, IPersistableContext,
IRestrictedContext)
@provides(IDataContext)
class DataContext(ListenableMixin, PersistableMixin, DictMixin):
""" A simple context which fires events.
"""
Expand Down Expand Up @@ -365,15 +362,11 @@ def checkpoint(self):
# Define adaptation offers from IContext to other context protocols using
# DataContext.

i_context_adaptation_offers = []
for interface in [ICheckpointable, IListenableContext, IPersistableContext,
IRestrictedContext]:
offer = AdaptationOffer(
factory=lambda x: DataContext(subcontext=x),
from_protocol=IContext,
to_protocol=interface
)
i_context_adaptation_offers.append(offer)
data_context_offer = AdaptationOffer(
factory=lambda x: DataContext(subcontext=x),
from_protocol=IContext,
to_protocol=IDataContext
)


def register_i_context_adapter_offers(adaptation_manager):
Expand All @@ -383,8 +376,7 @@ def register_i_context_adapter_offers(adaptation_manager):
2) `dict` can be adapted to `ICheckpointable`
"""

for offer in i_context_adaptation_offers:
adaptation_manager.register_offer(offer)
adaptation_manager.register_offer(data_context_offer)


# For backward compatibility, we register the adapters from `dict` globally
Expand Down
5 changes: 5 additions & 0 deletions codetools/contexts/i_context.py
Expand Up @@ -223,6 +223,11 @@ def checkpoint(self):
# here.


class IDataContext(ICheckpointable, IListenableContext, IPersistableContext,
IRestrictedContext):
""" Interface for full-featured contexts. """


#### Adaptation ###############################################################

class CheckPointableDictAdapter(object):
Expand Down
6 changes: 2 additions & 4 deletions codetools/contexts/multi_context.py
Expand Up @@ -18,13 +18,11 @@
adapt, provides, on_trait_change)

from .data_context import DataContext, ListenableMixin, PersistableMixin
from .i_context import (ICheckpointable, IListenableContext,
IPersistableContext, IRestrictedContext)
from .i_context import ICheckpointable, IDataContext, IRestrictedContext
from .utils import safe_repr


@provides(ICheckpointable, IListenableContext, IPersistableContext,
IRestrictedContext)
@provides(IDataContext)
class MultiContext(ListenableMixin, PersistableMixin, DictMixin):
""" Wrap several subcontexts.
"""
Expand Down

0 comments on commit 975251e

Please sign in to comment.