Skip to content

Commit

Permalink
Import from Twisted branch and change names.
Browse files Browse the repository at this point in the history
  • Loading branch information
glyph committed Dec 26, 2014
0 parents commit 82f0842
Show file tree
Hide file tree
Showing 22 changed files with 4,862 additions and 0 deletions.
21 changes: 21 additions & 0 deletions setup.py
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",
)
10 changes: 10 additions & 0 deletions tubes/__init__.py
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}
"""
53 changes: 53 additions & 0 deletions tubes/_components.py
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

Loading

0 comments on commit 82f0842

Please sign in to comment.