Skip to main content

infrae.comethods

This package provides an helper to write cofunction with the help of Python generators. It provides a decorator that let you write the following paradigm:

from infrae.comethod import cofunction

@cofunction
def processor(**options):
    # Init code
    content = yield
    while content is not None:
         # Work on content, set result in result.
         content = yield result
    # Cleanup code

If you create more of those comethods you can nest them:

import logging

@cofunction
def logger(parent **options):
    logger = logging.getLogger(options.get('name', 'default'))
    logger.info('Start')
    content = yield
    while content is not None:
         result = parent(content)
         logger.info('Processed {0}, got {1}'.format(content, result))
         content = yield result
    # Cleanup code
    logger.info('Done')

And you can use it like this:

with processor() as process:
   with logger(process) as log:
      for item in generator():
          log(item)

Or alternatively:

with processor() as process:
   with logger(process) as log:
      log.map(generator)

Where generator is a generator that yield values to work on. Of course, you can do more interesting things after.

You can find the Mercurial code repository at: https://hg.infrae.com/infrae.comethods/

Changes

1.0 (2011/11/07)

  • Initial version.

Metadata

Release files for infrae.comethods 1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for infrae.comethods 1.0
File Size Uploaded
infrae.comethods-1.0.tar.gz 2.7 kB Details

Release files / infrae.comethods-1.0.tar.gz

Download URL infrae.comethods-1.0.tar.gz
Size 2.7 kB
Tags Source
SHA-256 checksum
How to use checksums
5af45fb239f9944357e302485f20045d06f0ace194587e57d2e06e68f1076f56
BLAKE2b-256 checksum
How to use checksums
d1eafdbcb466d95264c507c13258c992e7850fd4b7ea8473b877cdd5b3b5dcce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

1.0 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page