forked from twisted/tubes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Import from Twisted branch and change names.
- Loading branch information
0 parents
commit 82f0842
Showing
22 changed files
with
4,862 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
""" | ||
Setup file for tubes. | ||
""" | ||
|
||
from setuptools import setup, find_packages | ||
|
||
setup( | ||
name='Tubes', | ||
version='0.0.0', | ||
description=""" | ||
Flow control and backpressure for event-driven applications. | ||
""", | ||
packages=find_packages(exclude=[]), | ||
package_dir={'tubes': 'tubes'}, | ||
install_requires=[ | ||
"characteristic", | ||
"six", | ||
], | ||
include_package_data=True, | ||
license="MIT", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# -*- test-case-name: tubes.test -*- | ||
# Copyright (c) Twisted Matrix Laboratories. | ||
# See LICENSE for details. | ||
|
||
""" | ||
L{tubes} offers an abstraction of data flow and backpressure for event-driven | ||
applications. | ||
@see: L{tubes.tube} | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
|
||
from zope.interface.adapter import AdapterRegistry | ||
from twisted.python.components import _addHook, _removeHook | ||
from contextlib import contextmanager | ||
|
||
@contextmanager | ||
def _registryActive(registry): | ||
""" | ||
A context manager that activates and deactivates a zope adapter registry | ||
for the duration of the call. | ||
For example, if you wanted to have a function that could adapt L{IFoo} to | ||
L{IBar}, but doesn't expose that adapter outside of itself:: | ||
def convertToBar(maybeFoo): | ||
with _registryActive(_registryAdapting((IFoo, IBar, fooToBar))): | ||
return IBar(maybeFoo) | ||
@note: This isn't thread safe, so other threads will be affected as well. | ||
@param registry: The registry to activate. | ||
@type registry: L{AdapterRegistry} | ||
@rtype: | ||
""" | ||
hook = _addHook(registry) | ||
yield | ||
_removeHook(hook) | ||
|
||
|
||
|
||
def _registryAdapting(*fromToAdapterTuples): | ||
""" | ||
Construct a Zope Interface adapter registry. | ||
For example, if you want to construct an adapter registry that can convert | ||
C{IFoo} to C{IBar} with C{fooToBar}. | ||
@param fromToAdapterTuples: A sequence of tuples of C{(fromInterface, | ||
toInterface, adapterCallable)}, where C{fromInterface} and | ||
C{toInterface} are L{Interface}s, and C{adapterCallable} is a callable | ||
that takes one argument which provides C{fromInterface} and returns an | ||
object providing C{toInterface}. | ||
@type fromToAdapterTuples: C{tuple} of 3-C{tuple}s of C{(Interface, | ||
Interface, callable)} | ||
@rtype: L{AdapterRegistry} | ||
""" | ||
result = AdapterRegistry() | ||
for From, to, adapter in fromToAdapterTuples: | ||
result.register([From], to, '', adapter) | ||
return result | ||
|
Oops, something went wrong.