class SchemaSource(SampleSource): provider(ISectionBlueprint) def __init__(self, transmogrifier, name, options, previous): super( SchemaSource, self).__init__( transmogrifier, name, options, previous) sourcecontent = options.get('source-content', 'full') if sourcecontent == 'full': self.sample = ( dict(_path='/spam', foo='one value', _type='TransmogrifyDexterityFTI', title='Spam', description='Lorem Ipsum bla bla!', test_file={ 'data': zptlogo, 'filename': 'zptlogo.gif'}, test_date='2010-10-12', test_datetime='2010-10-12 17:59:59', fieldnotchanged='nochange', ), dict(_path='/two', foo='Bla', _type='TransmogrifyDexterityFTI', title='My Second Object', # description=None, # None is not valid for this # field. test_file=zptlogo, _filename="testlogo.gif", test_date=date(2010, 0o1, 0o1, ), test_datetime=datetime(2010, 0o1, 0o1, 17, 59, 59), fieldnotchanged='nochange', ), ) elif sourcecontent == 'onlytitle': self.sample = ( dict(_path='/spam', _type='TransmogrifyDexterityFTI', title='Spammety spam'), dict(_path='/two', _type='TransmogrifyDexterityFTI', title='My Awesome Second Object'), )
def includeme(config): from zope.interface import Interface, provider class ILispyParserFactory(Interface): def __call__(*args, **kwargs): pass class ILispyParser(Interface): def __call__(data): pass def set_lispy_parser(config, *args, **kwargs): factory = config.registry.getUtility(ILispyParserFactory) parser = factory(*args, **kwargs) config.registry.registerUtility(provider(ILispyParser)(parser), ILispyParser) config.registry.registerUtility(provider(ILispyParserFactory)(create_handler), ILispyParserFactory) config.add_directive("set_lispy_parser", set_lispy_parser)
def trivialInput(symbol): """ Create a new L{IRichInput} implementation for the given input symbol. This creates a new type object and is intended to be used at module scope to define rich input types. Generally, only one use per symbol should be required. For example:: Apple = trivialInput(Fruit.apple) @param symbol: A symbol from some state machine's input alphabet. @return: A new type object usable as a rich input for the given symbol. @rtype: L{type} """ return provider(IRichInput)(type( symbol.name.title(), (FancyStrMixin, object), { "symbol": _symbol(symbol), }))
def trivialInput(symbol): """ Create a new L{IRichInput} implementation for the given input symbol. This creates a new type object and is intended to be used at module scope to define rich input types. Generally, only one use per symbol should be required. For example:: Apple = trivialInput(Fruit.apple) @param symbol: A symbol from some state machine's input alphabet. @return: A new type object usable as a rich input for the given symbol. @rtype: L{type} """ return provider(IRichInput)(type(symbol.name.title(), (FancyStrMixin, object), { "symbol": _symbol(symbol), }))
IVirtualAccess, ) from block.chain.monoid.mutable import Failure as MFailure from block.chain.monoid.immutable import Failure as IMFailure Failure = MFailure ### Wrapped value @implementer(IFalsyValue) class _Nothing(object): def __nonzero__(self): return False __bool__ = __nonzero__ Nothing = _Nothing() ### Access registration IdentityAccess = provider(IVirtualAccess)(op) @implementer(IVirtualAccess) class BoundAccess(object): def __init__(self,o): self.o = o def attrgetter(self, k): return getattr(self.o, k) def itemgetter(self, k): return self.o[k] def methodcaller(self, k, *args, **kwargs): def wrapped(v): return getattr(self.o, k)(v, *args, **kwargs)
def _add_bubbling_event(registry, SubjectClass, fn, name="", dynamic=True): iface = iface_from_class(SubjectClass, dynamic=dynamic, Exception=BubblingConfigurationError) if not isinstance(iface, (list, tuple)): iface = [iface] fn = provider(IEvent)(fn) registry.adapters.register(iface, IEvent, name, fn)
def compute_value(fn): return provider(IComputeValue)(fn)
class AtomServiceMime(AtomMime): provider(IAtomServiceMime) mime_type_string = 'application/atomsvc+xml'
class AtomEntryMime(AtomMime): provider(IAtomEntryMime) mime_type_string = 'application/atom+xml;type=entry'
class AtomFeedMime(AtomMime): provider(IAtomFeedMime) mime_type_string = 'application/atom+xml;type=feed'
def set_lispy_parser(config, *args, **kwargs): factory = config.registry.getUtility(ILispyParserFactory) parser = factory(*args, **kwargs) config.registry.registerUtility(provider(ILispyParser)(parser), ILispyParser)